function IME=impeuler(f,a,b,ya,h) % Improved Euler Method that is called Heun Method %Input - y'=f is the function % - a and b are the left and right endpoints % - ya is the initial condition y(a) % - h is the step size %Output - IME=[T' Y'] where T is the vector of abscissas and % - Y is the vector of ordinates % NUMERICAL METHODS: Matlab Programs % (c) 2007 by Xie Liling % Complementary Software to accompany the textbook: % Information and Computing Science: A Laboratory Course M=ceil((b-a)/h); T=zeros(1,M+1); Y=zeros(1,M+1); T=a:h:b; Y(1)=ya; for j=1:M Yj=Y(j)+h*feval(f,T(j),Y(j)); Y(j+1)=Y(j)+h*(feval(f,T(j),Y(j))+feval(f,T(j+1),Yj))/2; end IME=[T' Y'];