R中函数的积分
我想得到函数R中函数的积分,r,R,我想得到函数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), lowe
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
f=函数(x)dbeta(x、.5、.5)
>积分(函数(x)f(x),下=0,上=1)
绝对误差小于3e-06的1
f1=函数(x)dbeta(x、.5、.5)^2
>积分(函数(x)f1(x),下=0,上=1)
积分错误(函数(x)f1(x),下限=0,上限=1):
达到的最大细分数
第一个积分收敛到1,即使被积函数接近∞ 在极限。第二个积分不收敛。方便的是,我们可以从分析和数值两方面来说明这一点
I
=∫ x-1(1-x)-1 dx=log(x)-log(1-x)
用(ε,1-ε)代替(0,1)得到:
I
=2对数(1/ε)
所以I
→ ∞ asε→ 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")
eps您要集成的函数是1/x*1/(1-x)*常数
。你可以积分1/sqrt(x)*1/sqrt(1-x)*常数
,这就是为什么f
是可积的,但是f1
是不可积的,因为逆函数1/x
发散。@user1362215如果OP将限制更改为$0+\epsilon,1-\epsilon$,就会有答案,对吗?所以也许我们需要问为什么xe会问这个问题。如果你改变了极限,那么这将无法达到目的,除非ε是大的,否则积分还是相当大的。也许“未定义”才是罗斯想要的答案。