2013-06-28 35 views
3

我一直在嘗試使用scipy.integrate.tplquadrature來解決方程式,但不完全理解符號,所以不知道如何解決以下方程式。任何幫助將非常感激。使用Python進行三重集成

IMG http://i42.tinypic.com/t69sfo.gif

感謝,

+0

[我試圖這裏](http://www.wolframalpha.com/input/?i=integral %28X ** 2 + * + EXP%28X ** 2%29 * EXP%28-1 * Y * Z%2F2%2FX%29%2C +%7BX%2C0%2Cpi%7D%2C%7BY%2C0 %2Cinf%7D%2C%7Bz%2C0%2Cinf%7D%29),它說這個積分不會收斂 –

回答

1

在你的榜樣它給了一個零積分的結果。我用一個高值1.e22inf

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]