%Section 4.3 computer problem #4

format long;

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

a = 0.5;

formula_5 = zeros(1,13);
formula_19 = zeros(1,13);

for i=1:13
    h = 4^(1-i);
    formula_5(i) = [f(a+h)-f(a)]/h;
    formula_19(i) = [f(a+h)-f(a-h)]/(2*h)-[f(a+2*h)-2*(f(a+h)-f(a-h))-f(a-2*h)]/(12*h);
end

exact = f_p(a)*ones(1,13);

disp('absolute errors for central differences (formula 5) are...')
abs(formula_5-exact)

disp('absolute errors for formula 19 are...')
abs(formula_19-exact)


