我想获得函数f1
的积分,如何在R中解决以下问题?
f = function(x)dbeta(x, .5, .5)
> integrate(function(x) f(x), lower = 0, upper = 1)
1 with absolute error < 3e-06
f1 = function(x)dbeta(x, .5, .5)^2
> integrate(function(x) f1(x), lower = 0, upper = 1)
Error in integrate(function(x) f1(x), lower = 0, upper = 1) :
maximum number of subdivisions reached
答案 0 :(得分:1)
第一个积分收敛于1,即使被积函数在极限处逼近∞。第二个积分不会收敛。方便的是,我们可以通过分析和数字来证明这一点。
I
=∫x -1 (1-x) -1 dx = log(x) - log(1-x)
用(ε,1-ε)代替(0,1)得到:
I
= 2 log(1 /ε)
所以I
→∞为ε→0
我们可以在R中看到这个数字:
eps <- c(10^-(5:13))
g <- function(eps) integrate(function(x) dbeta(x,.5,.5),
lower = 0+eps, upper = 1-eps)$value
g.sq <- function(eps) integrate(function(x) dbeta(x,.5,.5)^2,
lower = 0+eps, upper = 1-eps)$value
(g.lim <- sapply(eps, g))
(g.sq.lim<- sapply(eps, g.sq))
plot(eps, g.sq.lim, col="red", type="b", ylim=c(0,7),ylab="", log="x")
par(new=T)
plot(eps, g.lim, col="blue", type="b", ylim=c(0,7),ylab="", log="x")