function opt_golden_test ( )

%*****************************************************************************80
%
%% opt_golden_test() tests opt_golden().
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    11 August 2019
%
%  Author:
%
%    John Burkardt
%
  addpath ( '../opt_golden' );

  timestamp ( );
  fprintf ( 1, '\n' );
  fprintf ( 1, 'opt_golden_test():\n' );
  fprintf ( 1, '  MATLAB/Octave version %s\n', version ( ) );
  fprintf ( 1, '  opt_golden() seeks a minimizer\n' );
  fprintf ( 1, '  of a function f(x) in the interval [a,b],\n' );
  fprintf ( 1, '  assuming f(x) is unimodal over [a,b],\n' );
%
%  Use M file.
%
  f_string = 'humps_fun(x)';
  a = 0.3;
  b = 0.9;
  n = 25;
  x_tol = 0.000001;

  fprintf ( 1, '\n' );
  fprintf ( 1, '  f = "%s"\n', f_string );
  fprintf ( 1, '  f(%g) = %g\n', a, humps_fun ( a ) );
  fprintf ( 1, '  f(%g) = %g\n', b, humps_fun ( b ) );
  fprintf ( 1, '  iteration limit n = %d\n', n );
  fprintf ( 1, '  x_tol = %g\n', x_tol );
  [ a, b, it ] = opt_golden ( f_string, a, b, n, x_tol );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  %d iterations were taken\n', it );
  fprintf ( 1, '  f(%g) = %g\n', a, humps_fun ( a ) );
  fprintf ( 1, '  f(%g) = %g\n', b, humps_fun ( b ) );
%
%  Use a formula.
%
  f_string = 'x^4+10*x*sin(x^2)';
  a = -2.0;
  b = 1.0;
  n = 35;
  x_tol = 0.000001;

  fprintf ( 1, '\n' );
  fprintf ( 1, '  f = "%s"\n', f_string );
  x = a;
  fprintf ( 1, '  f(%g) = %g\n', a, x^4+10*x*sin(x^2) );
  x = b;
  fprintf ( 1, '  f(%g) = %g\n', b, x^4+10*x*sin(x^2) );
  fprintf ( 1, '  iteration limit n = %d\n', n );
  fprintf ( 1, '  x_tol = %g\n', x_tol );
  [ a, b, it ] = opt_golden ( f_string, a, b, n, x_tol );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  %d iterations were taken\n', it );
  x = a;
  fprintf ( 1, '  f(%g) = %g\n', a, x^4+10*x*sin(x^2) );
  x = b;
  fprintf ( 1, '  f(%g) = %g\n', b, x^4+10*x*sin(x^2) );
%
%  Terminate.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'opt_golden_test():\n' );
  fprintf ( 1, '  Normal end of execution.\n' );
  timestamp ( );

  rmpath ( '../opt_golden' );

  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
