function bisection_test ( )

%*****************************************************************************80
%
%% bisection_test() tests bisection().
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    04 December 2023
%
%  Author:
%
%    John Burkardt
%
  addpath ( '../bisection' );

  timestamp ( );
  fprintf ( 1, 'bisection_test():\n' );
  fprintf ( 1, '  MATLAB/Octave version %s\n', version ( ) );
  fprintf ( 1, '  Test bisection()\n' );

  bisection_example ( 0.0, 8.0, @(x) x.^2 - 2*x - 15, 'x.^2 - 2*x - 15' );

  bisection_example ( 0.0, 1.0, @(x) cos(x) - x, 'cos(x) - x' );

  bisection_example ( 0.0, 10.0, @(x) kepler(x), 'Kepler function'  );
%
%  Terminate.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'bisection_test():\n' );
  fprintf ( 1, '  Normal end of execution.\n' );
  timestamp ( );

  rmpath ( '../bisection' );

  return
end
function bisection_example ( a, b, f, f_string )

%*****************************************************************************80
%
%% bisection_example() applies bisection() to a particular example.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    04 December 2023
%
%  Author:
%
%    John Burkardt
%
  tol = 10.0 * eps * ( b - a );
  [ a, b, it ] = bisection ( a, b, tol, f );
  x = ( a + b ) / 2.0;
  fa = f(a);
  fb = f(b);
  fx = f(x);

  fprintf ( 1, '\n' );
  fprintf ( 1, '  Function = "%s"\n', f_string );
  fprintf ( 1, '  a = %24.16g, f(a) = %g\n', a, fa );
  fprintf ( 1, '  b = %24.16g, f(b) = %g\n', b, fb );
  fprintf ( 1, '  Interval tolerance = %g\n', tol );
  fprintf ( 1, '  Number of bisections = %d\n', it );
  fprintf ( 1, '  x = %24.16g, f(x) = %g\n', x, fx );

  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

