function pendulum_ode45 ( )

%*****************************************************************************80
%
%% pendulum_ode45 tests pendulum_ode using the ode45 method.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    04 November 2020
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'pendulum_ode45:\n' );
  fprintf ( 1, '  Test pendulum_ode using ode45().\n' );

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

  f = @ pendulum_deriv;
  tspan = [ t0, 20.0 ];

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

  n = length ( t ) - 1;
  fprintf ( 1, '  Number of steps taken was N = %d\n', n );
 
  ye = pendulum_solution ( t );
%
%  Plot u = theta.
%
  figure ( 1 );
  clf ( );
  plot ( t, y(:,1), 'ro', ...
         t, ye(:,1), 'b-', 'linewidth', 2 );
  grid ( 'on' );
  xlabel ( '<-- Time -->' );
  ylabel ( '<-- Angular deflection (radians) -->' );
  title ( 'Linear pendulum, theta: ode45' );
  legend ( 'ode45', 'exact' );
  filename = 'pendulum_ode45_theta.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved in "%s"\n', filename );
%
%  Plot v = thetadot.
%
  figure ( 2 );
  clf ( );
  plot ( t, y(:,2), 'ro', ...
         t, ye(:,2), 'b-', 'linewidth', 2 );
  grid ( 'on' );
  xlabel ( '<-- Time -->' );
  ylabel ( '<-- Angular velocity (radians/sec) -->' );
  title ( 'Linear pendulum, thetadot: ode45' );
  legend ( 'ode45', 'exact' );
  filename = 'pendulum_ode45_thetadot.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved in "%s"\n', filename );
%
%  Plot energy.
%
  h = pendulum_energy ( y );

  figure ( 3 );
  clf ( );
  hold ( 'on' );
    plot ( t, h, 'b-', 'linewidth', 2 );
    plot ( [t(1), t(end) ], [ 0.0, 0.0 ], 'k-', 'linewidth', 2 );
  hold ( 'off' );
  grid ( 'on' );
  xlabel ( '<-- Time -->' );
  ylabel ( '<-- Energy -->' );
  title ( 'Energy conservation: ode45' );
  filename = 'pendulum_ode45_energy.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved in "%s"\n', filename );
  fprintf ( 1, '  h(1) = %g, h(n+1) = %g\n', h(1), h(n+1) );

  return
end

