[英]R-package deSolve: Error in checkFunc
我對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
}
}
您有什么建議可以擺脫錯誤或改進代碼嗎? 非常感謝你!
你的問題是,你有兩個衍生物'du'和'dm',但yini有三個值('u','m'和'h')。 這會導致錯誤。
一種解決方案是(1)添加三階導數或(2)從yini中移除'h'並將其添加到參數中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.