【发布时间】:2014-02-14 17:10:41
【问题描述】:
我最近一直在学习如何在 python 中执行双积分。这就是我正在使用的:
myint = dblquad(lambda xa,xb: np.exp(-(xa-xb)**2),-np.inf,x1,lambda x: -np.inf, lambda x: x2)
出于测试目的,我选择了 x1 和 x2 来表示 5 和 10。这似乎可行。
但实际上,我的 x1 = [1,2,3,4,5] 和 x2 = [5,6,7,8,9] 我希望对 x1 和x2 即矩阵。我猜我可以用 2 个 for 循环来做到这一点,但我认为可能有更好的方法。
所以我的问题是 - 我如何在限制矩阵上执行双重积分。
谢谢。
编辑:
我收到以下警告:
UserWarning: The maximum number of subdivisions (50) has been achieved.
If increasing the limit yields no improvement it is advised to analyze
the integrand in order to determine the difficulties. If the position of a
local difficulty can be determined (singularity, discontinuity) one will
probably gain from splitting up the interval and calling the integrator
on the subranges. Perhaps a special-purpose integrator should be used.
这是否意味着它不会收敛?我不太明白这个消息。
当我绘图时:
y = exp(-(x-5)^2)
例如,它看起来就像一条高斯曲线,所以在上面积分没有问题,对吧?是双积分的问题吗?
谢谢。
编辑:
啊,我明白了。感谢 Raman Shah,我现在明白问题所在了。
【问题讨论】:
-
你确定,这个积分收敛了吗?
-
Stefan 的评论很重要,使用
x1,x2 = (5,10)会发出积分器无法收敛的警告。考虑增加细分的数量。 -
如果你只集成一个高斯,你应该研究特殊的函数(例如误差函数)来实现它的功能。这可能会更快,更准确。编辑:我认为你有一些分歧,因为 xa = xb 的被积函数是 1 一直回到 -infinity。