python - SciPy 中的二维积分

标签 python integration wolfram-mathematica scipy multidimensional-array

我正在尝试在 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]

Wolfram|Alpha agrees

编辑:我刚刚发现 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/

相关文章:

python - 使用 Django 生成要下载的文件

python - 右移运算符如何在 python 打印语句中工作?

php - 重建现有的 webapp : . NET 或 PHP

wolfram-mathematica - 在 Mathematica 中查找两个 ListPlot 的交点

wolfram-mathematica - 粘贴 Mathematica 代码,以便将其分解为单独的输入单元格

wolfram-mathematica - 从 Rule 和/切换有什么好处。在大型应用程序中使用 OptionsPattern[] 和 OptionValue?

python - 如何在Python中重写这个嵌套的for循环?

python - 尝试通过 Buildout 在 Ubuntu 上安装 PyCrypto,src/config.h : No such file or directory

integration - 不使用真实银行账户来测试格子集成的方法

android - Facebook android sdk 的 Session.requestNewPublishPermissions 给出了一个异常