Skip to content

Commit b0390d5

Browse files
committed
update docs and add reference
1 parent b838a20 commit b0390d5

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

src/airy.jl

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
11
# Airy functions
22
#
3-
# airyai(x), airybi(nu, x)
4-
# airyaiprime(x), airybiprime(nu, x)
3+
# airyai(z), airybi(nu, z)
4+
# airyaiprime(z), airybiprime(nu, z)
55
#
6-
# A numerical routine to compute the airy functions and their derivatives.
7-
# These routines use their relations to other special functions using https://dlmf.nist.gov/9.6.
8-
# Specifically see (NIST 9.6.E1 - 9.6.E9) for computation from the defined bessel functions.
9-
# For negative arguments these definitions are prone to some cancellation leading to higher errors.
10-
# In the future, these could be replaced with more custom routines as they depend on a single variable.
6+
# A numerical routine to compute the airy functions and their derivatives in the entire complex plane.
7+
# These routines are based on the methods reported in [1] which use a combination of the power series
8+
# for small arguments and a large argument expansion for (x > ~10). The primary difference between [1]
9+
# and what is used here is that the regions where the power series and large argument expansions
10+
# do not provide good results they are filled by relation to other special functions (besselk and besseli)
11+
# using https://dlmf.nist.gov/9.6 (NIST 9.6.E1 - 9.6.E9). In this case the power series of besseli is used and then besselk
12+
# is calculated using the continued fraction approach. This method is described in more detail in src/besselk.jl.
13+
# However, care must be taken when computing besseli because when the imaginary component is much larger than the real part
14+
# cancellation will occur. This can be overcome by shifting the order of besseli to be much larger and then using the power series
15+
# and downward recurrence to get besseli(1/3, x). Another difficult region is when -10<x<-5 and the imaginary part is close to zero.
16+
# In this region we use rotation (see connection formulas http://dlmf.nist.gov/9.2.v) to shift to different region of complex plane
17+
# where algorithms show good convergence. If imag(z) == zero then we use the reflection identities to compute in terms of bessel functions.
18+
# In general, the cutoff regions compared to [1] are different to provide full double precision accuracy and to prioritize using the power series
19+
# and asymptotic expansion compared to other approaches.
1120
#
21+
# [1] Jentschura, Ulrich David, and E. Lötstedt. "Numerical calculation of Bessel, Hankel and Airy functions."
22+
# Computer Physics Communications 183.3 (2012): 506-519.
1223

1324
"""
1425
airyai(x)
@@ -318,6 +329,7 @@ function airyai_large_argument(x::Real)
318329
x < zero(x) && return real(airyai_large_argument(complex(x)))
319330
return airy_large_arg_a(abs(x))
320331
end
332+
321333
function airyai_large_argument(z::Complex{T}) where T
322334
x, y = real(z), imag(z)
323335
a = airy_large_arg_a(z)
@@ -332,6 +344,7 @@ function airyaiprime_large_argument(x::Real)
332344
x < zero(x) && return real(airyaiprime_large_argument(complex(x)))
333345
return airy_large_arg_c(abs(x))
334346
end
347+
335348
function airyaiprime_large_argument(z::Complex{T}) where T
336349
x, y = real(z), imag(z)
337350
c = airy_large_arg_c(z)
@@ -374,13 +387,15 @@ function airybi_large_argument(z::Complex{T}) where T
374387
return out
375388
end
376389
end
390+
377391
function airybiprime_large_argument(x::Real)
378392
if x < zero(x)
379393
return 2*real(airy_large_arg_d(complex(x)))
380394
else
381395
return 2*(airy_large_arg_d(x))
382396
end
383397
end
398+
384399
function airybiprime_large_argument(z::Complex{T}) where T
385400
x, y = real(z), imag(z)
386401
d = airy_large_arg_d(z)
@@ -406,6 +421,7 @@ function airybiprime_large_argument(z::Complex{T}) where T
406421
end
407422
end
408423

424+
# see equations 24 and relations using eq 25 and 26 in [1]
409425
function airy_large_arg_a(x::ComplexOrReal{T}) where T
410426
S = eltype(x)
411427
MaxIter = 3000

src/besseli.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ end
164164
165165
Modified Bessel function of the second kind of order nu, ``I_{nu}(x)``.
166166
"""
167-
besseli(nu::Real, x) = _besseli(nu, float(x))
167+
besseli(nu::Real, x::Real) = _besseli(nu, float(x))
168168

169169
_besseli(nu, x::Float16) = Float16(_besseli(nu, Float32(x)))
170170

0 commit comments

Comments
 (0)