% Compute the absolute- and relative errors for the 
% approximation 
%
%		f(x) ~= ( f(x+h) - f(x) )/h
%
% when f(x) = sin(x), x = 1.2 and h -> 0+
%

% Compute the finite difference for different h's
x0 = 1.2;
f0 = sin(1.2);
fp_exact = cos(1.2);
h = 10.^(-20:0.5:0);
fp_approx = (sin(x0+h) - f0)./h;

% Compute the error
err_abs = abs(fp_exact - fp_approx);
err_asym = f0/2*h;

% Plot the absolute error
loglog(h,err_abs,'-*',h,err_asym,'--')
xlabel('h')
ylabel('Absolute error')
