function diff_center_test ( )

%*****************************************************************************80
%
%% diff_center_test() tests diff_center().
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    27 July 2019
%
%  Author:
%
%    John Burkardt
%
  addpath ( '../diff_center' );

  timestamp ( );
  fprintf ( 1, '\n' );
  fprintf ( 1, 'diff_center_test():\n' );
  fprintf ( 1, '  MATLAB/Octave version %s\n', version ( ) );
  fprintf ( 1, '  Test diff_center():\n' );
%
%  Estimate f'(x) using decreasing sequence of h values.
%
  f = 'sin(x)';
  x = pi / 4.0;
  h = 1.0;
  fprintf ( 1, '\n' );
  fprintf ( 1, '  For f(x)=sin(x), estimate f''(%g)\n', x );
  fprintf ( 1, '  Exact value is %g\n', cos(x) );
  fprintf ( 1, '    H    Estimate\n' );
  fprintf ( 1, '\n' );
  for i = 1 : 10
    yp = diff_center ( f, x, h );
    fprintf ( 1, '  %10.8f  %14.6g\n', h, yp );
    h = h / 2.0;
  end
%
%  Estimate f'(x) over [0,2].
%
  a = 0.0;
  b = 2.0;
  n = 26;
  x = linspace ( a, b, n );
  yd = humps_deriv ( x );
  h = ( b - a ) / ( n - 1 );
  yp = diff_center ( 'humps_fun(x)', x, h );

  fprintf ( 1, '\n' );
  fprintf ( 1, '  Estimate f''(x) for humps function over [0,2]\n' );
  fprintf ( 1, '  at %d points, using h = %f\n', n, h );
  fprintf ( 1, '  Plot exact and estimated derivatives.\n' );

  clf ( );
  hold ( 'on' );
  plot ( x, yd, 'b-', 'linewidth', 3 )
  plot ( x, yp, 'r-', 'linewidth', 3 )
  legend ( 'True derivative', 'Centered difference' )
  grid ( 'on' );
  hold ( 'off' )
  filename = 'diff_humps.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );
  pause ( 5.0 )
%
%  Terminate.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'diff_center_test():\n' );
  fprintf ( 1, '  Normal end of execution.\n' );
  timestamp ( );

  rmpath ( '../diff_center' );

  return
end
function timestamp ( )

%*****************************************************************************80
%
%% timestamp() prints the current YMDHMS date as a timestamp.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    14 February 2003
%
%  Author:
%
%    John Burkardt
%
  t = now;
  c = datevec ( t );
  s = datestr ( c, 0 );
  fprintf ( 1, '%s\n', s );

  return
end

