function pendulum_nonlinear_ode23 ( )

%*****************************************************************************80
%
%% pendulum_nonlinear_ode23() tests pendulum_nonlinear_ode using ode23().
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    12 July 2021
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'pendulum_nonlinear_ode23():\n' );
  fprintf ( 1, '  Test pendulum_nonlinear_ode using ode23.\n' );

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

  f = @pendulum_nonlinear_deriv;
  tspan = [ t0, tstop ];

  [ t, y ] = ode23 ( f, tspan, y0 );

  n = length ( t );
  fprintf ( 1, '  Number of adaptive steps = %d\n', n );
%
%  Plot theta, and exact theta.
%
  ye = pendulum_nonlinear_exact ( t );

  figure ( 1 );
  clf ( );
  plot ( t, y(:,1), 'ro', ...
         t, ye(:,1), 'b-', 'linewidth', 2 );
  grid ( 'on' );
  xlabel ( '<-- Time -->' );
  ylabel ( '<-- Theta -->' );
  title ( 'nonlinear pendulum, ode23: angular deflection.' );
  legend ( 'Computed', 'Exact' );
  filename = 'pendulum_nonlinear_ode23_theta.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved in "%s"\n', filename );
  close ( );
%
%  Plot dtheta/dt
%
  figure ( 2 );
  clf ( );
  plot ( t, y(:,2), 'ro', ...
         t, ye(:,2), 'b-', 'linewidth', 2 );
  grid ( 'on' );
  xlabel ( '<-- Time -->' );
  ylabel ( '<-- ThetaDot -->' );
  title ( 'nonlinear pendulum, ode23: angular velocity.' );
  legend ( 'Computed', 'Exact' );
  filename = 'pendulum_nonlinear_ode23_thetadot.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved in "%s"\n', filename );
  close ( );
%
%  Plot phase
%
  figure ( 3 );
  clf ( );
  plot ( y(:,1), y(:,2), 'ro', ...
         ye(:,1), ye(:,2), 'b-', 'linewidth', 3 );
  grid ( 'on' );
  xlabel ( '<-- Theta -->' );
  ylabel ( '<-- ThetaDot -->' );
  title ( 'nonlinear pendulum, ode23: phase.' );
  legend ( 'Computed', 'Exact' );
  filename = 'pendulum_nonlinear_ode23_phase.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved in "%s"\n', filename );
  close ( );
%
%  Plot energy.
%
  h = pendulum_nonlinear_conserved ( y );
  he = pendulum_nonlinear_conserved ( ye );

  figure ( 4 );
  clf ( );
  hold ( 'on' );
    plot ( t, h, 'ro', 'linewidth', 3 );
    plot ( t, he, 'b--', 'linewidth', 3 );
    plot ( [ t0, tstop ], [ 0.0, 0.0 ], 'k-', 'linewidth', 2 );
  hold ( 'off' );
  grid ( 'on' );
  xlabel ( '<-- Time -->' );
  ylabel ( '<-- Energy -->' );
  title ( 'nonlinear pendulum, ode23: energy' );
  legend ( 'Computed', 'Exact', 'x axis' );
  filename = 'pendulum_nonlinear_ode23_energy.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved in "%s"\n', filename );
  close ( );
%
%  Terminate.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'pendulum_nonlinear_ode23():\n' );
  fprintf ( 1, '  Normal end of execution.\n' );

  return
end
