function henon_heiles_ode23s ( )

%*****************************************************************************80
%
%% henon_heiles_ode23s() uses ode23s() to solve henon_heiles_ode().
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    23 April 2021
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'henon_heiles_ode23s():\n' );
  fprintf ( 1, '  Use ode23s() to solve henon_heiles_ode().\n' );

  [ e, lam, t0, y0, tstop ] = henon_heiles_parameters ( );

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

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

  n = length ( t );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  Number of variable steps was %d\n', n );

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

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

  figure ( 2 );
  plot ( y(ilo:n,1), y(ilo:n,3) );
  grid ( 'on' );
  xlabel ( '<---  q1  --->' );
  ylabel ( '<---  q2  --->' );
  title ( 'henon\_heiles\_ode(): ode23s() Orbit', 'fontsize', 16 )
  filename = 'henon_heiles_ode23s_orbit.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );

  h = henon_heiles_conserved ( y );

  figure ( 3 );
  clf ( );
  hold ( 'on' );
    plot ( t, h, 'r-', 'linewidth', 3 );
    plot ( [ t(1), t(end) ], [h(1),h(1) ], 'b--', '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 ( 'henon\_heiles\_ode(): ode23s(), H(T) conservation', 'fontsize', 16 );
  filename = 'henon_heiles_ode23s_conserved.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );

  return
end
