R ODE中的强制函数给出错误导数数

问题描述

我想使用R来求解boxmodell的两个ODE。我想使用强制函数来随着时间t改变输入参数cw。当我仅使用具有两个框的boxmodell时,此方法有效:

dCs<-function(t,y,parms){
  with(as.list(c(y,parms)),{
    dCs<-k3*cw(t)-k4*cs
    return(list(dCs,dCw=cw(t)))
  })
}

但是当我按如下所示更改功能以添加另一个框时,出现错误:

dCs<-function(t,{
    dCp<-(k1*cw(t)-(k2+k3)*cp+k4*cs)
    dCs<-(k3*cp-k4*cs)
    list(dCw=cw(t),dCs,dCp)
  })
}

Fehler in checkFunc(Func2,times,rho) : 
  The number of derivatives returned by func() (1) must equal the length of the initial conditions vector (2) 

我对以下相同错误的答案进行了仔细检查,但它对我不起作用。据我所知,所有参数均正确标记: Difficulty running an ODE model in R including a parameter that varies by time (forcing function)

#modelled time
times<-seq(0,56)

#input parameters
parms<-c(k1=0.1,k2=0.01,k3=0.1,k4=0.01)

#initial values
y0<-c(cs = 0,cp = 0)

#linear interpolation of concentration cw
flux<-data.frame(time = c(10,12,17,1,2,14,3,21,4,28,5,35,6,42,7,49,8,56),cw = c(48,61,62,32,65,71,95,67,48,66,81,64,91,87,67))
cw<-approxfun(x = flux[,1],y = flux[,2],method = "linear",rule = 2)

out1<-ode(times = times,func = dCs,y = y0,parms = parms)

我该如何纠正初始状况?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)