2012-11-02 6 views
4

scipy.integrate를 사용하는 데 어려움을 겪고 있습니다. tplquad를 사용했는데, integrate을 사용하여 (잘린) 구의 볼륨을 얻으려면 어떻게해야합니까? 감사합니다scipy.integrate를 사용하여 잘린 구의 음량을 얻는 방법?

import scipy 
from scipy.integrate import quad, dblquad, tplquad 
from math import* 
from numpy import * 

R = 0.025235 #radius 
theta0 = acos(0.023895) #the angle from the edge of truncated plane to the center of 
sphere 

def f_1(phi,theta,r): 
    return r**2*sin(theta)*phi**0 
Volume = tplquad(f_1, 0.0,R, lambda y: theta0, lambda y: pi, lambda y,z: 0.0,lambda 
y,z: 2*pi) 

print Volume 
+2

odeint은 미분 방정식,하지 적분을 해결하기 위해 사용된다. 나는 정말로 보지 않는다. 당신이 왜 그것을 여기에서 사용하고 싶어하는지. 또한 마지막 두 치수를 분석적으로 통합하여 통합을 단순화 할 수 있으므로 단일 통합으로 남습니다. –

답변

2

구형 좌표계를 사용하는 것이 편리합니다. 당신은 한계 설정 절단, 그리고 enter image description here

수 있습니다 : r1r2t1t2p1p2 : 사용하기 편리 비행기로 잘라야

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] 

radius (r)뿐만 theta (t)phi (p)을 정의 taken from Arkansas TU 가정 직교 좌표계 (x,y,z), 여기서 x**2+y**2+z**2=R**2 (see mathworld). 여기에서 나는 구체의 절반을 입증하기 위해 절단하고 있습니다 :

from `x1=-R` to `x2=R`<br> 
from `y1=0` to `y2=(R**2-x**2)**0.5`<br> 
from `z1=-(R**2-x**2-y**2)**0.5` to `z2=(R**2-x**2-y**2)**0.5`<br> 
(an useful example using lambdas): 

R= 2. 
# limits for x 
x1 = -R 
x2 = R 

def diff_volume(z,y,x): 
    return 1. 

volume = tplquad(diff_volume, x1, x2, 
       lambda x: 0., lambda x: (R**2-x**2)**0.5, 
       lambda x,y: -(R**2-x**2-y**2)**0.5, 
       lambda x,y: (R**2-x**2-y**2)**0.5)[0]