function p00_bisection_test ( x_tol )

%*****************************************************************************80
%
%% p00_bisection_test() tests p00_bisection().
%
%  Licensing:
%
%    This code is distributed under the MIT license. 
%
%  Modified:
%
%    16 March 2026
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    real x_tol: bisection stops when the interval is smaller than x_tol.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'p00_bisection_test()\n' );
  fprintf ( 1, '  Minimize using the bisection method.\n' );
  fprintf ( 1, '  Bisection is halted when the interval is no more than %g\n', x_tol );
%
%  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 );

    it = 0;

    while ( true )

      if ( it == 0 )

        [ a, c ] = p00_interval ( test );
        b = 0.5 * ( a + c );
        fa = p00_f ( test, a );
        fb = p00_f ( test, b );
        fc = p00_f ( test, c );
        nf = 3;

      else

        d = 0.5 * ( a + b );
        fd = p00_f ( test, d );

        e = 0.5 * ( b + c );
        fe = p00_f ( test, e );

        nf = nf + 2;

        if ( fd <= fb )
          c = b;
          fc = fb;
          b = d;
          fb = fd;
        elseif ( fe <= fb )
          a = b;
          fa = fb;
          b = e;
          fb = fe;
        else
          a = d;
          fa = fd;
          c = e;
          fc = fe;
        end

      end 

      if ( abs ( c - a ) < x_tol )
        break;
      end

      it = it + 1;

    end
%
%  Print final (a,b,c) and (fa,fb,fc) results.
%
    fprintf ( 1, '  Number of iterations: %d\n', it );
    fprintf ( 1, '  Function evaluations: %d\n', nf );
    fprintf ( 1, '  X:  %16.12e  %16.12e  %16.12e\n', a,   b,  c );
    fprintf ( 1, '  F:  %16.12e  %16.12e  %16.12e\n', fa, fb, fc );

  end

  return
end

