我需要更长的时间来完全解释这一点,希望其他用户能够添加到这个 wiki。
从?integrate,abs.tol 参数定义为
要求绝对准确。
下面是以下注释:
当在无限区间积分时,明确地这样做,而不是仅仅使用一个大数作为端点。这增加了正确答案的机会——任何在无限区间上的积分是有限的函数在该区间的大部分时间里都必须接近于零。
因此,如果您想要绝对准确度而不是相对准确度(定义为 .Machine$double.eps^0.25 的结果),那么您可以这样做
> integrate(f, Inf, -Inf, abs.tol = 0L)
0.2 with absolute error < 8.4e-06
abs.tol 的默认参数是从rel.tol 传递的,即.Machine$double.eps^0.25
让我们看看“内部”发生了什么。
ifoo<-integrate(f,-Inf,Inf,abs.tol=1e-20)
5.275825e-21 with absolute error < 9.8e-21
str(ifoo)
List of 5
$ value : num 5.28e-21
$ abs.error : num 9.81e-21
$ subdivisions: int 3
$ message : chr "OK"
$ call : language integrate(f = f, lower = -Inf, upper = Inf, abs.tol = 1e-20)
- attr(*, "class")= chr "integrate"
ifoo<-integrate(f,-Inf,Inf,abs.tol=1e-40)
0.2 with absolute error < 8.4e-06
str(ifoo)
List of 5
$ value : num 0.2
$ abs.error : num 8.36e-06
$ subdivisions: int 21
$ message : chr "OK"
$ call : language integrate(f = f, lower = -Inf, upper = Inf, abs.tol = 1e-40)
- attr(*, "class")= chr "integrate"
请注意细分数量的突然增加。一般来说,更多的细分意味着更好的准确性,这毕竟是微积分的重点:将细分宽度减少到零,以获得准确的答案。我的猜测是,对于大(ish)abs.tol,计算值只需进行一些细分即可与一些“估计容差误差”一致,但是当所需的容差变得足够小时,会“添加更多的细分”。 "
编辑:感谢 Hong Ooi,他实际查看了有问题的被积函数。 :-) 。因为这个函数在x==25 有一个尖点,即导数的不连续性,所以优化算法可能会在收敛方面被“误导”。奇怪的是,通过利用这个被积函数很快接近零的事实,当 不 积分到 +/-Inf 时,结果会更好。事实上:
Rgames> integrate(f,20,30)
0.2 with absolute error < 1.9e-06
Rgames> integrate(f,22,27)
0.2 with absolute error < 8.3e-07
Rgames> integrate(f,0,50)
0.2 with absolute error < 7.8e-05