function opt_gradient_descent_test ( )

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

  timestamp ( );
  fprintf ( 1, '\n' );
  fprintf ( 1, 'opt_gradient_descent_test():\n' );
  fprintf ( 1, '  MATLAB/Octave version %s\n', version ( ) );
  fprintf ( 1, '  opt_gradient_descent() estimates a local minimum\n' );
  fprintf ( 1, '  of a function f(x) near a starting point x0,\n' );
  fprintf ( 1, '  using a stepsize factor gamma.\n' );
%
%  Use M file.
%
  f_string = 'humps_fun(x)';
  fp_string = 'humps_deriv(x)';
  x0 = 0.4;
  gamma = 0.01;

  fprintf ( 1, '\n' );
  fprintf ( 1, '  f(x) = "%s"\n', f_string );
  fprintf ( 1, '  f''(x) = "%s"\n', fp_string );
  fprintf ( 1, '  x0 = %f\n', x0 );
  fprintf ( 1, '  gamma = %f\n', gamma );
  [ x, it ] = opt_gradient_descent ( fp_string, x0, gamma );
  fx = humps_fun ( x );
  fpx = humps_deriv ( x );
  fprintf ( 1, '  f (%24.16g)=%24.16g,\n', x, fx );
  fprintf ( 1, '  f''(%24.16g)=%24.16g\n', x, fpx );
%
%  Try again with smaller gamma.
%
  fp_string = 'humps_deriv(x)';
  x0 = 0.4;
  gamma = 0.0005;

  fprintf ( 1, '\n' );
  fprintf ( 1, '  f(x) = "%s"\n', f_string );
  fprintf ( 1, '  f''(x) = "%s"\n', fp_string );
  fprintf ( 1, '  x0 = %f\n', x0 );
  fprintf ( 1, '  gamma = %f\n', gamma );
  [ x, it ] = opt_gradient_descent ( fp_string, x0, gamma );
  fx = humps_fun ( x );
  fpx = humps_deriv ( x );
  fprintf ( 1, '  f (%24.16g)=%24.16g,\n', x, fx );
  fprintf ( 1, '  f''(%24.16g)=%24.16g\n', x, fpx );
%
%  Function formula.
%
  f_string = 'x/10 + cos(x) + sin(1.0) + pi';
  fp_string = '1/10 - sin(x)';
  x0 = 1.0;
  gamma = 0.01;
  fprintf ( 1, '\n' );
  fprintf ( 1, '  f(x) = "%s"\n', f_string );
  fprintf ( 1, '  f''(x) = "%s"\n', fp_string );
  fprintf ( 1, '  x0 = %f\n', x0 );
  fprintf ( 1, '  gamma = %f\n', gamma );
  [ x, it ] = opt_gradient_descent ( fp_string, x0, gamma );
  fx = x/10 + cos(x) + sin(1.0) + pi;
  fpx = 1/10 - sin(x);
  fprintf ( 1, '  f (%24.16g)=%24.16g,\n', x, fx );
  fprintf ( 1, '  f''(%24.16g)=%24.16g\n', x, fpx );
%
%  Terminate.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'opt_gradient_descent_test():\n' );
  fprintf ( 1, '  Normal end of execution.\n' );
  timestamp ( );

  rmpath ( '../opt_gradient_descent' );

  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

