如何使用 scipy 在 python 中执行这种积分:
$$\int_{0}^{1} f(x) \, dx \int_{0}^{x} g(y) \, dy \int_{0}^{x} h(z) \,dz $$
尝试使用 tplquad,但我认为两个内部积分是 x 的独立函数这一事实不是我能够编写的。
SciPy 的
tplquad
期望函数至少包含三个顺序为 (z, y, x) 的参数。没有比这更容易的了:
def fgh(z, y, x):
return f(x)*g(y)*h(z)
要指定边界
lambda
函数非常有用。求积的示例代码如下:
tplquad(fgh, a=0, b=1, \
gfun=lambda x:0, hfun=lambda x:x, \
qfun=lambda x,y:0, rfun=lambda x,y:x)