类似地,我想把一个函数数值积分
import scipy.integrate as integrate
inside = lambda x: integrate.quad(lambda x,y: 1, 0, x, args=(x))[0]
outside = integrate.quad(inside, 0, 1)[0]
print(outside)
0.5
但是使用scipy.integrate.fixed_quad
函数(它以积分顺序n
作为参数)。但是,当我写的时候
Traceback (most recent call last): File "", line 1, in File "", line 1, in File "/Users/username/anaconda/lib/python3.5/site-packages/scipy/integrate/ quadrature.py", line 82, in fixed_quad return (b-a)/2.0 * np.sum(w*func(y, *args), axis=0), None
TypeError: () argument after * must be an iterable, not int
我不知道我做错了什么,因为我在跟踪scipy.integrate.fixed_quad上的文档。在
问题是你对
args
,args=(x)
的定义。它应该作为元组传递,因此需要添加一个额外的逗号使其成为元组:那么
^{pr2}$收益率
线
工作方式与
quad
一样,检查args
是否为元组;如果不是,则转换它(直接从源代码获取):在
fixed_quad
中,情况并非如此,这就是为什么在一种情况下(而不是在两种情况下)都收到了错误。在相关问题 更多 >
编程相关推荐