Skip to content

Commit 41ae451

Browse files
committed
update exports and export sphericalbessel
1 parent edb8753 commit 41ae451

File tree

3 files changed

+57
-2
lines changed

3 files changed

+57
-2
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Numerical routines for computing Bessel and Hankel functions for real arguments.
66

77
The goal of the library is to provide high quality numerical implementations of Bessel functions with high accuracy without comprimising on computational time. In general, we try to match (and often exceed) the accuracy of other open source routines such as those provided by [SpecialFunctions.jl](https://github.com/JuliaMath/SpecialFunctions.jl). There are instances where we don't quite match that desired accuracy (within a digit or two) but in general will provide implementations that are 5-10x faster (see [benchmarks](https://github.com/heltonmc/Bessels.jl/edit/update_readme/README.md#benchmarks)).
88

9-
The library currently supports Bessel functions, modified Bessel functions and Hankel functions of the first and second kind for positive real arguments and integer and noninteger orders. Negative arguments are also supported only if the return value is real. We plan to support complex arguments in the future. An unexported gamma function is also provided.
9+
The library currently supports Bessel functions, modified Bessel functions, Hankel functions and spherical Bessel functions of the first and second kind for positive real arguments and integer and noninteger orders. Negative arguments are also supported only if the return value is real. We plan to support complex arguments in the future. An unexported gamma function is also provided.
1010

1111
# Quick start
1212

@@ -209,6 +209,8 @@ Benchmarks were run using Julia Version 1.7.2 on an Apple M1 using Rosetta.
209209
- `besselh(nu, k, x)`
210210
- `hankelh1(nu, x)`
211211
- `hankelh2(nu, x)`
212+
- `sphericalbesselj(nu, x)`
213+
- `sphericalbessely(nu, x)`
212214
- `Bessels.gamma(x)`
213215

214216
# Current Development Plans

src/Bessels.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ export bessely0
88
export bessely1
99
export bessely
1010

11+
export sphericalbesselj
12+
export sphericalbessely
13+
1114
export besseli
1215
export besselix
1316
export besseli0

src/sphericalbessel.jl

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,30 @@
1+
# Spherical Bessel functions
2+
#
3+
# sphericalbesselj(nu, x), sphericalbessely(nu, x)
4+
#
5+
# A numerical routine to compute the spherical bessel functions of the first and second kind.
6+
# For small arguments, the power series series is used for sphericalbesselj. If nu is not a big integer
7+
# then forward recurrence is used if x >= nu. If x < nu, forward recurrence for sphericalbessely is used
8+
# and then a continued fraction and wronskian is used to compute sphericalbesselj [1]. For all other values,
9+
# we directly call besselj and bessely routines.
10+
#
11+
# [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."
12+
# Computer physics communications 76.3 (1993): 381-388.
13+
#
14+
15+
#####
16+
##### Generic routine for `sphericalbesselj`
17+
#####
18+
19+
"""
20+
sphericalbesselj(nu, x)
21+
22+
Spherical bessel function of the first kind of order `nu`, ``j_ν(x)``. This is the non-singular
23+
solution to the radial part of the Helmholz equation in spherical coordinates.
24+
"""
125
function sphericalbesselj(nu::Real, x::T) where T
226
isnan(nu) || isnan(x) && return NaN
327
x < zero(T) && return throw(DomainError(x, "Complex result returned for real arguments. Complex arguments are currently not supported"))
4-
abs_nu = abs(nu)
528

629
if nu < zero(T)
730
return SQPIO2(T) * besselj(nu + 1/2, x) / sqrt(x)
@@ -10,6 +33,10 @@ function sphericalbesselj(nu::Real, x::T) where T
1033
end
1134
end
1235

36+
#####
37+
##### Positive arguments for `sphericalbesselj`
38+
#####
39+
1340
function sphericalbesselj_positive_args(nu::Real, x::T) where T
1441
if x^2 / (4*nu + 110) < eps(T)
1542
# small arguments power series expansion
@@ -28,6 +55,10 @@ function sphericalbesselj_positive_args(nu::Real, x::T) where T
2855
end
2956
end
3057

58+
#####
59+
##### Integer recurrence and/or wronskian with continued fraction
60+
#####
61+
3162
# very accurate approach however need to consider some performance issues
3263
# if recurrence is stable (x>=nu) can generate very fast up to orders around 250
3364
# for larger orders it is more efficient to use other expansions
@@ -56,6 +87,17 @@ function sphericalbesselj_recurrence(nu::Integer, x::T) where T
5687
end
5788
end
5889

90+
#####
91+
##### Generic routine for `sphericalbessely`
92+
#####
93+
94+
"""
95+
sphericalbessely(nu, x)
96+
97+
Spherical bessel function of the second kind at order `nu`, ``y_ν(x)``. This is the singular
98+
solution to the radial part of the Helmholz equation in spherical coordinates. Sometimes
99+
known as a spherical Neumann function.
100+
"""
59101
function sphericalbessely(nu::Real, x::T) where T
60102
isnan(nu) || isnan(x) && return NaN
61103
x < zero(T) && return throw(DomainError(x, "Complex result returned for real arguments. Complex arguments are currently not supported"))
@@ -68,6 +110,10 @@ function sphericalbessely(nu::Real, x::T) where T
68110
end
69111
end
70112

113+
#####
114+
##### Positive arguments for `sphericalbesselj`
115+
#####
116+
71117
function sphericalbessely_positive_args(nu::Real, x::T) where T
72118
if besseljy_debye_cutoff(nu, x)
73119
# for very large orders use expansion nu >> x to avoid overflow in recurrence
@@ -79,6 +125,10 @@ function sphericalbessely_positive_args(nu::Real, x::T) where T
79125
end
80126
end
81127

128+
#####
129+
##### Integer recurrence
130+
#####
131+
82132
function sphericalbessely_forward_recurrence(nu::Integer, x::T) where T
83133
xinv = inv(x)
84134
s, c = sincos(x)

0 commit comments

Comments
 (0)