function zero_laguerre_test ( )

%*****************************************************************************80
%
%% zero_laguerre_test() tests zero_laguerre().
%
%  Licensing:
%
%    This code is distributed under the MIT license. 
%
%  Modified:
%
%    27 March 2024
%
%  Author:
%
%    John Burkardt
%
  addpath ( '../zero_laguerre' );

  timestamp ( );

  fprintf ( 1, '\n' );
  fprintf ( 1, 'zero_laguerre_test():\n' );
  fprintf ( 1, '  MATLAB/Octave version %s\n', version ( ) );
  fprintf ( 1, '  Test zero_laguerre().\n' );

  test01 ( );
  test02 ( );
%
%  Terminate.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'zero_laguerre_test():\n' );
  fprintf ( 1, '  Normal end of execution.\n' );
  fprintf ( 1, '\n' );
  timestamp ( );

  rmpath ( '../zero_laguerre' );

  return
end
function test01 ( )

%*****************************************************************************80
%
%% test01() runs the tests on a polynomial function.
%
%  Licensing:
%
%    This code is distributed under the MIT license. 
%
%  Modified:
%
%    18 January 2007
%
%  Author:
%
%    John Burkardt
%

%
%  Give a starting point.
%
  x0 = 1.0;
%
%  The polynomial degree.
%
  degree = 3;
%
%  Set the error tolerance.
%
  abserr = 0.00001;
%
%  KMAX is the maximum number of iterations.
%
  kmax = 30;

  fprintf ( 1, '\n' );
  fprintf ( 1, 'test01():\n' );
  fprintf ( 1, '  (Polynomial function F(X))\n' );
  fprintf ( 1, '  Find a root of F(X)=(X+3)*(X+3)*(X-2)=0\n' );

  [ x, ierror, k ] = zero_laguerre ( x0, degree, abserr, kmax, @func01 );

  fprintf ( 1, '\n' );
  if ( ierror ~= 0 )
    fprintf ( 1, '  Iteration failed with ierror = %d\n', ierror );
  else
    fprintf ( 1, '  Iteration steps taken: %d\n', k );
    fprintf ( 1, '  Estimated root X = %g\n', x );
    fprintf ( 1, '  F(X) = %g\n', func01 ( x, 0 ) );
  end

  return
end
function fx = func01 ( x, ider )

%*****************************************************************************80
%
%% func01() computes the function value for the first test.
%
%  Licensing:
%
%    This code is distributed under the MIT license. 
%
%  Modified:
%
%    17 December 1998
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    real X, the point at which the evaluation is to take place.
%
%    integer IDER, specifies what is to be evaluated:
%    0, evaluate the function.
%    1, evaluate the first derivative.
%    2, evaluate the second derivative.
%
%  Output:
%
%    real FUNC01, the value of the function or derivative.
%
  if ( ider == 0 )
    fx = ( x + 3.0 )^2 * ( x - 2.0 );
  elseif ( ider == 1 )
    fx = ( x + 3.0 ) * ( 3.0 * x - 1.0 );
  elseif ( ider == 2 )
    fx = 6.0 * x + 8.0;
  end

  return
end
function test02 ( )

%*****************************************************************************80
%
%% test02() runs the tests on the Newton polynomial.
%
%  Licensing:
%
%    This code is distributed under the MIT license. 
%
%  Modified:
%
%    27 March 2024
%
%  Author:
%
%    John Burkardt
%

%
%  Give a starting point.
%
  x0 = 1.0;
%
%  The polynomial degree.
%
  degree = 3;
%
%  Set the error tolerance.
%
  abserr = 0.00001;
%
%  KMAX is the maximum number of iterations.
%
  kmax = 30;

  fprintf ( 1, '\n' );
  fprintf ( 1, 'test02():\n' );
  fprintf ( 1, '  (Polynomial function F(X))\n' );
  fprintf ( 1, '  p(x) = x^3 - 2x - 5\n' );

  [ x, ierror, k ] = zero_laguerre ( x0, degree, abserr, kmax, @func02 );

  fprintf ( 1, '\n' );
  if ( ierror ~= 0 )
    fprintf ( 1, '  Iteration failed with ierror = %d\n', ierror );
  else
    fprintf ( 1, '  Iteration steps taken: %d\n', k );
    fprintf ( 1, '  Estimated root X = %g\n', x );
    fprintf ( 1, '  F(X) = %g\n', func02 ( x, 0 ) );
  end

  return
end
function fx = func02 ( x, ider )

%*****************************************************************************80
%
%% func02() computes the function value for the Newton polynomial.
%
%  Licensing:
%
%    This code is distributed under the MIT license. 
%
%  Modified:
%
%    27 March 2024
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    real X, the point at which the evaluation is to take place.
%
%    integer IDER, specifies what is to be evaluated:
%    0, evaluate the function.
%    1, evaluate the first derivative.
%    2, evaluate the second derivative
%
%  Output:
%
%    real FUNC02, the value of the function or derivative.
%
  if ( ider == 0 )
    fx = x^3 - 2.0 * x - 5.0;
  elseif ( ider == 1 )
    fx = 3.0 * x^2 - 2.0;
  elseif ( ider == 2 )
    fx = 6.0 * x; 
  end

  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
