h = 0.2;
x = pi / 4;
fp = 2.0;

fd = zeros ( 50, 1 );

for i = 1 : 50
  fd(i) = ( tan(x+h) - tan(x) ) / h;
  fprintf ( '  %2d  %14.8g  %14.8g  %g\n', i, h, fd(i), abs ( fd(i) - fp ));
  h = h / 2.0;
end

plot ( 1:50, log ( fd - fp  ), 'linewidth', 3 );
grid ( 'on' );
title ( '50 estimates of derivative of tan(x) at pi/4' )
xlabel ( 'log2 (1/5/h)' );
ylabel ( 'log (error)' );

print ( '-dpng', 'tan_difference.png' );

