ambrosini.us

Historical teaching note · 2006-04 · restored from archived Blogger HTML

Cheap Euler's method implementation

This time in MatLab! % Euler's method for estimating solution of % initial value problem % parameters a = 0; % left end point b = 1; % right end point alpha = 0; % initial condition N = 2; % function fv = f(x,y), fv = x e^(2 x) - 2 y; apparently can't do this in a % script file... lame h = (b - a)/N; t = a; w = alpha; output(1,1) = 1; output(1,2) = t; output(1,3) = w; for i = 1:N w = w + h * t * exp(3 * t) - 2 * w; % here's the function of interest... matlab is annoying t = a + i * h output(i + 1,1) = i + 1; output(i + 1,2) = t; output(i + 1,3) = w; end output