function oscillator_ode45 ( )

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

  [ alpha, beta, epsilon, t0, y0, tstop ] = oscillator_parameters ( );

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

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

  n = size ( t, 1 );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  Number of variable size steps = %d\n', n );
%
%  Solution plot.
%
  figure ( 1 );
  clf ( );
  plot ( t, y(:,1), 'g', ...
         t, y(:,2), 'r', ...
         'linewidth', 2 );
  grid ( 'on' );
  xlabel ( 'Time' );
  ylabel ( 'p(t), q(t)' );
  title ( 'oscillator_ode(): ode45(), Plot' )
  filename = 'oscillator_plot_ode45.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );
%
%  Phase plane plot.
%
  figure ( 2 );
  clf ( );
  plot ( y(:,1), y(:,2), 'linewidth', 2 );
  grid ( 'on' );
  xlabel ( '<--- p(t) --->' );
  ylabel ( '<--- q(t) --->' );
  title ( 'oscillator_ode(): ode45(), Phase' )
  axis ( 'equal' );
  filename = 'oscillator_phase_ode45.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );
%
%  Conservation.
%
  h = oscillator_conserved ( y );

  figure ( 3 );
  clf ( );
  hold ( 'on' );
    plot ( t, h, 'r-', 'linewidth', 2 );
    plot ( tspan, [ h(1), h(1) ], 'b--', 'linewidth', 2 );
    plot ( tspan, [ 0.0, 0.0 ], 'k-', 'linewidth', 2 );
  hold ( 'off' );
  grid ( 'on' );
  xlabel ( '<--- t --->' );
  ylabel ( '<--- h(t) --->' );
  title ( 'oscillator_ode(): ode45(), conservation' )
  filename = 'oscillator_conservation_ode45.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );

  return
end

