function shm_leapfrog ( n )

%*****************************************************************************80
%
%% shm_leapfrog() uses leapfrog() to solve the shm ODE.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    30 April 2020
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer N: the number of steps to take.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'shm_leapfrog():\n' );
  fprintf ( 1, '  Use leapfrog() to solve the shm ODE.\n' );
%
%  Get parameters.
%
  [ t0, y0, tstop ] = shm_parameters ( );

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

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

  fprintf ( 1, '\n' );
  fprintf ( 1, '  Number of equal steps is %d\n', n );

  ye = shm_exact ( t );

  clf ( );
  hold ( 'on' );
    plot ( t, y(:,1), 'ro', 'linewidth', 2 );
    plot ( t, ye(:,1), 'b-', 'linewidth', 2 );
  hold ( 'off' );
  grid ( 'on' );
  xlabel ( '<--- T --->' );
  ylabel ( '<--- Y1(T) --->' );
  title ( 'SHM leapfrog: Y1(t)' );
  legend ( 'Leapfrog', 'Exact' );
  filename = 'shm_leapfrog_y1.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"', filename );

  clf ( );
  hold ( 'on' );
    plot ( t, y(:,2), 'ro', 'linewidth', 2 );
    plot ( t, ye(:,2), 'b-', 'linewidth', 2 );
  hold ( 'off' );
  grid ( 'on' );
  xlabel ( '<--- T --->' );
  ylabel ( '<--- Y2(T) --->' );
  title ( 'SHM leapfrog: Y2(t)' );
  legend ( 'Leapfrog', 'Exact' );
  filename = 'shm_leapfrog_y2.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"', filename );

  clf ( );
  plot ( y(:,1), y(:,2), 'r-', 'linewidth', 2 );
  grid ( 'on' );
  xlabel ( '<--- Y1(T) --->' );
  ylabel ( '<--- Y2(T) --->' );
  title ( 'SHM leapfrog: Phase' );
  axis ( 'equal' );
  filename = 'shm_leapfrog_phase.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"', filename );

  h = 0.5 * ( y(:,1).^2 + y(:,2).^2 );

  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 ( 'SHM leapfrog: conservation' );
  filename = 'shm_leapfrog_conservation.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"', filename );

  return
end

