function oscillator_ode_test ( )

%*****************************************************************************80
%
%% oscillator_ode_test tests oscillator_ode().
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    09 February 2020
%
%  Author:
%
%    John Burkardt
%
  addpath ( '../oscillator_ode' )

  timestamp ( );
  fprintf ( 1, '\n' );
  fprintf ( 1, 'oscillator_ode_test:\n' );
  fprintf ( 1, '  MATLAB/Octave version %s\n', version ( ) );
  fprintf ( 1, '  Test oscillator_ode using ode45.\n' );

  f = @ oscillator_deriv;
  [ alpha, beta, epsilon, t0, y0 ] = oscillator_parameters ( );
  tstop = 2.0 * pi;
  tspan = [ t0, tstop ];

  [ t, y ] = ode45 ( f, tspan, y0 );
%
%  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 Time Plot' )
  filename = 'oscillator_plot.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 Phase Plot' )
  axis ( 'equal' );
  filename = 'oscillator_phase.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, 'linewidth', 2 );
  plot ( tspan, [ 0.0, 0.0 ], 'k-', 'linewidth', 2 );
  hold ( 'off' );
  grid ( 'on' );
  xlabel ( '<--- t --->' );
  ylabel ( '<--- h(t) --->' );
  title ( 'Oscillator conservation Plot' )
  filename = 'oscillator_conservation.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );
%
%  Terminate.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'oscillator_ode_test:\n' );
  fprintf ( 1, '  Normal end of execution.\n' );
  fprintf ( 1, '\n' );
  timestamp ( );

  rmpath ( '../oscillator_ode' )

  return
end
