Usage example for forward_euler related to question 6.7
0001 % Usage example for forward_euler 0002 % related to question 6.7 0003 0004 f = @(t,y) -10^2*(y - t^(-1)) - t^(-2); 0005 % Note that the exponent has changed for illustration purposes 0006 t0 = 1; 0007 y0 = 1; 0008 h = 0.022; 0009 % In theory we need h < 0.02 to ensure the error remains small 0010 T = 2; 0011 analytic = @(t) t.^(-1); 0012 [ y,t,err ] = forward_euler( f,t0,y0,h,T,analytic ); 0013 figure; 0014 plot(t,y,'o'); 0015 xlabel('t'); 0016 ylabel('y(t)'); 0017 hold on; 0018 ezplot(analytic, [1 2]); 0019 legend('numerical','analytic');