function y = pendulum_nonlinear_exact ( t )

%*****************************************************************************80
%
%% pendulum_nonlinear_exact(): exact solution of pendulum_nonlinear_ode().
%
%  Discussion:
%
%    This function only returns the first component of the solution,
%    y(1), the angular deflection.
%
%    Moreover, this solution is only valid for the case that the
%    initial condition specifies y(2)=0, that is, the problem
%    starts with a presumably nonzero angular deflection, but
%    zero angular velocity.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    16 November 2020
%
%  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.
%
%  Input:
%
%    real T(:): the evaluation times.
%
%  Output:
%
%    real Y(:): the value of the first component of the solution.
%
  [ g, l, m, t0, y0, tstop ] = pendulum_nonlinear_parameters ( );

  omega0 = sqrt ( g / l );

  theta0 = y0(1);

  st = sin ( theta0 / 2.0 );

  y = 2.0 * asin ...
  ( ...
    st * ellipj ...
    ( ...
      ellipke ( st^2 ) - omega0 * t, st^2 ...
    ) ...
  );

  return
end

