function roots_rc_test ( )

%*****************************************************************************80
%
%% roots_rc_test() tests roots_rc().
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    07 March 2019
%
%  Author:
%
%    John Burkardt
%
  addpath ( '../roots_rc' );

  timestamp ( );
  fprintf ( 1, '\n' );
  fprintf ( 1, 'roots_rc_test():\n' );
  fprintf ( 1, '  MATLAB/Octave version %s\n', version ( ) );
  fprintf ( 1, '  roots_rc() seeks a solution of\n' );
  fprintf ( 1, '  the N-dimensional nonlinear system F(X) = 0.\n' );

  n = 4;
  it_max = 30;

  fprintf ( 1, '\n' );
  fprintf ( 1, '       FERR          X\n' );
  fprintf ( 1, '\n' );
%
%  Initialization.
%
  q(1:2*n+2,1:n+2) = 0.0;

  xnew(1) = 1.2;
  xnew(2:n) = 1.0;

  it = 0;

  while ( true )

    x(1:n) = xnew(1:n);

    fx(1) = 1.0 - x(1);
    fx(2:n) = 10.0 * ( x(2:n) - x(1:n-1).^2 );

    if ( it == 0 )
      fprintf ( 1, '                ' );
    else
      fprintf ( 1, '  %14.6g', ferr );
    end
    for i = 1 : n
      fprintf ( 1, '  %14.6g', x(i) );
    end
    fprintf ( 1, '\n' );

    [ xnew, ferr, q ] = roots_rc ( n, x, fx, q );

    if ( ferr < 1.0E-07 )
      fprintf ( 1, '\n' );
      fprintf ( 1, '  Sum of |f(x)| less than tolerance.\n' );
      break
    end

    if ( it_max < it )
      fprintf ( 1, '\n' );
      fprintf ( 1, '  Too many iterations!\n' );
      break
    end

    it = it + 1;

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

  rmpath ( '../roots_rc' );

  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

