简体   繁体   中英

Solve equations with integral in R

I am trying to find roots of x (X 1 in code) and y (X[2] in code) for two equations as follows

Integral Equations

I use function multiroot in R package rootSolve:

m<-0.01 
r<- 0.5
c<- 0.01006885

eq.sol<-function(x,para)
{
  m<-para[1]
  r<-para[2]
  c<-para[3]
  inteq1<-function(b)
  {
   x[1]*exp(-x[1]*b)/(b+x[2])
  }
  inteq2<-function(b)
  {
   x[1]*exp(-x[1]*b)/(b+x[2])^2 
  }
  F1<-integrate(inteq1, 0, Inf)$value-m*c*(1-r)/(c+m*r)
  F2<-integrate(inteq2, 0, Inf)$value-m^2*c*(1-r)^2/(c+m*r)
  c(F1=F1, F2=F2)
}

find.para<-multiroot(eq.sol, start = c(0.05,1), para = c(m, r, c), positive = TRUE)

where m, r and c are constants. Two variables are expected to be positive. However, it returns following errors:

diagonal element is zero 
[1] 2
Warning messages:
1: In stode(y, times, func, parms = parms, ...) :
  error during factorisation of matrix (dgefa);         singular matrix
2: In stode(y, times, func, parms = parms, ...) : steady-state not reached

UPDATE

Thanks for Lyngbakr's solution. It seems a good initial guess is necessary in this case. However, if inserting this function in another function and randomly drawing c from some distribution, say U(0.005, 0.05), I cannot make it work for all samples of c. Is there any suggestion?

Try different initial guesses. For example,

find.para<-multiroot(eq.sol, start = c(1e-3, 1e-3), parms = c(phi, r, c), positive = TRUE)

gives,

$root
[1]  0.002437481 98.082693040

$f.root
           F1            F2 
-2.844821e-09 -5.135857e-12 

$iter
[1] 21

$estim.precis
[1] 1.424978e-09

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM