【发布时间】:2013-06-26 11:24:14
【问题描述】:
【问题讨论】:
-
I tried here 它说这个积分不收敛
标签: python scipy integration
【问题讨论】:
标签: python scipy integration
在您的示例中,它给出了零积分结果。我为inf使用了高价值1.e22:
from scipy import exp, pi
inf = 1.e22
from scipy.integrate import tplquad
func = lambda x,y,z: x**2 * exp(-x**2) * exp(-0.5*y*z/x)
x1,x2 = 0, pi
y1,y2 = lambda x: 0, lambda x: inf
z1,z2 = lambda x,y: 0, lambda x,y: inf
print tplquad( func, x1, x2, y1, y2, z1, z2 )
#(0.0, 0.0)
这是一个例子to calculate the volume of a sphere:
import scipy
from scipy.integrate import quad, dblquad, tplquad
from numpy import *
# limits for radius
r1 = 0.
r2 = 1.
# limits for theta
t1 = 0
t2 = 2*pi
# limits for phi
p1 = 0
p2 = pi
def diff_volume(p,t,r):
return r**2*sin(p)
volume = tplquad(diff_volume, r1, r2, lambda r: t1, lambda r: t2,
lambda r,t: p1, lambda r,t: p2)[0]
【讨论】: