function pendulum_compare_euler ( n )

%*****************************************************************************80
%
%% pendulum_compare_euler compares computed and exact pendulum solutions.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    29 October 2019
%
%  Author:
%
%    John Burkardt
%
  if ( nargin < 1 )
    n = input ( 'Enter number of timesteps n: ' );
  end

  a = 0.0;
  b = 6.0 * pi;
  u = 1.0;
  v = 0.0;
  y0 = [ u, v ];
  
  [ t, y ] = euler ( @(t,y)pendulum_prime(t,y), n, a, b, y0 );

  figure ( 1 )
  clf ( );
  hold ( 'on' );
  plot ( t, y, 'r-', 'linewidth', 3 );
  yexact = pendulum_exact ( t, y0 );
  plot ( t, yexact, 'b-', 'linewidth', 3 );
  hold ( 'off' );
  grid ( 'on' );
  xlabel ( '<-- T -->' );
  ylabel ( '<-- Y(T) -->' );
  dt = ( b - a ) / n;
  label = sprintf ( 'pendulum ODE with dt = %g\n', dt );
  title ( label );
  filename = 'pendulum_compare_plot.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );

  figure ( 2 )
  clf ( );
  hold ( 'on' );
  plot ( y(:,1), y(:,2), 'm-', 'linewidth', 3 );
  plot ( y(1,1), y(1,2), 'g.', 'markersize', 40 );
  plot ( y(end,1), y(end,2), 'r.', 'markersize', 30 );
  plot ( yexact(:,1), yexact(:,2), 'b-', 'linewidth', 3 );
  hold ( 'off' );
  grid ( 'on' );
  axis ( 'equal' );
  xlabel ( '<-- Theta -->' );
  ylabel ( '<-- dThetadT -->' );
  dt = ( b - a ) / n;
  label = sprintf ( 'Pendulum ODE with dt = %g\n', dt );
  title ( label );
  filename = 'pendulum_compare_phase.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );

  return
end
  
