问题描述
from scipy import integrate
def g(y,x,a):
return x*y**2 + a
a= 13
integrate.dblquad(g,2,lambda x: 0,lambda x: x,args=(a))
TypeError Traceback(最近一次调用最后一次) 在 5 = 13 6 ----> 7 积分.dblquad(g,args=(a))
~\anaconda3\lib\site-packages\scipy\integrate\quadpack.py in dblquad(func,a,b,gfun,hfun,args,epsabs,epsrel) 第 599 章 600 --> 601 return nquad(func,[temp_ranges,[a,b]],args=args,602 opts={"epsabs": epsabs,"epsrel": epsrel}) 603
~\anaconda3\lib\site-packages\scipy\integrate\quadpack.py in nquad(func,range,opts,full_output) 824 其他: 825 opts = [opt if callable(opt) else _OptFunc(opt) for opt in opts] --> 826 return _NQuad(func,ranges,full_output).integrate(*args) 827 828
类型错误:* 后的integrate() 参数必须是可迭代的,而不是int
解决方法
您可以在 a
的内部(甚至外部)定义 g
:
from scipy import integrate
a = 13
def g(y,x):
return x * y ** 2 + a
integrate.dblquad(g,2,lambda x: 0,lambda x: x)
(我从不热衷于 args
论点。)