function pendulum_nonlinear_ode_test ( )

%*****************************************************************************80
%
%% pendulum_nonlinear_ode_test tests pendulum_nonlinear_ode.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    08 November 2020
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'pendulum_nonlinear_ode_test:\n' );
  fprintf ( 1, '  MATLAB/Octave version %s\n', version ( ) );
  fprintf ( 1, '  Test pendulum_nonlinear_ode.\n' );

  [ g, l, m, t0, y0 ] = pendulum_nonlinear_parameters ( );

  fprintf ( 1, '\n' );
  fprintf ( 1, '  Initial angular deflection = %g radians\n', y0(1) );
  fprintf ( 1, '  Initial angular velocity = %g radians/second\n', y0(2) );

  tstop = 50.0;
  tspan = [ t0, tstop ];

  [ t, y ] = ode45 ( @pendulum_nonlinear_deriv, tspan, y0 );

  n = length ( t );
  fprintf ( 1, '  Number of adaptive time steps n = %d\n', n );
%
%  Plot Theta and dTheta/dT over time.
%
  figure ( );
  clf ( );
  plot ( t, y(:,1), 'b-', t, y(:,2), 'r-', 'linewidth', 2 );
  grid ( 'on' );
  xlabel ( '<-- Time -->' );
  ylabel ( '<-- Theta/ThetaDot -->' );
  title ( 'nonlinear pendulum, theta and thetadot.' );
  filename = 'pendulum_nonlinear_plot.png';
  print ( '-dpng', filename );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  Graphics saved in "%s"\n', filename );
%
%  Plot phase
%
  figure ( );
  clf ( );
  plot ( y(:,1), y(:,2), 'r-', 'linewidth', 2 );
  grid ( 'on' );
  xlabel ( '<-- Theta -->' );
  ylabel ( '<-- ThetaDot -->' );
  title ( 'nonlinear pendulum, phase.' );
  filename = 'pendulum_nonlinear_phase.png';
  print ( '-dpng', filename );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  Graphics saved in "%s"\n', filename );
%
%  Plot the energy.
%
  h = pendulum_nonlinear_conserved ( y );

  figure ( );
  clf ( );
  hold ( 'on' );
    plot ( t, h, 'b-', 'linewidth', 2 );
    plot ( [ t0, tstop ], [ 0.0, 0.0 ], 'k-', 'linewidth', 2 );
  hold ( 'off' );
  grid ( 'on' );
  xlabel ( '<-- Time -->' );
  ylabel ( '<-- Energy -->' );
  title ( 'nonlinear pendulum energy' );
  filename = 'pendulum_nonlinear_energy.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved in "%s"\n', filename );
%
%  Terminate.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'pendulum_nonlinear_ode_test:\n' );
  fprintf ( 1, '  Normal end of execution.\n' );

  return
end
