17 #include <gsl/gsl_sf_bessel.h>
26 complex_t J0_PowSer(
const complex_t z)
29 static const double eps = 1e-15;
30 static double a[] = {-7.03125e-2, 0.112152099609375, -0.5725014209747314,
31 6.074042001273483, -1.100171402692467e2, 3.038090510922384e3,
32 -1.188384262567832e5, 6.252951493434797e6, -4.259392165047669e8,
33 3.646840080706556e10, -3.833534661393944e12, 4.854014686852901e14,
34 -7.286857349377656e16, 1.279721941975975e19};
35 static double b[] = {7.32421875e-2, -0.2271080017089844, 1.727727502584457,
36 -2.438052969955606e1, 5.513358961220206e2, -1.825775547429318e4,
37 8.328593040162893e5, -5.006958953198893e7, 3.836255180230433e9,
38 -3.649010818849833e11, 4.218971570284096e13, -5.827244631566907e15,
39 9.476288099260110e17, -1.792162323051699e20};
41 double a0 = std::abs(z);
45 if (std::real(z) < 0.0)
49 complex_t z2 = 0.25 * z * z;
52 for (
size_t k = 1; k <= 40; ++k) {
53 cr *= -z2 / (double)(k * k);
55 if (std::abs(cr) < std::abs(cj0) * eps)
67 complex_t ct1 = z1 -
M_PI_4;
69 complex_t cq0 = -0.125;
70 const complex_t z1m2 = 1. / (z1 * z1);
71 complex_t ptmp = z1m2;
72 for (
size_t k = 0; k < kz; ++k) {
77 cj0 = std::sqrt(
M_2_PI / z1) * (cp0 * std::cos(ct1) - cq0 / z1 * std::sin(ct1));
86 complex_t J1_PowSer(
const complex_t z)
89 static const double eps = 1e-15;
91 static double a1[] = {0.1171875,
100 -3.833857520742790e10,
101 4.011838599133198e12,
102 -5.060568503314727e14,
103 7.572616461117958e16,
104 -1.326257285320556e19};
105 static double b1[] = {-0.1025390625, 0.2775764465332031, -1.993531733751297,
106 2.724882731126854e1, -6.038440767050702e2, 1.971837591223663e4,
107 -8.902978767070678e5, 5.310411010968522e7, -4.043620325107754e9,
108 3.827011346598605e11, -4.406481417852278e13, 6.065091351222699e15,
109 -9.833883876590679e17, 1.855045211579828e20};
111 double a0 = std::abs(z);
116 if (std::real(z) < 0.0)
120 const complex_t z2 = 0.25 * z * z;
123 for (
int k = 1; k <= 40; ++k) {
124 cr *= -z2 / (double)(k * (k + 1));
126 if (std::abs(cr) < std::abs(cj1) * eps)
140 complex_t cq1 = 0.375;
141 const complex_t z1m2 = 1. / (z1 * z1);
142 complex_t ptmp = z1m2;
143 for (
size_t k = 0; k < kz; ++k) {
148 const complex_t ct2 = z1 - 0.75 *
M_PI;
149 cj1 = std::sqrt(
M_2_PI / z1) * (cp1 * std::cos(ct2) - cq1 / z1 * std::sin(ct2));
151 if (std::real(z) < 0.0)
164 return gsl_sf_bessel_J0(x);
169 return gsl_sf_bessel_J1(x);
174 return x == 0 ? 0.5 : gsl_sf_bessel_J1(x) / x;
179 return gsl_sf_bessel_I0(x);
184 if (std::imag(z) == 0)
185 return gsl_sf_bessel_J0(std::real(z));
191 if (std::imag(z) == 0)
192 return gsl_sf_bessel_J1(std::real(z));
198 if (std::imag(z) == 0) {
199 double xv = std::real(z);
200 return xv == 0 ? 0.5 : gsl_sf_bessel_J1(xv) / xv;
202 return z == 0. ? 0.5 : J1_PowSer(z) / z;
Defines Bessel functions in namespace Math.
Defines M_PI and some more mathematical constants.
double J0(double x)
Bessel function of the first kind and order 0.
double I0(double x)
Modified Bessel function of the first kind and order 0.
double J1(double x)
Bessel function of the first kind and order 1.
double J1c(double x)
Bessel function J1(x)/x.