function pendulum_compare ( n )

%*****************************************************************************80
%
%% pendulum_compare compares plots and energies for three pendulum solutions.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    21 March 2020
%
%  Author:
%
%    John Burkardt
%
  if ( nargin < 1 )
    n = 100;
  end

  fprintf ( 1, '\n' );
  fprintf ( 1, 'pendulum_compare:\n' );
  fprintf ( 1, '  Compare plots and energies for three pendulum solutionss.\n' );
%
%  Compute solutions.
%
  [ t1, u1, v1 ] = pendulum_euler_backward ( n );
  [ t2, u2, v2 ] = pendulum_midpoint ( n );
  [ t3, u3, v3 ] = pendulum_rk4 ( n );

  figure ( 1 );
  plot ( t1, u1, 'r', ...
         t2, u2, 'g', ...
         t3, u3, 'b', ...
         'linewidth', 2 );
  xlabel ( '<-- t -->' );
  ylabel ( '<-- y(t) -->' );
  legend ( 'Backward Euler', 'Midpoint', 'RK4' );
  title ( 'Three solutions to a pendulum problem.' );
  grid ( 'on' );
  filename = 'pendulum_compare_plot.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );
%
%  Compute energies.
% 
  h1 = pendulum_conserved ( u1, v1 );
  h2 = pendulum_conserved ( u2, v2 );
  h3 = pendulum_conserved ( u3, v3 );

  figure ( 2 );
  plot ( t1, h1, 'r', ...
         t2, h2, 'g', ...
         t3, h3, 'b', ...
         'linewidth', 2 );
  xlabel ( '<-- t -->' );
  ylabel ( '<-- E(u,v) -->' );
  legend ( 'Backward Euler', 'Midpoint', 'RK4' );
  title ( 'Energy for a pendulum problem.' );
  grid ( 'on' );
  filename = 'pendulum_compare_energy.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );

  return
end

