function pendulum_nonlinear_period_test ( )

%*****************************************************************************80
%
%% pendulum_nonlinear_period_test() tests pendulum_nonlinear_period().
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    04 May 2021
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'pendulum_nonlinear_period_test():\n' );
  fprintf ( 1, '  Compute the period as a function of initial energy.\n' );

  [ g, l, m, t0, y0, tstop ] = pendulum_nonlinear_parameters ( );
  y0_save = y0;
  ep = 2.0 * m * g / l;

  fprintf ( 1, '\n' );
  fprintf ( 1, '  parameters:\n' );
  fprintf ( 1, '    g     = %g\n', g );
  fprintf ( 1, '    l     = %g\n', l );
  fprintf ( 1, '    m     = %g\n', m );
  fprintf ( 1, '    t0    = %g\n', t0 );
  fprintf ( 1, '    y0    = (%g,%g)\n', y0 );
  fprintf ( 1, '    tstop = %g\n', tstop );
  fprintf ( 1, '    Energy needed to flip      = %g\n', ep );
%
%  Set up some initial conditions.
%
  n = 100;
  theta = linspace ( 0.0, 0.99*pi, n );
  p = zeros ( n, 1 );
%
%  Compute a table of periods.
%
  verbose = false;

  for i = 1 : n
    y0 = [ theta(i), 0.0 ];
    [ g, l, m, t0, y0, tstop ] = pendulum_nonlinear_parameters ( g, l, m, t0, y0, tstop );
    p(i) = pendulum_nonlinear_period ( );
    e0 = pendulum_nonlinear_conserved ( y0 );
    if ( verbose )
      fprintf ( 1, '  %2d  (%g,%g)  %g  %g\n', i, y0, e0/ep, p(i) );
    end
  end
%
%  Plot the periods.
%
  figure ( );
  clf ( );
  plot ( theta, p, 'r-', 'linewidth', 3 );
  grid ( 'on' );
  xlabel ( '<-- Theta -->' );
  ylabel ( '<-- Period -->' );
  title ( 'pendulum_nonlinear_ode(): period' );
  filename = 'pendulum_nonlinear_period.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved in "%s"\n', filename );
%
%  Just in case, restore the default.
%
  y0 = y0_save;
  [ g, l, m, t0, y0, tstop ] = pendulum_nonlinear_parameters ( g, l, m, t0, y0, tstop );

  return
end

