用I 调用quad 的正确方法是:
In [20]: quad(I, 0, 10, args=(1,2))
Out[20]: (0.6984886554222364, 1.1361829471531105e-11)
正如 Longwen 所指出的,I 的第一个参数是 z,quad 变化。 (y,a) 是 quad 传递给 I 的参数而不做任何更改。
但您收到错误是因为您尝试使用数组作为z 边界
In [21]: quad(I, 0, np.arange(3), args=(1,2))
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-21-fbbfa9c0cd3f> in <module>()
----> 1 quad(I, 0, np.arange(3), args=(1,2))
/usr/local/lib/python3.5/dist-packages/scipy/integrate/quadpack.py in quad(func, a, b, args, full_output, epsabs, epsrel, limit, points, weight, wvar, wopts, maxp1, limlst)
313 if (weight is None):
314 retval = _quad(func, a, b, args, full_output, epsabs, epsrel, limit,
--> 315 points)
316 else:
317 retval = _quad_weight(func, a, b, args, full_output, epsabs, epsrel,
/usr/local/lib/python3.5/dist-packages/scipy/integrate/quadpack.py in _quad(func, a, b, args, full_output, epsabs, epsrel, limit, points)
362 def _quad(func,a,b,args,full_output,epsabs,epsrel,limit,points):
363 infbounds = 0
--> 364 if (b != Inf and a != -Inf):
365 pass # standard integration
366 elif (b == Inf and a != -Inf):
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
ValueError when using if commands in function - 另一个最近尝试做同样事情的问题,使用数组作为集成边界。那篇文章提供了更多的错误回溯,因此更容易识别问题。
如果不是因为这个 ValueError,你的 3 术语 args 会产生不同的错误:
In [19]: quad(I, 0, 10, args=(10,1,2))
....
TypeError: I() takes 3 positional arguments but 4 were given