Skip to content

Commit 1a77816

Browse files
committed
add hankel functions
1 parent 57275dd commit 1a77816

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/hankel.jl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,25 @@ function besselh(nu::Real, k::Integer, x)
194194
end
195195
end
196196

197+
function besselh(nu::AbstractRange, k::Integer, x::T) where T
198+
(nu[1] >= 0 && step(nu) == 1) || throw(ArgumentError("nu must be >= 0 with step(nu)=1"))
199+
if nu[end] < x
200+
out = Vector{Complex{T}}(undef, length(nu))
201+
out[1], out[2] = besselh(nu[1], k, x), besselh(nu[2], k, x)
202+
return besselj_up_recurrence!(out, x, nu)
203+
else
204+
Jn = besselj(nu, x)
205+
Yn = bessely(nu, x)
206+
if k == 1
207+
return complex.(Jn, Yn)
208+
elseif k == 2
209+
return complex.(Jn, -Yn)
210+
else
211+
throw(ArgumentError("k must be 1 or 2"))
212+
end
213+
end
214+
end
215+
197216
"""
198217
hankelh1(nu, x)
199218
Bessel function of the third kind of order `nu`, ``H^{(1)}_\\nu(x)``.

test/hankel_test.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,8 @@ v, x = 14.3, 29.4
2626
@test isapprox(hankelh2(v, x), SpecialFunctions.hankelh2(v, x), rtol=2e-13)
2727
@test isapprox(besselh(v, 1, x), SpecialFunctions.besselh(v, 1, x), rtol=2e-13)
2828
@test isapprox(besselh(v, 2, x), SpecialFunctions.besselh(v, 2, x), rtol=2e-13)
29+
30+
@test isapprox(hankelh1(1:50, 10.0), SpecialFunctions.hankelh1.(1:50, 10.0), rtol=2e-13)
31+
@test isapprox(hankelh1(0.5:1:25.5, 15.0), SpecialFunctions.hankelh1.(0.5:1:25.5, 15.0), rtol=2e-13)
32+
@test isapprox(hankelh1(1:50, 100.0), SpecialFunctions.hankelh1.(1:50, 100.0), rtol=2e-13)
33+
@test isapprox(hankelh2(1:50, 10.0), SpecialFunctions.hankelh2.(1:50, 10.0), rtol=2e-13)

0 commit comments

Comments
 (0)