Boost-Geometry-Utils
view release on metacpan or search on metacpan
src/boost/math/special_functions/ellint_rj.hpp view on Meta::CPAN
// 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;
y = (y + lambda) / 4;
z = (z + lambda) / 4;
p = (p + lambda) / 4;
++k;
}
while(k < policies::get_max_series_iterations<Policy>());
// Check to see if we gave up too soon:
policies::check_series_iterations<T>(function, k, pol);
// Taylor series expansion to the 5th order
EA = X * Y + Y * Z + Z * X;
EB = X * Y * Z;
EC = P * P;
E2 = EA - 3 * EC;
E3 = EB + 2 * P * (EA - EC);
S1 = 1 + E2 * (E2 * T(9) / 88 - E3 * T(9) / 52 - T(3) / 14);
S2 = EB * (T(1) / 6 + P * (T(-6) / 22 + P * T(3) / 26));
S3 = P * ((EA - EC) / 3 - P * EA * T(3) / 22);
value = 3 * sigma + factor * (S1 + S2 + S3) / (u * sqrt(u));
return value;
}
} // namespace detail
template <class T1, class T2, class T3, class T4, class Policy>
inline typename tools::promote_args<T1, T2, T3, T4>::type
ellint_rj(T1 x, T2 y, T3 z, T4 p, const Policy& pol)
{
typedef typename tools::promote_args<T1, T2, T3, T4>::type result_type;
typedef typename policies::evaluation<result_type, Policy>::type value_type;
return policies::checked_narrowing_cast<result_type, Policy>(
detail::ellint_rj_imp(
static_cast<value_type>(x),
static_cast<value_type>(y),
static_cast<value_type>(z),
static_cast<value_type>(p),
pol), "boost::math::ellint_rj<%1%>(%1%,%1%,%1%,%1%)");
}
template <class T1, class T2, class T3, class T4>
inline typename tools::promote_args<T1, T2, T3, T4>::type
ellint_rj(T1 x, T2 y, T3 z, T4 p)
{
return ellint_rj(x, y, z, p, policies::policy<>());
}
}} // namespaces
#endif // BOOST_MATH_ELLINT_RJ_HPP
( run in 0.518 second using v1.01-cache-2.11-cpan-71847e10f99 )