Scipy-使用球面贝塞尔函数时的误差



我正在尝试用带有Scipy模块的Python绘制绘图。根据http://docs.scipy.org/doc/scipy/reference/special.html我用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()

当我编译程序时,我得到的只是这个错误:

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'

有一种方法可以用正则贝塞尔函数以及贝塞尔函数和球面贝塞尔函数之间的关系来做它,但我不喜欢这个解决方案,因为我也需要球面贝塞尔函数的导数。

我有没有可能设置错误,可以将其修复为scipy.special.spherical_jn工作?

scipy.special.spherical_jn是在2016年7月25日发布的scipy 0.18.0版本中添加的。我猜你用的是老版本的scipy。要进行检查,请运行

import scipy
print(scipy.__version__)

最新更新