function henon_heiles_ode45 ( tspan, w0 )

%*****************************************************************************80
%
%% henon_heiles_ode45 uses ode45() to solve the Henon Heiles problem.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    24 April 2020
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'henon_heiles_ode45_test:\n' );
  fprintf ( 1, '  Use ode45 to solve the Henon Heiles problem.\n' );

  [ t, w ] = ode45 ( @henon_heiles_deriv, tspan, w0 );

  n = length ( t );

  if ( 500 < n )
    ilo = n - 500;
  else
    ilo = 1;
  end

  figure ( 1 );
  clf ( );
  hold ( 'on' );
  plot ( t(ilo:n), w(ilo:n,1), 'r-', 'linewidth', 2 );
  plot ( t(ilo:n), w(ilo:n,2), 'g-', 'linewidth', 2 );
  plot ( t(ilo:n), w(ilo:n,3), 'b-', 'linewidth', 2 );
  plot ( t(ilo:n), w(ilo:n,4), 'm-', 'linewidth', 2 );
  hold ( 'off' );
  grid ( 'on' );
  xlabel ( '<---  t  --->' );
  ylabel ( '<---  p,q  --->' );
  title ( 'ode45: Henon Heiles Time Plot', 'fontsize', 16 )
  legend ( 'X', 'X''', 'Y', 'Y''' );
  filename = 'henon_heiles_ode45_plot.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );

  figure ( 2 );
  plot ( w(ilo:n,1), w(ilo:n,3) );
  grid ( 'on' );
  xlabel ( '<---  q1  --->' );
  ylabel ( '<---  q2  --->' );
  title ( 'ode45: Henon Heiles Orbit', 'fontsize', 16 )
  filename = 'henon_heiles_ode45_orbit.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );

  h = henon_heiles_conserved ( w );

  figure ( 3 );
  clf ( );
  hold ( 'on' );
  plot ( t, h, 'r-', 'linewidth', 3 );
  plot ( [ t(1), t(end) ], [0.0, 0.0 ], 'k-', 'linewidth', 3 );
  hold ( 'off' );
  grid ( 'on' );
  xlabel ( '<-- T -->', 'Fontsize', 16 );
  ylabel ( '<-- H(T) -->', 'Fontsize', 16 );
  title ( 'ode45: H(T) conservation', 'fontsize', 16 );
  filename = 'henon_heiles_ode45_conserved.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );

  return
end
