R-package deSolve:checkFunc中出错

R-package deSolve:checkFunc中出错,r,ode,differential-equations,R,Ode,Differential Equations,我是R方面的新手,我正试图用de deSolve软件包来解微分方程组 我总共有10000个时间步,每100个时间步我必须更改变量的值。 我尝试的代码给出了以下错误: Error in checkFunc(Func2, times, y, rho) : The number of derivatives returned by func() (2) must equal the length of the initial conditions vector (3) 我不太确定这个错误是从

我是R方面的新手,我正试图用de deSolve软件包来解微分方程组

我总共有10000个时间步,每100个时间步我必须更改变量的值。 我尝试的代码给出了以下错误:

Error in checkFunc(Func2, times, y, rho) : 
  The number of derivatives returned by func() (2) must equal the length of the initial conditions vector (3) 
我不太确定这个错误是从哪里来的。 以下是我目前的代码:

library(deSolve)

#--------variables and parameter--------------------------


parameters <- c(up = 0.0001, hm = 0.1, hp = 0,889, mm = 0.1 , nt = 100)
yini <- c(u = 1, m = 0.001, h = 0.001)
times <- seq(0,100, by=0.1)
out<- NULL

#--------functions---------------------------------------
DiffU <- function(t, yini, parameters){
  with(as.list(c(yini, parameters)),{

    #functions
    du <- -(up*u) + hm*h + (1/2*nt)*h
    dm <- hp*h - mm*m - (1/nt)*m

    # return functions
    list(c(du, dm))
  })
}

#---------------------------------------------
repeat{
  out<- rbind(out, ode(yini, times, DiffU, parameters))
  yini<-c(u = u+0.5*h, m = 0.001, h = m+0.5*h)
  x<- x+1
  if (x==100){
    break
  }
}
库(deSolve)
#--------变量和参数--------------------------

参数你的问题是,你有两个导数'du'和'dm',但yini有三个值('u','m'和'h')。这会导致错误


一种解决方案是(1)添加一个三阶导数或(2)从yini中删除“h”并将其添加到参数中。

您的问题是,您有两个导数“du”和“dm”,但yini有三个值(“u”、“m”和“h”)。这会导致错误

一种解决方案是(1)添加三阶导数或(2)从yini中删除“h”并将其添加到参数中