% % Applies Euler's method to: % % y' = f(t,y) y(t0)=y0 % % taking n steps of length h. % % w(n+1) = w(n) + h f(w(n),t(n)) % % INPUT: F string variable containing % the name of the function file % where f(t,y) is stored. % h step size % n number of steps % t0 initial value of the t-variable % y0 initial value of the y-variable % % OUTPUT: vectors (t,w) where w(n) is % the approximation of y(t) at % t(n)=t0+(n-1)*h, n=1,2,3,... % % function [t,w]=Euler(F,h,n,t0,y0) t(1)=t0; w(1)=y0; for i=2:(n+1) fi=feval(F,t(i-1),w(i-1)); w(i)=w(i-1)+h*fi; t(i)=t(i-1)+h; end