function sling_ode45 ( )

%*****************************************************************************80
%
%% sling_ode45() tests sling_ode using ode45().
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    30 May 2021
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'sling_ode45():\n' );
  fprintf ( 1, '  Test sling_ode() using ode45.\n' );

  [ s, t0, y0, tstop ] = sling_parameters ( );

  f = @ sling_deriv;
  tspan = [ t0, tstop ];
  [ t, y ] = ode45 ( f, tspan, y0 );

  n = length ( t );
  fprintf ( 1, '  Number of steps taken was %d\n', n );
%
%  Plot u, v.
%
  figure ( 1 );
  clf ( );
  hold ( 'on' );
    plot ( t, y(:,1), 'r-', 'linewidth', 2 );
    plot ( t, y(:,2), 'b-', 'linewidth', 2 );
  hold ( 'off' );
  grid ( 'on' );
  xlabel ( '<-- Time -->' );
  ylabel ( '<-- Solution components -->' );
  title_string = sprintf ( 'sling ode45: plot, s = %g\n', s );
  title ( title_string );
  legend ( 'x', 'y' );
  filename = sprintf ( 'sling_ode45_plot_%g.png', s );
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved in "%s"\n', filename );
%
%  Phase plot.
%
  figure ( 2 );
  clf ( );
  hold ( 'on' );
    plot ( y(:,1), y(:,2), 'b-', 'linewidth', 2 );
    plot ( y(1,1), y(1,2), 'g.', 'markersize', 20 );
    plot ( y(end,1), y(end,2), 'r.', 'markersize', 20 );
  hold ( 'off' );
  grid ( 'on' );
  xlabel ( '<-- x -->' );
  ylabel ( '<-- y -->' );
  title_string = sprintf ( 'sling ode45: phase, s = %g\n', s );
  title ( title_string );
  axis ( 'equal' );
  filename = sprintf ( 'sling_ode45_phase_%g.png', s );
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved in "%s"\n', filename );
%
%  Plot energy.
%
  h = sling_conserved ( y );

  figure ( 3 );
  clf ( );
  hold ( 'on' );
    plot ( t, h, 'r-', 'linewidth', 2 );
    plot ( [ t0, tstop ], [ h(1), h(1) ], 'b--', 'linewidth', 2 );
    plot ( [ t0, tstop ], [ 0.0, 0.0 ], 'k-', 'linewidth', 2 );
  hold ( 'off' );
  grid ( 'on' );
  xlabel ( '<-- Time -->' );
  ylabel ( '<-- Energy -->' );
  title_string = sprintf ( 'sling ode45: energy, s = %g\n', s );
  title ( title_string );
  legend ( 'Computed energy', 'Exact energy', 'Zero energy' );
  filename = sprintf ( 'sling_ode45_conservation_%g.png', s );
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved in "%s"\n', filename );

  return
end

