在R中找到没有封闭形式的积分方程的根

Finding root of an Integral equation with no closed form in R

我有一个带有自由常数 S 的函数 f(x)。一旦我对函数 f(x) 从 0 到无穷大进行积分,我想估计 S 的值使积分等于 1。

a <-0.3 #alpha
b <- 2.5 #beta
d <-0.7 #delta
g <-1.1 #gamma

#defining the function, note S is free (which causes an error, pasted below)
integrand <- function(x) {b*g/d*exp(-g*x)*(1-exp(-d* x))*exp(-a*b*S/d*(1-exp(-d*x)))}

#defining the integral equation I would like to solve for S
intfun<- function(S) {integrate(integrand,lower=0,upper=Inf)-1}

#trying to find the root of function
uniroot(intfun, lower = 0, upper = 1)

我也试过:

uniroot(integrate(integrand,lower=0,upper=Inf)-1, lower = 0, upper = 1)

给出的错误:

Error in f(x, ...) : object 'S' not found

我要找的S值在0.564029附近。

你应该改变你的功能:

a <-0.3 #alpha
b <- 2.5 #beta
d <-0.7 #delta
g <-1.1 #gamma

#defining the function, note S is free (which causes an error, pasted below)
integrand <- function(x, S) {b*g/d*exp(-g*x)*(1-exp(-d* x))*exp(-a*b*S/d*(1-exp(-d*x)))}

#defining the integral equation I would like to solve for S
intfun<- function(S) {
  integrate(function(x)integrand(x, S),lower=0,upper=Inf)[[1]]-1
}

 uniroot(intfun,c(-1,1))
$root
[1] 0.564041

$f.root
[1] -6.961327e-06

$iter
[1] 6

$init.it
[1] NA

$estim.prec
[1] 6.103516e-05