function p = pendulum_nonlinear_period ( )

%*****************************************************************************80
%
%% pendulum_nonlinear_period(): period for pendulum_nonlinear_ode().
%
%  Discussion:
%
%    The formula used here is based on the initial energy, and does not assume 
%    that the initial velocity is zero.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    04 May 2021
%
%  Author:
%
%    John Burkardt
%
%  Reference:
%
%    Augusto Belendez, Carolina Pascual, David Mendez, 
%    Tarsicio Belendez Vazquez, Cristian Neipp,
%    Exact solution of the nonlinear pendulum problem,
%    Revista Brasileira de Ensino de Fisica,
%    Volume 29, Number 4, pages 645-648, 2007.
%
%    Karlheinz Ochs,
%    A comprehensive analytical solution of the nonlinear pendulum,
%    European Journal of Physics,
%    Volume 32, pages 479-490, 2011.
%
%  Output:
%
%    real P: the length of the period.
%

%
%  Get the parameters.
%
  [ g, l, m, t0, y0, tstop ] = pendulum_nonlinear_parameters ( );
%
%  Get the initial energy.
%
  e0 = pendulum_nonlinear_conserved ( y0 );
%
%  Get the energy needed to just reach the vertical position.
%
  emax = 2.0 * m * g / l;
%
%  The period is essentially infinite if the energy meets or exceeds the
%  "flip over" energy.
%
  if ( emax <= e0 )
    p = Inf;
  else
    k = sqrt ( e0 / emax );
    p = 4.0 * sqrt ( l / g ) * ellipke ( k );
  end

  return
end

