Skip to content

Commit 1f48ef0

Browse files
committed
ad docs for hankel
1 parent 392c8c6 commit 1f48ef0

File tree

2 files changed

+65
-6
lines changed

2 files changed

+65
-6
lines changed

src/bessely.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,13 +228,13 @@ end
228228
#####
229229
##### Generic routine for `bessely`
230230
#####
231+
231232
"""
232233
bessely(nu, x::T) where T <: Float64
233234
234-
Bessel function of the first kind of order nu, ``Y_{nu}(x)``.
235+
Bessel function of the second kind of order nu, ``Y_{nu}(x)``.
235236
nu and x must be real where nu and x can be positive or negative.
236237
"""
237-
238238
function bessely(nu::Real, x::T) where T
239239
isinteger(nu) && return bessely(Int(nu), x)
240240
abs_nu = abs(nu)

src/hankel.jl

Lines changed: 63 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,32 @@
1+
# Hankel functions
2+
#
3+
# besseljy(nu, x)
4+
# besselh(nu, x), hankelh1(nu, x), hankelh2(nu, x)
5+
#
6+
# A numerical routine to compute both Bessel functions of the first J_{ν}(x) and second kind Y_{ν}(x)
7+
# for real orders and arguments of positive or negative value. Please see notes in src/besselj.jl and src/bessely.jl
8+
# for notes on implementation details as most of the routine is similar. A key difference is when the methods to compute bessely
9+
# don't also give besselj, we rely on a continued fraction approach to compute J_{ν}(x)/J_{ν-1}(x) to get J_{ν}(x) [1].
10+
# The continued fraction approach is in general quickly converging when nu and x are small in magnitude.
11+
# When x and nu are large and nu > x we fall back to computing J_{ν}(x) and Y_{ν}(x) separately as this was found to be more efficient.
12+
#
13+
# [1] Ratis, Yu L., and P. Fernández de Córdoba. "A code to calculate (high order) Bessel functions based on the continued fractions method."
14+
# Computer physics communications 76.3 (1993): 381-388.
15+
#
16+
17+
#####
18+
##### Generic routine for `besseljy`
19+
#####
20+
21+
"""
22+
besseljy(nu, x::T) where T <: Float64
23+
24+
Return both Bessel functions of the first ``J_{nu}(x)`` and
25+
second ``Y_{nu}(x)`` kind. This method will be faster than calling (besselj(nu, x), bessely(nu, x)) separately,
26+
unless nu is slightly larger than x.
27+
28+
Results may be slightly different than individual functions in some domains due to using different algorithms.
29+
"""
130
function besseljy(nu::Real, x::T) where T
231
isinteger(nu) && return besseljy(Int(nu), x)
332
abs_nu = abs(nu)
@@ -29,8 +58,8 @@ function besseljy(nu::Integer, x::T) where T
2958
abs_x = abs(x)
3059
sg = iseven(abs_nu) ? 1 : -1
3160

32-
Jnu = besselj_positive_args(abs_nu, abs_x)
33-
Ynu = bessely_positive_args(abs_nu, abs_x)
61+
Jnu, Ynu = besseljy_positive_args(abs_nu, abs_x)
62+
3463
if nu >= zero(T)
3564
if x >= zero(T)
3665
return Jnu, Ynu
@@ -42,13 +71,17 @@ function besseljy(nu::Integer, x::T) where T
4271
if x >= zero(T)
4372
return Jnu * sg, Ynu * sg
4473
else
45-
spi, cpi = sincospi(abs_nu)
4674
return throw(DomainError(x, "Complex result returned for real arguments. Complex arguments are currently not supported"))
75+
#spi, cpi = sincospi(abs_nu)
4776
#return (cpi*Jnu - spi*Ynu) * sg, Ynu + 2im * besselj_positive_args(abs_nu, abs_x)
4877
end
4978
end
5079
end
5180

81+
#####
82+
##### `besseljy` for positive arguments and orders
83+
#####
84+
5285
function besseljy_positive_args(nu::Real, x::T) where T
5386
nu == 0 && return (besselj0(x), bessely0(x))
5487
nu == 1 && return (besselj1(x), bessely1(x))
@@ -69,7 +102,7 @@ function besseljy_positive_args(nu::Real, x::T) where T
69102
if isinteger(nu) && nu < 150
70103
Y0 = bessely0(x)
71104
Y1 = bessely1(x)
72-
Ynm1, Yn = besselj_up_recurrence(x, bessely1(x), bessely0(x), 1, nu-1)
105+
Ynm1, Yn = besselj_up_recurrence(x, Y1, Y0, 1, nu-1)
73106

74107
ratio_Jv_Jvm1 = besselj_ratio_jnu_jnum1(nu, x)
75108
Jn = 2 /*x * (Ynm1 - Yn / ratio_Jv_Jvm1))
@@ -115,6 +148,13 @@ function besseljy_positive_args(nu::Real, x::T) where T
115148
end
116149
end
117150

151+
#####
152+
##### Continued fraction for J_{ν}(x)/J_{ν-1}(x)
153+
#####
154+
155+
# implements continued fraction to compute ratio of J_{ν}(x)/J_{ν-1}(x)
156+
# using equation 22 and 24 of [1]
157+
# in general faster converging for small magnitudes of x and nu and nu >> x
118158
function besselj_ratio_jnu_jnum1(n, x::T) where T
119159
MaxIter = 5000
120160
xinv = inv(x)
@@ -133,6 +173,16 @@ function besselj_ratio_jnu_jnum1(n, x::T) where T
133173
return h
134174
end
135175

176+
#####
177+
##### Hankel functions
178+
#####
179+
180+
"""
181+
besselh(nu, [k=1,] x)
182+
183+
Bessel function of the third kind of order `nu` (the Hankel function). `k` is either 1 or 2,
184+
selecting [`hankelh1`](@ref) or [`hankelh2`](@ref), respectively.
185+
"""
136186
function besselh(nu::Real, k::Integer, x)
137187
Jn, Yn = besseljy(nu, x)
138188
if k == 1
@@ -144,5 +194,14 @@ function besselh(nu::Real, k::Integer, x)
144194
end
145195
end
146196

197+
"""
198+
hankelh1(nu, x)
199+
Bessel function of the third kind of order `nu`, ``H^{(1)}_\\nu(x)``.
200+
"""
147201
hankelh1(nu, x) = besselh(nu, 1, x)
202+
203+
"""
204+
hankelh2(nu, x)
205+
Bessel function of the third kind of order `nu`, ``H^{(2)}_\\nu(x)``.
206+
"""
148207
hankelh2(nu, x) = besselh(nu, 2, x)

0 commit comments

Comments
 (0)