[Numpy-discussion] NaN (Not a Number) occurs in calculation of complex number for Bessel functions

Pauli Virtanen pav at iki.fi
Fri Dec 21 08:59:02 EST 2012

Dag Sverre Seljebotn <d.s.seljebotn <at> astro.uio.no> writes:
> Do you have an implemention of the Bessel functions that work as you 
> wish in C or Fortran? If so, that could be wrapped and called from Python.

For spherical Bessel functions it's possible to also use the relation
to Bessel functions, which have a better implementation (AMOS) in Scipy:

import numpy as np
from scipy.special import jv

def sph_jn(n, z):
    return jv(n + 0.5, z) * np.sqrt(np.pi / (2 * z))

print sph_jn(536, 2513.2741228718346 + 201.0619298974676j)
# (2.5167666386507171e+81+3.3576357192536334e+81j)

This should solve the problem.

Pauli Virtanen

More information about the NumPy-Discussion mailing list