function p = predator_prey_period ( )

%*****************************************************************************80
%
%% predator_prey_period() computes the period of the predator prey limit cycle.
%
%  Discussion:
%
%    The period estimate of Shagi-Di Shi is based on the full nonlinear equation.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    17 December 2021
%
%  Author:
%
%    John Burkardt
%
%  Reference:
%
%    Shagi-Di Shih,
%    The period of a Lotka-Volterra System,
%    Taiwanese Journal of Mathematics,
%    Volume 1, Number 4, December 1997, pages 451-470.
%
%  Output:
%
%    real P: the estimated period.
%

%
%  Get the system parameters.
%
  [ alpha, beta, gamma, delta, t0, y0, tstop ] = predator_prey_parameters ( );
%
%  Rename two parameters to accord with his notation.
%
  a = alpha;
  d = gamma;
%
%  Compute the energy.
%
  E = predator_prey_conserved ( y0 );
%
%  The period is defined as an integral.
%
  p = integral ( @(s) predator_prey_period_integrand ( s, E, a, d ), 0.0, E ) / a / d;

  return
end
function value = predator_prey_period_integrand ( s, E, a, d )

%*****************************************************************************80
%
%% predator_prey_period_integrand() is the integrand for the period integral.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    17 December 2021
%
%  Author:
%
%    John Burkardt
%
%  Reference:
%
%    Shagi-Di Shih,
%    The period of a Lotka-Volterra System,
%    Taiwanese Journal of Mathematics,
%    Volume 1, Number 4, December 1997, pages 451-470.
%
%  Input:
%
%    real S: the independent variable.
%
%    real E: the energy.
%
%    real A, D: two parameter values.
%
%  Output:
%
%    real VALUE: the value of the integrand at S.
%
  value = predator_prey_period_phi ( s / d ) .* predator_prey_period_phi ( ( E - s ) / a );

  return
end
function value = predator_prey_period_phi ( s )

%*****************************************************************************80
%
%% predator_prey_period_phi() evaluates the phi(s) function.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    17 December 2021
%
%  Author:
%
%    John Burkardt
%
%  Reference:
%
%    Shagi-Di Shih,
%    The period of a Lotka-Volterra System,
%    Taiwanese Journal of Mathematics,
%    Volume 1, Number 4, December 1997, pages 451-470.
%
%  Input:
%
%    real S: the independent variable.
%
%  Output:
%
%    real VALUE: the value of phi(s).
%
  d1 = 1.0 + lambertw (  0, - exp ( - 1.0 - s ) );
  d2 = 1.0 + lambertw ( -1, - exp ( - 1.0 - s ) );
  value = 1.0 ./ d1 - 1.0 ./ d2;

  return
end
