function pendulum_euler ( n )

%*****************************************************************************80
%
%% pendulum_euler() uses euler() to solve the pendulum ODE.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    30 April 2021
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer n: the number of steps.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'pendulum_euler():\n' );
  fprintf ( 1, '  Use euler() to solve the pendulum ODE.\n' );

  f = @pendulum_deriv;
  t0 = 0.0;
  t1 = 12.0 * pi;
  tspan = [ t0, t1 ];
  uv0 = [ 1.0; 0.0 ];

  [ t, uv ] = euler ( f, tspan, uv0, n );

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

  figure ( 1 );
  plot ( t, uv, 'linewidth', 3 );
  grid ( 'on' );
  legend ( 'U(t)', 'U''(t)' );
  title ( 'Pendulum euler plot' );
  filename = 'pendulum_euler_plot.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );
  
  figure ( 2 );
  plot ( uv(:,1), uv(:,2), 'linewidth', 3 );
  grid ( 'on' );
  title ( 'Pendulum euler phase' );
  filename = 'pendulum_euler_phase.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );

  h = pendulum_conserved ( uv );

  figure ( 3 );
  hold ( 'on' )
    plot ( t, h, 'r-', 'linewidth', 3 );
    plot ( tspan, [h(1), h(1)], 'b--', 'linewidth', 3 );
    plot ( [tspan], [0.0,0.0], 'k--' );
  hold ( 'off' );
  grid ( 'on' );
  title ( 'Pendulum euler conservation' );
  filename = 'pendulum_euler_conservation.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );

  return
end

