Skip to content

Commit 2820bea

Browse files
authored
Added spherical bessel functions (#196)
1 parent 10ad004 commit 2820bea

File tree

6 files changed

+59
-2
lines changed

6 files changed

+59
-2
lines changed

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "SpecialFunctions"
22
uuid = "276daf66-3868-5448-9aa4-cd146d93841b"
3-
version = "0.10.0"
3+
version = "0.11.0"
44

55
[deps]
66
OpenSpecFun_jll = "efe28fd5-8261-553b-a9e1-b2916fc3738e"
@@ -13,4 +13,4 @@ OpenSpecFun_jll = "0.5.3"
1313
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
1414

1515
[targets]
16-
test = ["Test"]
16+
test = ["Test"]

docs/src/functions_list.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,12 @@ SpecialFunctions.besselj0
3232
SpecialFunctions.besselj1
3333
SpecialFunctions.besselj
3434
SpecialFunctions.besseljx
35+
SpecialFunctions.sphericalbesselj
3536
SpecialFunctions.bessely0
3637
SpecialFunctions.bessely1
3738
SpecialFunctions.bessely
3839
SpecialFunctions.besselyx
40+
SpecialFunctions.sphericalbessely
3941
SpecialFunctions.hankelh1
4042
SpecialFunctions.hankelh1x
4143
SpecialFunctions.hankelh2

docs/src/functions_overview.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,12 @@ Here the *Special Functions* are listed according to the structure of [NIST Digi
6060
| [`besselj0(z)`](@ref SpecialFunctions.besselj0) | `besselj(0,z)` |
6161
| [`besselj1(z)`](@ref SpecialFunctions.besselj1) | `besselj(1,z)` |
6262
| [`besseljx(nu,z)`](@ref SpecialFunctions.besseljx) | scaled Bessel function of the first kind of order `nu` at `z` |
63+
| [`sphericalbesselj(nu,z)`](@ref SpecialFunctions.sphericalbesselj) | [Spherical Bessel function](https://en.wikipedia.org/wiki/Bessel_function#Spherical_Bessel_functions:_jn,_yn) of the first kind of order `nu` at `z` |
6364
| [`bessely(nu,z)`](@ref SpecialFunctions.bessely) | [Bessel function](https://en.wikipedia.org/wiki/Bessel_function) of the second kind of order `nu` at `z` |
6465
| [`bessely0(z)`](@ref SpecialFunctions.bessely0) | `bessely(0,z)` |
6566
| [`bessely1(z)`](@ref SpecialFunctions.bessely1) | `bessely(1,z)` |
6667
| [`besselyx(nu,z)`](@ref SpecialFunctions.besselyx) | scaled Bessel function of the second kind of order `nu` at `z` |
68+
| [`sphericalbessely(nu,z)`](@ref SpecialFunctions.sphericalbessely) | [Spherical Bessel function](https://en.wikipedia.org/wiki/Bessel_function#Spherical_Bessel_functions:_jn,_yn) of the second kind of order `nu` at `z` |
6769
| [`besselh(nu,k,z)`](@ref SpecialFunctions.besselh) | [Bessel function](https://en.wikipedia.org/wiki/Bessel_function) of the third kind (a.k.a. Hankel function) of order `nu` at `z`; `k` must be either `1` or `2` |
6870
| [`hankelh1(nu,z)`](@ref SpecialFunctions.hankelh1) | `besselh(nu, 1, z)` |
6971
| [`hankelh1x(nu,z)`](@ref SpecialFunctions.hankelh1x) | scaled `besselh(nu, 1, z)` |

src/SpecialFunctions.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@ export
1616
besseli,
1717
besselix,
1818
besselj,
19+
sphericalbesselj,
1920
besselj0,
2021
besselj1,
2122
besseljx,
2223
besselk,
2324
besselkx,
2425
bessely,
26+
sphericalbessely,
2527
bessely0,
2628
bessely1,
2729
besselyx,

src/bessel.jl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,30 @@ function bessely(n::Integer, x::BigFloat)
691691
return z
692692
end
693693

694+
"""
695+
sphericalbesselj(nu, x)
696+
697+
Spherical bessel function of the first kind at order `nu`, ``j_ν(x)``. This is the non-singular
698+
solution to the radial part of the Helmholz equation in spherical coordinates.
699+
"""
700+
function sphericalbesselj(nu, x::T) where {T}
701+
besselj_nuhalf_x = besselj(nu + one(nu)/2, x)
702+
if abs(x) sqrt(eps(real(zero(besselj_nuhalf_x))))
703+
nu == 0 ? one(besselj_nuhalf_x) : zero(besselj_nuhalf_x)
704+
else
705+
((float(T))(π)/2x) * besselj_nuhalf_x
706+
end
707+
end
708+
709+
"""
710+
sphericalbessely(nu, x)
711+
712+
Spherical bessel function of the second kind at order `nu`, ``y_ν(x)``. This is the singular
713+
solution to the radial part of the Helmholz equation in spherical coordinates. Sometimes
714+
known as a spherical Neumann function.
715+
"""
716+
sphericalbessely(nu, x::T) where {T} = ((float(T))(π)/2x) * bessely(nu + 1//2, x)
717+
694718
"""
695719
hankelh1(nu, x)
696720

test/bessel.jl

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,33 @@ end
189189
end
190190
end
191191

192+
@testset "sphericalbesselj" begin
193+
@test sphericalbesselj(1, 1) 0.3011686789397568
194+
@test sphericalbesselj(10, 5.5) 0.0009369210263385842
195+
@test sphericalbesselj(1.25, 5.5) -0.1123558799930763
196+
@test sphericalbesselj(1.25, -5.5+0im) 0.079447604649286 + 0.079447604649286im
197+
198+
@test sphericalbesselj(0, 0.01) 0.999983333416666
199+
@test sphericalbesselj(0, 0) == 1.0
200+
@test sphericalbesselj(1, 0) == 0.0
201+
@test sphericalbesselj(1, 0.01) 0.003333300000119047
202+
203+
@test_throws DomainError sphericalbesselj(1.25, -5.5)
204+
end
205+
206+
@testset "sphericalbessely" begin
207+
@test sphericalbessely(1, 1) -1.381773290676036
208+
@test sphericalbessely(10, 5.5) -10.89087037026398
209+
@test sphericalbessely(1.25, 5.5) 0.148322390312228
210+
@test sphericalbessely(1.25, -5.5+0im) -0.054015441306998 - 0.104879767991574im
211+
212+
@test sphericalbessely(0, 1e-5) -99999.9999950000000
213+
@test sphericalbessely(1, 1e-5) -1e10
214+
215+
@test_throws DomainError sphericalbessely(1.25, -5.5)
216+
@test_throws AmosException sphericalbessely(1, 0)
217+
end
218+
192219
@testset "besselhx" begin
193220
for elty in [Complex{Float16},Complex{Float32},Complex{Float64}]
194221
z = convert(elty, 1.0 + 1.9im)

0 commit comments

Comments
 (0)