【发布时间】:2019-12-31 12:33:06
【问题描述】:
我正在尝试使用 scipy 的 tplquad 做一些简单的物理三重积分。例如,我尝试在单位立方体上积分单位球(func d)的恒定质量密度。这行不通。但是,如果我将单位立方体的恒定质量密度(func f)积分到单位立方体上,我会很快得到结果。
我认为问题在于将常量积分限制提供为常量而不是函数。我使用 lambda 解决了这个问题,但我仍然无法获得积分。
from scipy import integrate
''' returns the mass density at a point (x,y,z)'''
def d(z, x, y):
return int(x**2 + y**2 + z**2 <= 1) # unit ball with constant density = 1 , here all orthogonal axes are principal
def f(x,y,z):
return 1
integrate.tplquad(d, -1, 1, lambda x: -1, lambda x: 1,lambda x, y: -1, lambda x, y: 1) # doesn't work / too slow
integrate.tplquad(f, -1, 1, lambda x: -1, lambda x: 1,lambda x, y: -1, lambda x, y: 1) # works fine
我希望 d 在给定范围内的积分为 4/3*pi。
【问题讨论】:
标签: python scipy numerical-integration