在 R 中迭代处理数值积分误差的最佳方法?

问题描述 投票:0回答:1

考虑 R 中的以下数值积分:

integrand = function(u){log(u) * u ^ (2 * (H - 1)) * (exp(a * u) - exp(- a * u))}
integrate(f = integrand, lower = 0, upper = 100,
              rel.tol = .Machine$double.eps ^ 0.01, subdivisions = 1e6)

由于

lower = 0
,这是有分歧的。我想逐步增加下限
from 0 to 
1e-13` 并一次逐步增加一位小数,直到收敛。您建议使用哪个代码?我不熟悉错误处理。

r error-handling numerical-methods numerical-integration
1个回答
0
投票

您需要提供

H
a
的值,如评论部分中已提到的。

尽管如此,对于我设置的任意默认值,我建议您使用

calculus
包。这是如何使用它的示例片段。我还降低了上限,以免运行时间太长。

这是参考:https://cran.r-project.org/web/packages/calculus/index.html

library(calculus)

integrand <- function(u, H = 2, a = 3) {
  log(u) * u^(2 * (H - 1)) * (exp(a * u) - exp(-a * u))
}

integral(integrand, bounds = list(u = c(0, 1)))
© www.soinside.com 2019 - 2024. All rights reserved.