You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/besselj.jl
+13-33Lines changed: 13 additions & 33 deletions
Original file line number
Diff line number
Diff line change
@@ -59,21 +59,11 @@ function _besselj0(x::Float64)
59
59
q2 = (-1/8, 25/384, -1073/5120, 375733/229376)
60
60
p =evalpoly(x2, p2)
61
61
q =evalpoly(x2, q2)
62
-
if x >1e15
63
-
a =SQ2OPI(T) *sqrt(xinv) * p
64
-
xn =muladd(xinv, q, -PIO4(T))
65
-
s_x, c_x =sincos(x)
66
-
s_xn, c_xn =sincos(xn)
67
-
return a * (c_x * c_xn - s_x * s_xn)
68
-
end
69
62
end
70
63
71
64
a =SQ2OPI(T) *sqrt(xinv) * p
72
-
xn =muladd(xinv, q, -PIO4(T))
73
-
74
-
# the following computes b = cos(x + xn) more accurately
75
-
# see src/misc.jl
76
-
b =cos_sum(x, xn)
65
+
xn = xinv*q
66
+
b =sin_sum(x, pi/4, xn)
77
67
return a * b
78
68
end
79
69
end
@@ -137,21 +127,11 @@ function _besselj1(x::Float64)
137
127
q2 = (3/8, -21/128, 1899/5120, -543483/229376)
138
128
p =evalpoly(x2, p2)
139
129
q =evalpoly(x2, q2)
140
-
if x >1e15
141
-
a =SQ2OPI(T) *sqrt(xinv) * p
142
-
xn =muladd(xinv, q, -3*PIO4(T))
143
-
s_x, c_x =sincos(x)
144
-
s_xn, c_xn =sincos(xn)
145
-
return s * a * (c_x * c_xn - s_x * s_xn)
146
-
end
147
130
end
148
131
149
132
a =SQ2OPI(T) *sqrt(xinv) * p
150
-
xn =muladd(xinv, q, -3*PIO4(T))
151
-
152
-
# the following computes b = cos(x + xn) more accurately
153
-
# see src/misc.jl
154
-
b =cos_sum(x, xn)
133
+
xn = xinv*q
134
+
b =sin_sum(x, -pi/4, xn)
155
135
return a * b * s
156
136
end
157
137
end
@@ -182,7 +162,7 @@ end
182
162
#####
183
163
184
164
besselj0(z::T) where T <:Union{ComplexF32, ComplexF64}=besseli0(z/im)
185
-
besselj1(z::T) where T <:Union{ComplexF32, ComplexF64}=besseli1(z/im) * im
165
+
besselj1(z::T) where T <:Union{ComplexF32, ComplexF64}=besseli1(z/im) * im
186
166
187
167
188
168
# Bessel functions of the first kind of order nu
@@ -208,17 +188,17 @@ besselj1(z::T) where T <: Union{ComplexF32, ComplexF64} = besseli1(z/im) * im
208
188
#
209
189
# For values where the expansions for large arguments and orders are not valid, backward recurrence is employed after shifting the order up
210
190
# to where `besseljy_debye` is accurate then using downward recurrence. In general, the routine will be the slowest when ν ≈ x as all methods struggle at this point.
211
-
#
191
+
#
212
192
# [1] http://dlmf.nist.gov/10.2.E2
213
-
# [2] Bremer, James. "An algorithm for the rapid numerical evaluation of Bessel functions of real orders and arguments."
193
+
# [2] Bremer, James. "An algorithm for the rapid numerical evaluation of Bessel functions of real orders and arguments."
214
194
# Advances in Computational Mathematics 45.1 (2019): 173-211.
215
-
# [3] Matviyenko, Gregory. "On the evaluation of Bessel functions."
195
+
# [3] Matviyenko, Gregory. "On the evaluation of Bessel functions."
216
196
# Applied and Computational Harmonic Analysis 1.1 (1993): 116-135.
217
-
# [4] Heitman, Z., Bremer, J., Rokhlin, V., & Vioreanu, B. (2015). On the asymptotics of Bessel functions in the Fresnel regime.
197
+
# [4] Heitman, Z., Bremer, J., Rokhlin, V., & Vioreanu, B. (2015). On the asymptotics of Bessel functions in the Fresnel regime.
218
198
# Applied and Computational Harmonic Analysis, 39(2), 347-356.
219
-
# [5] Ratis, Yu L., and P. Fernández de Córdoba. "A code to calculate (high order) Bessel functions based on the continued fractions method."
199
+
# [5] Ratis, Yu L., and P. Fernández de Córdoba. "A code to calculate (high order) Bessel functions based on the continued fractions method."
Copy file name to clipboardExpand all lines: src/bessely.jl
+16-36Lines changed: 16 additions & 36 deletions
Original file line number
Diff line number
Diff line change
@@ -64,7 +64,7 @@ function _bessely0_compute(x::Float64)
64
64
z = w * w
65
65
p =evalpoly(z, PP_y0(T)) /evalpoly(z, PQ_y0(T))
66
66
q =evalpoly(z, QP_y0(T)) /evalpoly(z, QQ_y0(T))
67
-
xn = x -PIO4(T)
67
+
xn = x -pi/4
68
68
sc =sincos(xn)
69
69
p = p * sc[1] + w * q * sc[2]
70
70
return p *SQ2OPI(T) /sqrt(x)
@@ -81,21 +81,11 @@ function _bessely0_compute(x::Float64)
81
81
q2 = (-1/8, 25/384, -1073/5120, 375733/229376)
82
82
p =evalpoly(x2, p2)
83
83
q =evalpoly(x2, q2)
84
-
if x >1e15
85
-
a =SQ2OPI(T) *sqrt(xinv) * p
86
-
xn =muladd(xinv, q, -PIO4(T))
87
-
s_x, c_x =sincos(x)
88
-
s_xn, c_xn =sincos(xn)
89
-
return a * (s_x * c_xn + c_x * s_xn)
90
-
end
91
84
end
92
85
93
86
a =SQ2OPI(T) *sqrt(xinv) * p
94
-
xn =muladd(xinv, q, -PIO4(T))
95
-
96
-
# the following computes b = sin(x + xn) more accurately
97
-
# see src/misc.jl
98
-
b =sin_sum(x, xn)
87
+
xn = xinv*q
88
+
b =sin_sum(x, -pi/4, xn)
99
89
return a * b
100
90
end
101
91
end
@@ -170,21 +160,11 @@ function _bessely1_compute(x::Float64)
170
160
q2 = (3/8, -21/128, 1899/5120, -543483/229376)
171
161
p =evalpoly(x2, p2)
172
162
q =evalpoly(x2, q2)
173
-
if x >1e15
174
-
a =SQ2OPI(T) *sqrt(xinv) * p
175
-
xn =muladd(xinv, q, -3*PIO4(T))
176
-
s_x, c_x =sincos(x)
177
-
s_xn, c_xn =sincos(xn)
178
-
return a * (s_x * c_xn + c_x * s_xn)
179
-
end
180
163
end
181
164
182
165
a =SQ2OPI(T) *sqrt(xinv) * p
183
-
xn =muladd(xinv, q, -3*PIO4(T))
184
-
185
-
# the following computes b = sin(x + xn) more accurately
186
-
# see src/misc.jl
187
-
b =sin_sum(x, xn)
166
+
xn = xinv*q
167
+
b =sin_sum(-x, -pi/4, -xn)
188
168
return a * b
189
169
end
190
170
end
@@ -225,7 +205,7 @@ end
225
205
# for positive arguments and orders. For integer orders up to 250, forward recurrence is used starting from
226
206
# `bessely0` and `bessely1` routines for calculation of Y_{n}(x) of the zero and first order.
227
207
# For small arguments, Y_{ν}(x) is calculated from the power series (`bessely_power_series(nu, x`) form of J_{ν}(x) using the connection formula [1].
228
-
#
208
+
#
229
209
# When x < ν and ν being reasonably large, the debye asymptotic expansion (Eq. 33; [3]) is used `besseljy_debye(nu, x)`.
230
210
# When x > ν and x being reasonably large, the Hankel function is calculated from the debye expansion (Eq. 29; [3]) with `hankel_debye(nu, x)`
231
211
# and Y_{n}(x) is calculated from the imaginary part of the Hankel function.
@@ -234,20 +214,20 @@ end
234
214
#
235
215
# For values where the expansions for large arguments and orders are not valid, forward recurrence is employed after shifting the order down
236
216
# to where these expansions are valid then using recurrence. In general, the routine will be the slowest when ν ≈ x as all methods struggle at this point.
237
-
# Additionally, the Hankel expansion is only accurate (to Float64 precision) when x > 19 and the power series can only be computed for x < 7
217
+
# Additionally, the Hankel expansion is only accurate (to Float64 precision) when x > 19 and the power series can only be computed for x < 7
238
218
# without loss of precision. Therefore, when x > 19 the Hankel expansion is used to generate starting values after shifting the order down.
239
219
# When x ∈ (7, 19) and ν ∈ (0, 2) Chebyshev approximation is used with higher orders filled by recurrence.
240
-
#
220
+
#
241
221
# [1] https://dlmf.nist.gov/10.2#E3
242
-
# [2] Bremer, James. "An algorithm for the rapid numerical evaluation of Bessel functions of real orders and arguments."
222
+
# [2] Bremer, James. "An algorithm for the rapid numerical evaluation of Bessel functions of real orders and arguments."
243
223
# Advances in Computational Mathematics 45.1 (2019): 173-211.
244
-
# [3] Matviyenko, Gregory. "On the evaluation of Bessel functions."
224
+
# [3] Matviyenko, Gregory. "On the evaluation of Bessel functions."
245
225
# Applied and Computational Harmonic Analysis 1.1 (1993): 116-135.
246
-
# [4] Heitman, Z., Bremer, J., Rokhlin, V., & Vioreanu, B. (2015). On the asymptotics of Bessel functions in the Fresnel regime.
226
+
# [4] Heitman, Z., Bremer, J., Rokhlin, V., & Vioreanu, B. (2015). On the asymptotics of Bessel functions in the Fresnel regime.
247
227
# Applied and Computational Harmonic Analysis, 39(2), 347-356.
248
-
# [5] Ratis, Yu L., and P. Fernández de Córdoba. "A code to calculate (high order) Bessel functions based on the continued fractions method."
228
+
# [5] Ratis, Yu L., and P. Fernández de Córdoba. "A code to calculate (high order) Bessel functions based on the continued fractions method."
0 commit comments