function bisection_min_test ( )

%*****************************************************************************80
%
%% bisection_min_test() tests bisection_min().
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    01 March 2026
%
%  Author:
%
%    John Burkardt
%
  addpath ( '../bisection_min' );

  timestamp ( );

  fprintf ( 1, '\n' );
  fprintf ( 1, 'bisection_min_test():\n' );
  fprintf ( 1, '  MATLAB/Octavev version: %s\n', version ( ) );
  fprintf ( 1, '  bisection_min() seeks a minimizer\n' );
  fprintf ( 1, '  of a function f(x) in the interval [a,b],\n' );
  fprintf ( 1, '  assuming f(x) is strictly unimodal over [a,b],\n' );
%
%  humps(x) = 1 / ((x-0.3)^2 + 0.01) + 1 / ((x-0.9)^2 + 0.04) - 6.0
%
  a = 0.3;
  b = 0.9;
  x_tol = 0.000001;

  fprintf ( 1, '\n' );
  fprintf ( 1, '  f = humps_fun(x)\n' );
  fprintf ( 1, '  f(%g) = %g\n', a, humps_fun ( a ) );
  fprintf ( 1, '  f(%g) = %g\n', b, humps_fun ( b ) );
  fprintf ( 1, '  x_tol = %g\n', x_tol );
  [ a, m, b, it, nf ] = bisection_min ( @humps_fun, a, b, x_tol );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  Number of iterations: %d\n', it );
  fprintf ( 1, '  Function evaluations: %d\n', nf );
  fprintf ( 1, '  f(%g) = %g\n', a, humps_fun ( a ) );
  fprintf ( 1, '  f(%g) = %g\n', m, humps_fun ( m ) );
  fprintf ( 1, '  f(%g) = %g\n', b, humps_fun ( b ) );
%
%  test_fun(x)=x^4+10*x*sin(x^2)
%
  a = -2.0;
  b = 1.0;
  x_tol = 0.000001;

  fprintf ( 1, '\n' );
  fprintf ( 1, '  f = test_fun(x)\n' );
  fprintf ( 1, '  f(%g) = %g\n', a, test_fun ( a ) );
  fprintf ( 1, '  f(%g) = %g\n', b, test_fun ( b ) );
  fprintf ( 1, '  x_tol = %g\n', x_tol );
  [ a, m, b, it, nf ] = bisection_min ( @test_fun, a, b, x_tol );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  Number of iterations: %d\n', it );
  fprintf ( 1, '  Function evaluations: %d\n', nf );
  fprintf ( 1, '  f(%g) = %g\n', a, test_fun ( a ) );
  fprintf ( 1, '  f(%g) = %g\n', m, test_fun ( m ) );
  fprintf ( 1, '  f(%g) = %g\n', b, test_fun ( b ) );
%
%  Terminate.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'bisection_min_test():\n' );
  fprintf ( 1, '  Normal end of execution.\n' );

  timestamp ( );

  rmpath ( '../bisection_min' );

  return
end
function timestamp ( )

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

  return
end

