File indexing completed on 2025-01-18 09:40:00
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef BOOST_MATH_SF_DETAIL_BESSEL_JY_ASYM_HPP
0013 #define BOOST_MATH_SF_DETAIL_BESSEL_JY_ASYM_HPP
0014
0015 #ifdef _MSC_VER
0016 #pragma once
0017 #endif
0018
0019 #include <boost/math/special_functions/factorials.hpp>
0020
0021 namespace boost{ namespace math{ namespace detail{
0022
0023 template <class T>
0024 inline T asymptotic_bessel_amplitude(T v, T x)
0025 {
0026
0027
0028 BOOST_MATH_STD_USING
0029 T s = 1;
0030 T mu = 4 * v * v;
0031 T txq = 2 * x;
0032 txq *= txq;
0033
0034 s += (mu - 1) / (2 * txq);
0035 s += 3 * (mu - 1) * (mu - 9) / (txq * txq * 8);
0036 s += 15 * (mu - 1) * (mu - 9) * (mu - 25) / (txq * txq * txq * 8 * 6);
0037
0038 return sqrt(s * 2 / (constants::pi<T>() * x));
0039 }
0040
0041 template <class T>
0042 T asymptotic_bessel_phase_mx(T v, T x)
0043 {
0044
0045
0046
0047
0048
0049
0050 T mu = 4 * v * v;
0051 T denom = 4 * x;
0052 T denom_mult = denom * denom;
0053
0054 T s = 0;
0055 s += (mu - 1) / (2 * denom);
0056 denom *= denom_mult;
0057 s += (mu - 1) * (mu - 25) / (6 * denom);
0058 denom *= denom_mult;
0059 s += (mu - 1) * (mu * mu - 114 * mu + 1073) / (5 * denom);
0060 denom *= denom_mult;
0061 s += (mu - 1) * (5 * mu * mu * mu - 1535 * mu * mu + 54703 * mu - 375733) / (14 * denom);
0062 return s;
0063 }
0064
0065 template <class T, class Policy>
0066 inline T asymptotic_bessel_y_large_x_2(T v, T x, const Policy& pol)
0067 {
0068
0069 BOOST_MATH_STD_USING
0070
0071 T ampl = asymptotic_bessel_amplitude(v, x);
0072 T phase = asymptotic_bessel_phase_mx(v, x);
0073 BOOST_MATH_INSTRUMENT_VARIABLE(ampl);
0074 BOOST_MATH_INSTRUMENT_VARIABLE(phase);
0075
0076
0077
0078
0079
0080
0081 T cx = cos(x);
0082 T sx = sin(x);
0083 T ci = boost::math::cos_pi(v / 2 + 0.25f, pol);
0084 T si = boost::math::sin_pi(v / 2 + 0.25f, pol);
0085 T sin_phase = sin(phase) * (cx * ci + sx * si) + cos(phase) * (sx * ci - cx * si);
0086 BOOST_MATH_INSTRUMENT_CODE(sin(phase));
0087 BOOST_MATH_INSTRUMENT_CODE(cos(x));
0088 BOOST_MATH_INSTRUMENT_CODE(cos(phase));
0089 BOOST_MATH_INSTRUMENT_CODE(sin(x));
0090 return sin_phase * ampl;
0091 }
0092
0093 template <class T, class Policy>
0094 inline T asymptotic_bessel_j_large_x_2(T v, T x, const Policy& pol)
0095 {
0096
0097 BOOST_MATH_STD_USING
0098
0099 T ampl = asymptotic_bessel_amplitude(v, x);
0100 T phase = asymptotic_bessel_phase_mx(v, x);
0101 BOOST_MATH_INSTRUMENT_VARIABLE(ampl);
0102 BOOST_MATH_INSTRUMENT_VARIABLE(phase);
0103
0104
0105
0106
0107
0108
0109 BOOST_MATH_INSTRUMENT_CODE(cos(phase));
0110 BOOST_MATH_INSTRUMENT_CODE(cos(x));
0111 BOOST_MATH_INSTRUMENT_CODE(sin(phase));
0112 BOOST_MATH_INSTRUMENT_CODE(sin(x));
0113 T cx = cos(x);
0114 T sx = sin(x);
0115 T ci = boost::math::cos_pi(v / 2 + 0.25f, pol);
0116 T si = boost::math::sin_pi(v / 2 + 0.25f, pol);
0117 T sin_phase = cos(phase) * (cx * ci + sx * si) - sin(phase) * (sx * ci - cx * si);
0118 BOOST_MATH_INSTRUMENT_VARIABLE(sin_phase);
0119 return sin_phase * ampl;
0120 }
0121
0122 template <class T>
0123 inline bool asymptotic_bessel_large_x_limit(int v, const T& x)
0124 {
0125 BOOST_MATH_STD_USING
0126
0127
0128
0129
0130
0131
0132
0133
0134
0135
0136 BOOST_MATH_ASSERT(v >= 0);
0137 return (v ? v : 1) < x * 0.004f;
0138 }
0139
0140 template <class T>
0141 inline bool asymptotic_bessel_large_x_limit(const T& v, const T& x)
0142 {
0143 BOOST_MATH_STD_USING
0144
0145
0146
0147
0148
0149
0150
0151
0152
0153
0154 return (std::max)(T(fabs(v)), T(1)) < x * sqrt(tools::forth_root_epsilon<T>());
0155 }
0156
0157 template <class T, class Policy>
0158 void temme_asymptotic_y_small_x(T v, T x, T* Y, T* Y1, const Policy& pol)
0159 {
0160 T c = 1;
0161 T p = (v / boost::math::sin_pi(v, pol)) * pow(x / 2, -v) / boost::math::tgamma(1 - v, pol);
0162 T q = (v / boost::math::sin_pi(v, pol)) * pow(x / 2, v) / boost::math::tgamma(1 + v, pol);
0163 T f = (p - q) / v;
0164 T g_prefix = boost::math::sin_pi(v / 2, pol);
0165 g_prefix *= g_prefix * 2 / v;
0166 T g = f + g_prefix * q;
0167 T h = p;
0168 T c_mult = -x * x / 4;
0169
0170 T y(c * g), y1(c * h);
0171
0172 for(int k = 1; k < policies::get_max_series_iterations<Policy>(); ++k)
0173 {
0174 f = (k * f + p + q) / (k*k - v*v);
0175 p /= k - v;
0176 q /= k + v;
0177 c *= c_mult / k;
0178 T c1 = pow(-x * x / 4, T(k)) / factorial<T>(k, pol);
0179 g = f + g_prefix * q;
0180 h = -k * g + p;
0181 y += c * g;
0182 y1 += c * h;
0183 if(c * g / tools::epsilon<T>() < y)
0184 break;
0185 }
0186
0187 *Y = -y;
0188 *Y1 = (-2 / x) * y1;
0189 }
0190
0191 template <class T, class Policy>
0192 T asymptotic_bessel_i_large_x(T v, T x, const Policy& pol)
0193 {
0194 BOOST_MATH_STD_USING
0195 T s = 1;
0196 T mu = 4 * v * v;
0197 T ex = 8 * x;
0198 T num = mu - 1;
0199 T denom = ex;
0200
0201 s -= num / denom;
0202
0203 num *= mu - 9;
0204 denom *= ex * 2;
0205 s += num / denom;
0206
0207 num *= mu - 25;
0208 denom *= ex * 3;
0209 s -= num / denom;
0210
0211
0212 T e = exp(x/2);
0213
0214 s = e * (e * s / sqrt(2 * x * constants::pi<T>()));
0215
0216 return (boost::math::isfinite)(s) ?
0217 s : policies::raise_overflow_error<T>("boost::math::asymptotic_bessel_i_large_x<%1%>(%1%,%1%)", nullptr, pol);
0218 }
0219
0220 }}}
0221
0222 #endif
0223