function spring_ode23 ( )

%*****************************************************************************80
%
%% spring_ode23() uses ode23() to solve spring_ode().
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    26 April 2021
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'spring_ode23():\n' );
  fprintf ( 1, '  Test spring_ode() using ode23().\n' );

  [ m, b, k, t0, y0, tstop ] = spring_parameters ( );

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

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

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

  ye = spring_exact ( t );
%
%  Plot y1
%
  figure ( 1 );
  clf ( );
  plot ( t, y(:,1), 'ro', ...
         t, ye(:,1), 'b-', 'linewidth', 2 );
  grid ( 'on' );
  xlabel ( '<-- Time -->' );
  ylabel ( '<-- Displacement -->' );
  title ( 'spring_ode(): ode23, displacement' );
  legend ( 'ode23', 'exact' );
  filename = 'spring_ode23_y1.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved in "%s"\n', filename );
%
%  Plot y2.
%
  figure ( 2 );
  clf ( );
  plot ( t, y(:,2), 'ro', ...
         t, ye(:,2), 'b-', 'linewidth', 2 );
  grid ( 'on' );
  xlabel ( '<-- Time -->' );
  ylabel ( '<-- Velocity -->' );
  title ( 'spring_ode(): ode23, velocity' );
  legend ( 'ode23', 'exact' );
  filename = 'spring_ode23_y2.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved in "%s"\n', filename );
%
%  Plot phase.
%
  figure ( 3 );
  clf ( );
  plot ( y(:,1), y(:,2), 'ro', ...
         ye(:,1), ye(:,2), 'b-', 'linewidth', 2 );
  grid ( 'on' );
  xlabel ( '<-- Displacement -->' );
  ylabel ( '<-- Velocity -->' );
  title ( 'spring_ode(): ode23, phase' );
  legend ( 'ode23', 'exact' );
  filename = 'spring_ode23_phase.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved in "%s"\n', filename );
%
%  Plot energy.
%
  h = spring_conserved ( y );

  figure ( 4 );
  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 ( 'spring_ode(): ode23, energy' );
  filename = 'spring_ode23_conservation.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved in "%s"\n', filename );

  return
end

