%computes numerically the derivative of f at a via a naive algorithm

format long;

f = @(x) sin(x);
f_p = @(x) cos(x);

n = 20;
a = 0.5;
h = 0.1;
y = zeros(1,n);

for i=1:n
    h = 0.1*h;
    y(i) = (sin(a+h)-sin(a))/h;
end

disp('approximate values are...')
y

disp('exact value is...')
f_p(a)

exact = f_p(a)*ones(1,n);
disp('absolute errors are...')
abs(y-exact)
