当每个内部积分都依赖于其他积分时,使用 R 进行三重积分

Triple integration using R when each inner integral depends on the others

我的问题类似于“double integral in R”,但在我的例子中,我想做一个三重积分,其中每个极限都取决于外积分。

我要计算

如何定义内部依赖关系?

我认为,根据您所附的 post 的建议,关键是添加 Vectorize 功能,我们想出了这样的事情:

# Example function 
phi <- function(t){t}

integrate(Vectorize(function(x) { 
  integrate(Vectorize(function(y) { 
    integrate(function(z) { 
      phi(x)*phi(y)*phi(z)   ## function you want to calculate
    }, -10, 6-x-y)$value     ## 2nd level interval
   }), -5, 3-x)$value        ## 1st level interval
}), -5,4)                    ## top interval

# 16480.2 with absolute error < 1.8e-10

上面的做法比较笼统,大家可以在其他功能上测试一下。 (答案与WolframAlpha提供的相同)