function normal_ode_test ( n1 )

%*****************************************************************************80
%
%% normal_ode_test() tests normal_ode().
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    04 May 2021
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer N1: the number of steps to take.
%
  addpath ( '../normal_ode' );

  if ( nargin < 1 )
    n1 = 100;
  end

  timestamp ( ); 
  fprintf ( 1, '\n' );
  fprintf ( 1, 'normal_ode_test():\n' );
  fprintf ( 1, '  MATLAB/Octave version %s\n', version ( ) );
  fprintf ( 1, '  Solve normal_ode() using the Euler method.\n' );
  fprintf ( 1, '  Estimate ODE approximation error by taking twice as many steps.\n' );

  [ t0, y0, tstop ] = normal_parameters ( );

  dydt = @ normal_deriv;
  tspan = [ t0, tstop ];

  [ t1, y1 ] = euler ( dydt, tspan, y0, n1 );

  n2 = 2 * n1;
  [ t2, y2 ] = euler ( dydt, tspan, y0, n2 );

  y = normal_exact ( t1 );

  e =  y(1:n1+1)    - y1(1:n1+1);
  e2 = y2(1:2:n2+1) - y1(1:n1+1);

  e_norm = rms ( e );
  e2_norm = rms ( e2 );

  figure ( 1 );
  tplot = linspace ( t0, tstop, 101 );
  yplot = normal_exact ( tplot );
  plot ( t1, y1, 'ro', t2, y2, 'b+', tplot, yplot, 'k-', 'linewidth', 3 );
  grid ( 'on' );
  s = sprintf ( 'normal_ode(): using %d and %d steps', n1, n2 );
  title ( s );
  legend ( 'N steps', '2N steps', 'exact', 'location', 'northwest' );
  filename = 'normal_ode_test.png';
  print ( '-dpng', filename );

  figure ( 2 );
  plot ( [t0,tstop], [0.0,0.0], 'k--', t1, e2, 'r-', t1, e, 'k-', 'linewidth', 3 );
  grid ( 'on' );
  s = sprintf ( 'normal_ode(): estimated error using %d and %d steps', n1, n2 );
  title ( s );
  legend ( 'Zero error', 'Estimated error', 'Exact error', 'location', 'northwest' );
  filename = 'normal_ode_error_test.png';
  print ( '-dpng', filename );

  fprintf ( 1, '\n' );
  fprintf ( 1, '  Solution used %d and %d steps\n', n1, n2 );
  fprintf ( 1, '  Estimated RMS error = %g\n', e2_norm );
  fprintf ( 1, '  Exact     RMS error = %g\n', e_norm );

  fprintf ( 1, '\n' );
  fprintf ( 1, '  At the point t         = %g\n', tstop );
  fprintf ( 1, '  Y estimate             = %g\n', y1(n1+1) );
  fprintf ( 1, '  Y double step estimate = %g\n', y2(n2+1) );
  fprintf ( 1, '  Y exact value          = %g\n', y(n1+1) );
  fprintf ( 1, '  Y error estimate       = %g\n', y2(n2+1) - y1(n1+1) );
  fprintf ( 1, '  Y exact error          = %g\n', y(n1+1)  - y1(n1+1) );
%
%  Terminate.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'normal_ode_test():\n' );
  fprintf ( 1, '  Normal end of execution.\n' );
  timestamp ( ); 

  rmpath ( '../normal_ode' );

  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

