如何使用 python 中的 tplquad、dblquad 进行积分?

How to do this integral using tplquad, dblquad in python?

如何使用 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)