[Numpy-discussion] NaN (Not a Number) occurs in calculation of complex number for Bessel functions
Lev Givon
lev at columbia.edu
Fri Dec 21 09:11:34 EST 2012
Received from Pauli Virtanen on Fri, Dec 21, 2012 at 08:59:02AM EST:
> Dag Sverre Seljebotn <d.s.seljebotn <at> astro.uio.no> writes:
> [clip]
> > 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.
You can also try the spherical Bessel function in Sympy; it should be
able to handle this case as well [1].
L.G.
[1] http://docs.sympy.org/0.7.2/modules/functions/special.html#bessel-type-functions
More information about the NumPy-Discussion
mailing list