Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:40:11

0001 //  Copyright (c) 2006 Xiaogang Zhang, 2015 John Maddock
0002 //  Use, modification and distribution are subject to the
0003 //  Boost Software License, Version 1.0. (See accompanying file
0004 //  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0005 //
0006 //  History:
0007 //  XZ wrote the original of this file as part of the Google
0008 //  Summer of Code 2006.  JM modified it to fit into the
0009 //  Boost.Math conceptual framework better, and to correctly
0010 //  handle the y < 0 case.
0011 //  Updated 2015 to use Carlson's latest methods.
0012 //
0013 
0014 #ifndef BOOST_MATH_ELLINT_RC_HPP
0015 #define BOOST_MATH_ELLINT_RC_HPP
0016 
0017 #ifdef _MSC_VER
0018 #pragma once
0019 #endif
0020 
0021 #include <boost/math/policies/error_handling.hpp>
0022 #include <boost/math/tools/config.hpp>
0023 #include <boost/math/special_functions/math_fwd.hpp>
0024 #include <boost/math/special_functions/log1p.hpp>
0025 #include <boost/math/constants/constants.hpp>
0026 #include <iostream>
0027 
0028 // Carlson's degenerate elliptic integral
0029 // R_C(x, y) = R_F(x, y, y) = 0.5 * \int_{0}^{\infty} (t+x)^{-1/2} (t+y)^{-1} dt
0030 // Carlson, Numerische Mathematik, vol 33, 1 (1979)
0031 
0032 namespace boost { namespace math { namespace detail{
0033 
0034 template <typename T, typename Policy>
0035 T ellint_rc_imp(T x, T y, const Policy& pol)
0036 {
0037     BOOST_MATH_STD_USING
0038 
0039     static const char* function = "boost::math::ellint_rc<%1%>(%1%,%1%)";
0040 
0041     if(x < 0)
0042     {
0043        return policies::raise_domain_error<T>(function,
0044             "Argument x must be non-negative but got %1%", x, pol);
0045     }
0046     if(y == 0)
0047     {
0048        return policies::raise_domain_error<T>(function,
0049             "Argument y must not be zero but got %1%", y, pol);
0050     }
0051 
0052     // for y < 0, the integral is singular, return Cauchy principal value
0053     T prefix, result;
0054     if(y < 0)
0055     {
0056         prefix = sqrt(x / (x - y));
0057         x = x - y;
0058         y = -y;
0059     }
0060     else
0061        prefix = 1;
0062 
0063     if(x == 0)
0064     {
0065        result = constants::half_pi<T>() / sqrt(y);
0066     }
0067     else if(x == y)
0068     {
0069        result = 1 / sqrt(x);
0070     }
0071     else if(y > x)
0072     {
0073        result = atan(sqrt((y - x) / x)) / sqrt(y - x);
0074     }
0075     else
0076     {
0077        if(y / x > T(0.5))
0078        {
0079           T arg = sqrt((x - y) / x);
0080           result = (boost::math::log1p(arg, pol) - boost::math::log1p(-arg, pol)) / (2 * sqrt(x - y));
0081        }
0082        else
0083        {
0084           result = log((sqrt(x) + sqrt(x - y)) / sqrt(y)) / sqrt(x - y);
0085        }
0086     }
0087     return prefix * result;
0088 }
0089 
0090 } // namespace detail
0091 
0092 template <class T1, class T2, class Policy>
0093 inline typename tools::promote_args<T1, T2>::type 
0094    ellint_rc(T1 x, T2 y, const Policy& pol)
0095 {
0096    typedef typename tools::promote_args<T1, T2>::type result_type;
0097    typedef typename policies::evaluation<result_type, Policy>::type value_type;
0098    return policies::checked_narrowing_cast<result_type, Policy>(
0099       detail::ellint_rc_imp(
0100          static_cast<value_type>(x),
0101          static_cast<value_type>(y), pol), "boost::math::ellint_rc<%1%>(%1%,%1%)");
0102 }
0103 
0104 template <class T1, class T2>
0105 inline typename tools::promote_args<T1, T2>::type 
0106    ellint_rc(T1 x, T2 y)
0107 {
0108    return ellint_rc(x, y, policies::policy<>());
0109 }
0110 
0111 }} // namespaces
0112 
0113 #endif // BOOST_MATH_ELLINT_RC_HPP
0114