function p00_optisection_test ( x_tol )

%*****************************************************************************80
%
%% p00_optisection_test() tests p00_optisection().
%
%  Licensing:
%
%    This code is distributed under the MIT license. 
%
%  Modified:
%
%    01 May 2026
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    real x_tol: execution stops when the interval is smaller than x_tol.
%
  n = 100;
  c = 0.2;

  fprintf ( 1, '\n' );
  fprintf ( 1, 'p00_optisection_test():\n' );
  fprintf ( 1, '  Minimize f(x) in [a,b] using the optisection method of Kodnyanko.\n' );
  fprintf ( 1, '  The function f(x) is assumed to be unimodal.\n' );
  fprintf ( 1, '  Success is determined if the interval is no more than %g\n', x_tol );
  fprintf ( 1, '  Failure is determined if the number of iterations reaches %d\n', n );
  fprintf ( 1, '  The proportionality coefficient C is %g\n', c );
%
%  Get the number of tests.
%
  test_num = p00_test_num ( );

  for test = 1 : test_num

    title = p00_title ( test );

    fprintf ( 1, '\n' );
    fprintf ( 1, '  test %d\n', test );
    fprintf ( 1, '  "%s"\n', title );

    [ a, b ] = p00_interval ( test );
    fa = p00_f ( test, a );
    fb = p00_f ( test, b );
    fprintf ( 1, '  [ A,    B]:  %16.12e                      %16.12e\n', a,   b );
    fprintf ( 1, '  [FA,   FB]:  %16.12e                      %16.12e\n', fa,   fb );

    [ a, b, mx, my, it, nf ] = optisection ( @(x)p00_f ( test, x ), a, b, n, x_tol, c );
%
%  Print results.
%
    fa = p00_f ( test, a );
    fb = p00_f ( test, b );

    fprintf ( 1, '  Number of iterations: %d\n', it );
    fprintf ( 1, '  Function evaluations: %d\n', nf );
    fprintf ( 1, '  [ A, M, B]:  %16.12e  %16.12e  %16.12e\n', a,  mx, b );
    fprintf ( 1, '  [FA,FM,FB]:  %16.12e  %16.12e  %16.12e\n', fa, my, fb );

  end

  return
end

