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

Pauli Virtanen pav at iki.fi
Fri Dec 21 10:45:40 EST 2012


Your code tries to to evaluate

    z = 1263309.3633394379 + 101064.74910119522j
    jv(536, z)
    # -> (inf+inf*j)

In reality, this number is not infinite, but

    jv(536, z) == -2.3955170861527422e+43888 + 9.6910119847300024e+43887

These numbers (~ 10^43888) are too large for the floating point
numbers that computers use (maximum ~ 10^308). This is why you get
infinities and NaNs in the result. The same is true for the spherical
Bessel functions.

You will not be able to do this calculation using any software
that uses only floating point numbers (Scipy, Matlab, ...).

You need to use analytical properties of your problem to
get rid of such large numbers. Alternatively, you can use arbitrary
precision numbers. Python has libraries for that:


By the way, the proper place for this discussion is the following
mailing list:


Pauli Virtanen

More information about the NumPy-Discussion mailing list