% Chapter 9 Exercise 1. 

hinit = 10^-1;
x = pi/6.0;
true = -1/2;
fpp = zeros(16,1);
h = hinit;
for i =1:16
    fpp(i) = (sin(x + h) -2*sin(x) + sin(x - h))/h^2;
    h = h/10;
end

error = abs( fpp - true*ones(16,1));

fprintf('    h      Diff. Quotient      Error\n');
fprintf('==============================================\n');

h = hinit;
for i = 1:16
    fprintf('%5.2e  %16.8e   %16.8e\n',h,fpp(i),error(i))
    h = h/10;
end
