我正在尝试在 SciPy 中集成一个多变量函数在 2D 区域上。 什么相当于以下 Mathematica代码?
In[1]:= F[x_, y_] := Cos[x] + Cos[y]
In[2]:= Integrate[F[x, y], {x, -\[Pi], \[Pi]}, {y, -\[Pi], \[Pi]}]
Out[2]= 0
查看 SciPy documentation我只能找到对一维正交的支持。有没有办法在 SciPy 中进行多维积分?
最佳答案
我认为它会像这样工作:
def func(x,y):
return cos(x) + cos(y)
def func2(y, a, b):
return integrate.quad(func, a, b, args=(y,))[0]
print integrate.quad(func2, -pi/2, pi/2, args=(-pi/2, pi/2))[0]
编辑:我刚刚发现 dblquad这似乎完全符合您的要求:
print integrate.dblquad(func, -pi/2, pi/2, lambda x:-pi/2, lambda x:pi/2)[0]
关于python - SciPy 中的二维积分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2368337/