%Script file: eulertest.m
%
%Displays local and global errors for Euler's method
%applied to y'=+-y, 0 < t < 5
%

disp(' dy/dt = -y ')
disp(' h LTE_max err_5 relerr_5 ')

for n = [20 40 80 160]

h=5.0/n;
y=1.0;
tau=h*1.0/2.0;

for i=1:n
y=(1-h)*y;
end

err=exp(-5.0)-y;
rerr=err/exp(-5.0);

disp(sprintf('%5.3e %5.3e %5.3e %5.3e',h,tau,err,rerr))

end

disp(' ********************************** ')

disp(' dy/dt = y ')
disp(' h LTE_max err_5 relerr_5 ')

for n = [20 40 80 160]

h=5.0/n;
y=1.0;
tau=h*exp(5.0)/2.0;

for i=1:n
y=(1+h)*y;
end

err=exp(5.0)-y;
rerr=err/exp(5.0);

disp(sprintf('%5.3e %5.3e %5.3e %5.3e',h,tau,err,rerr))

end