2

我们可以将deSolveR 中的包用于常微分方程 (ODE),但是,我找不到解决两个嵌套 ODE 方程的方法,假设`

b'(t) = beta - k*b(t); 
a'(t) = alpha -b(t)*gamma;

其中'表示差异化。a那么我们该如何解决b呢?作为a'的函数b,我们必须同时求解ab

我收到一个错误:

lsoda(y, times, func, parms, ...) 中的错误:无法嵌套使用的求解器组合。

当我尝试b在 ode 解决方案中添加解决方案时a

4

1 回答 1

3

I may be confused, but you seem to be describing coupled equations, which lsoda can handle perfectly well, as follows (I implemented your ODEs but made up some parameters since I didn't know what you had in mind.)

gfun <- function(t,y,parms,...) {
  ## 'with' trick lets us write gradient in terms of variable/parameter names
  with(as.list(c(y,parms)),
       list(c(b=beta-k*b,a=alpha-b*gamma),NULL))
}

library(deSolve)
L1 <- lsoda(y=c(b=1,a=1),
            times=seq(0,10,by=0.1),
            func=gfun,
            parms=c(alpha=0.1,beta=0.2,gamma=0.05,k=0.01))

matplot(L1[,1],L1[,-1],type="l",lty=1,bty="l",las=1)

PS: this seems to be a set of coupled linear ODEs, so you should actually be able to get a full closed-form solution rather than solving them numerically. (I'm too lazy to do that right now; b(t) can be solved immediately (an "affine" equation), a(t) can be solved by integration.)

于 2011-04-12T14:28:34.533 回答