我正在使用 R 的积分函数,但被积函数给我带来了一些麻烦(它有一个奇点)。考虑到这一点,
distrib <- function(x){
dnorm(x, mean=700,sd=50)
}
phi <- function(nu, epsilon=20, maxi=Inf){
fun <- function(nup) {
lambdap <- 1e7/nup
distrib(lambdap) / (nup*(nup - nu))
}
# first part: from epsilon to nu - epsilon
I1 <- integrate(fun, epsilon, nu-epsilon, rel.tol = 1e-8,
subdivisions = 200L)
# second part: from nu + epsilon to Infty
I2 <- integrate(fun, nu+epsilon, maxi, rel.tol = 1e-8,
subdivisions = 200L)
I1$value + I2$value
}
x <- seq(1e7/500, 1e7/1000, length=200)
phi1 <- sapply(x, phi)
phi1 <- sapply(x, phi, epsilon=5)
#Error in integrate(fun, epsilon, nu - epsilon, rel.tol = 1e-08, subdivisions = #200L) :
# the integral is probably divergent
有没有比使用截止参数并手动调整它直到给出结果(不一定准确)更好的方法来计算 R 中的此类主值?