Boost-Geometry-Utils
view release on metacpan or search on metacpan
src/boost/math/special_functions/ellint_rj.hpp view on Meta::CPAN
// Summer of Code 2006. JM modified it to fit into the
// Boost.Math conceptual framework better, and to correctly
// handle the p < 0 case.
//
#ifndef BOOST_MATH_ELLINT_RJ_HPP
#define BOOST_MATH_ELLINT_RJ_HPP
#ifdef _MSC_VER
#pragma once
#endif
#include <boost/math/special_functions/math_fwd.hpp>
#include <boost/math/tools/config.hpp>
#include <boost/math/policies/error_handling.hpp>
#include <boost/math/special_functions/ellint_rc.hpp>
#include <boost/math/special_functions/ellint_rf.hpp>
// Carlson's elliptic integral of the third kind
// R_J(x, y, z, p) = 1.5 * \int_{0}^{\infty} (t+p)^{-1} [(t+x)(t+y)(t+z)]^{-1/2} dt
// Carlson, Numerische Mathematik, vol 33, 1 (1979)
namespace boost { namespace math { namespace detail{
template <typename T, typename Policy>
T ellint_rj_imp(T x, T y, T z, T p, const Policy& pol)
{
T value, u, lambda, alpha, beta, sigma, factor, tolerance;
T X, Y, Z, P, EA, EB, EC, E2, E3, S1, S2, S3;
unsigned long k;
BOOST_MATH_STD_USING
using namespace boost::math::tools;
static const char* function = "boost::math::ellint_rj<%1%>(%1%,%1%,%1%)";
if (x < 0)
{
return policies::raise_domain_error<T>(function,
"Argument x must be non-negative, but got x = %1%", x, pol);
}
if(y < 0)
{
return policies::raise_domain_error<T>(function,
"Argument y must be non-negative, but got y = %1%", y, pol);
}
if(z < 0)
{
return policies::raise_domain_error<T>(function,
"Argument z must be non-negative, but got z = %1%", z, pol);
}
if(p == 0)
{
return policies::raise_domain_error<T>(function,
"Argument p must not be zero, but got p = %1%", p, pol);
}
if (x + y == 0 || y + z == 0 || z + x == 0)
{
return policies::raise_domain_error<T>(function,
"At most one argument can be zero, "
"only possible result is %1%.", std::numeric_limits<T>::quiet_NaN(), pol);
}
// error scales as the 6th power of tolerance
tolerance = pow(T(1) * tools::epsilon<T>() / 3, T(1) / 6);
// for p < 0, the integral is singular, return Cauchy principal value
if (p < 0)
{
//
// We must ensure that (z - y) * (y - x) is positive.
// Since the integral is symmetrical in x, y and z
// we can just permute the values:
//
if(x > y)
std::swap(x, y);
if(y > z)
std::swap(y, z);
if(x > y)
std::swap(x, y);
T q = -p;
T pmy = (z - y) * (y - x) / (y + q); // p - y
BOOST_ASSERT(pmy >= 0);
T p = pmy + y;
value = boost::math::ellint_rj(x, y, z, p, pol);
value *= pmy;
value -= 3 * boost::math::ellint_rf(x, y, z, pol);
value += 3 * sqrt((x * y * z) / (x * z + p * q)) * boost::math::ellint_rc(x * z + p * q, p * q, pol);
value /= (y + q);
return value;
}
// duplication
sigma = 0;
factor = 1;
k = 1;
do
{
u = (x + y + z + p + p) / 5;
X = (u - x) / u;
Y = (u - y) / u;
Z = (u - z) / u;
P = (u - p) / u;
if ((tools::max)(abs(X), abs(Y), abs(Z), abs(P)) < tolerance)
break;
T sx = sqrt(x);
T sy = sqrt(y);
T sz = sqrt(z);
lambda = sy * (sx + sz) + sz * sx;
alpha = p * (sx + sy + sz) + sx * sy * sz;
alpha *= alpha;
beta = p * (p + lambda) * (p + lambda);
sigma += factor * boost::math::ellint_rc(alpha, beta, pol);
factor /= 4;
x = (x + lambda) / 4;
( run in 1.228 second using v1.01-cache-2.11-cpan-39bf76dae61 )