pythonscipybessel-functions

Scipy - Error while using spherical Bessel functions


I'm trying to draw plots in Python with Scipy module. According to http://docs.scipy.org/doc/scipy/reference/special.html I wrote code with scipy.special.spherical_jn(n,x,0):

import matplotlib.pyplot as plt
import numpy as np
import scipy.special as sp

from matplotlib import rcParams
rcParams.update({'figure.autolayout': True})

def odrazTE(a,o,d):
    temp1 = sp.spherical_jn[1,a,0]
    temp2 = 1
    return abs(temp1/temp2)**2

t = np.arange(0.001, 2, 0.001)
plt.plot(t,odrazTE(t,t,1),label='TE1')
plt.show()

While I'm compiling the program, all I get is this error:

Traceback (most recent call last):
  File "standing-sphere.py", line 33, in <module>
    plt.plot(t,odrazTE(t,t,1),label='TE1')
  File "standing-sphere.py", line 15, in odrazTE
    temp1 = sp.spherical_jn[1,a,0]
AttributeError: 'module' object has no attribute 'spherical_jn'

There is way how to do it with regular Bessel function and relationship between Bessel and spherical Bessel function, but I don't like this solution because of derivative of sph.bess. function that I need too.

Is there any chance I have set something wrongly and it can be fixed to scipy.special.spherical_jn work?


Solution

  • scipy.special.spherical_jn was added in scipy version 0.18.0, which was released on July 25, 2016. My guess is you are using an older version of scipy. To check, run

    import scipy
    print(scipy.__version__)