
graphsetup

N = (1:15)';
h = 2.^(-N);

yp_h = (exp(1+h) - exp(1))./h;
yp_h2 = (exp(1+h) - exp(1-h))./(2*h);


err_h = abs(yp_h - exp(1));
err_h2 = abs(yp_h2 - exp(1));

figure(3)
loglog(h,err_h,'*',h,err_h2,'p')
xlabel('\fontsize{16} h'),ylabel('\fontsize{16} error')
title('\fontsize{16} Finite Difference approximations to fprime')
legend('\fontsize{16} h','\fontsize{16} h^2', ...
       'Location','northwest')

grid

format short e
disp(' ')
disp('        h         err_h/h    err_h2/h2 ')
disp('   ------------------------------------')
disp([h err_h./h err_h2./h.^2])
format long e
disp(' ')







