Spherical Bessel functions of the first kind are defined as,
from mpmath import mpf, sqrt, pi, besselj
def sph_jn(n, z):
return besselj(n + mpf(1)/2, z)*sqrt(pi/(2*z))
For positive integer n, these functions have closed-form expressions in terms of trigonometric functions. For example, sph_jn(0, x) = sin(x)/x (see http://dlmf.nist.gov/10.49.E3).
For negative values of x, the mpmath implementation of these functions has the wrong sign. For example,
>>> sph_jn(0, -1)
mpc(real='-0.84147098480789639', imag='0.0')
The magnitude is correct, but the sign is not!
EDIT: The same problem plagues spherical Bessel functions of the second kind, defined analogously in terms of bessely.
Spherical Bessel functions of the first kind are defined as,
For positive integer
n, these functions have closed-form expressions in terms of trigonometric functions. For example,sph_jn(0, x) = sin(x)/x(see http://dlmf.nist.gov/10.49.E3).For negative values of
x, thempmathimplementation of these functions has the wrong sign. For example,The magnitude is correct, but the sign is not!
EDIT: The same problem plagues spherical Bessel functions of the second kind, defined analogously in terms of
bessely.