我有点困在一个函数上,我试图通过scipy,python进行数值积分。在
为了简单起见,我将函数定义为:integral f(x,y)= SUM[double integral(ax+by)dxdy]
a和b是常数,但对于每个积分的方程,它们是不同的。我已经将每个函数分别积分,然后将所有积分的结果求和,但是这需要花费大量的时间来计算,这对于我正在尝试实现的目标并不理想。在
是否有一种方法可以通过扩展和来同时集成整个函数:
^{pr2}$
然后将带有(a,b)元组列表的函数传递给scipy的dblquad函数?在
目前,我正在努力在文献中找到任何与此相关的东西。在
*编辑
我提供了一个示例代码,以更清楚地显示我想要实现的目标:import sys
import re
import math
from scipy.integrate import dblquad
def f((x,y),variables):
V=0
for v in variables:
a,b=v
V=V+ax+by
return (V)
def integral(x_max,y_max,variables):
return dblquad(f, 0, y_max, lambda x: 0, lambda x: x_max,args=variables)
def main():
variables=[(1,2),(3,4),(5,6)] #example variables. The length of this list can change with the code I am running.
x_max=y_max=1
integral(x_max,y_max,variables)
if __name__ == '__main__':
main()
因此,返回的错误是:Traceback (most recent call last):
File "integration_example.py", line 23, in
main()
File "integration_example.py", line 19, in main
integral(x_max,y_max,variables)
File "integration_example.py", line 14, in integral
return dblquad(f, 0, y_max, lambda x: 0, lambda x: x_max,args=variables)
File "/usr/lib/python2.7/dist-packages/scipy/integrate/quadpack.py", line 435, in dblquad
return quad(_infunc,a,b,(func,gfun,hfun,args),epsabs=epsabs,epsrel=epsrel)
File "/usr/lib/python2.7/dist-packages/scipy/integrate/quadpack.py", line 254, in quad
retval = _quad(func,a,b,args,full_output,epsabs,epsrel,limit,points)
File "/usr/lib/python2.7/dist-packages/scipy/integrate/quadpack.py", line 319, in _quad
return _quadpack._qagse(func,a,b,args,full_output,epsabs,epsrel,limit)
File "/usr/lib/python2.7/dist-packages/scipy/integrate/quadpack.py", line 382, in _infunc
myargs = (x,) + more_args
TypeError: can only concatenate tuple (not "list") to tuple
很明显,函数不喜欢我用我写这篇文章的方式传递一系列要放入积分中的值。有办法吗?
(抱歉,这可能是更好的措辞方式)。在