我一直在尝试在 Python 中绘制以下函数:
但我不断收到以下错误:
File "//anaconda/lib/python3.5/site-packages/scipy/integrate/quadpack.py", line 383, in _quad
return _quadpack._qagie(func,bound,infbounds,args,full_output,epsabs,epsrel,limit)
error: Supplied function does not return a valid float.
这是我正在使用的代码:
import numpy as np
from scipy import integrate
import matplotlib.pyplot as plt
a = 0.1
pi = np.pi
u = np.linspace(-100,100,200)
def integrand(a,u,y):
top = np.exp(-y**2)
bottom = a**2 + (u - y)**2
return top/bottom
def func(u):
res = np.zeros_like(u)
for i,val in enumerate(u):
y,err = integrate.quad(integrand, -np.inf, np.inf, args=(a,u))
res[i] = y
return (a/pi)*res
plt.plot(u,func(u))
u 是代表频率范围的一系列值。我一直在努力让集成在 python 中工作。有没有人可以推荐我去让它工作的好方向?
谢谢
