简单 ODE 问题中的 ODE 警告消息

ODE waring messages in simple ODE problem

我正在研究一个复杂的模型来研究人口动态。我收到一些警告消息但不确定为什么?我不确定它是否对解决方案有任何影响。

我在示例 Lotka-Volterra 模型中重现了相同的错误。请以此为例,它可能与模型的实际动力学不符。

(1) 请您解释一下,如何消除这些警告?

(2)对输出有影响吗?

感谢阅读。这是代码:


library(deSolve)

predpreyLV<-function(t,y,p){
  N<-y[1]
  P<-y[2]

  with(as.list(p),{
    dNdt<- r*N*(1-(N/1000))-a*P*N
    dPdt<- -b*P+f*P*N
    return(list(c(dNdt,dPdt)))
  })
}

rootfun <- function (t,y,parms){
  if (t>=200 && y[2]>130)
    return (0)
  else
    return (1)
}

eventfun <- function (t,y,parms){
   y[2] = y[2]*0.99
   return (y)
}

r<-0.5; a<-0.01; f<-0.01; b<-0.2;

p<-c(r=r,a=a, b=b, f=f)
y0<-c(N=25, P=5)
times<-seq(0,500,0.01)

LV.out<-ode(y=y0,times,predpreyLV, p,method="lsodar",
            rootfunc = rootfun, events = list(func=eventfun, time = seq(198,200,0.01)))

我收到以下警告,需要了解发生原因:

*警告消息:

1: 在 checkevents(events, times, Ynames, dllname, TRUE) 中: 并非所有事件时间 'events$time' 都在输出 'times' 中,因此它们会自动包含在内。

2: 在 checkevents(events, times, Ynames, dllname, TRUE) 中: 一些时间步长非常接近事件 - 在这些情况下仅使用事件时间。*

一种方法是将两个时间向量四舍五入到所需的精度:

times  <- round(seq(0,500,0.01), 2)
evtime <- round(seq(198,200,0.01), 2)

evtime %in% times ## check if all events are in 'times'

LV.out<-ode(y=y0,times,predpreyLV, p,method="lsodar",
            rootfunc = rootfun, events = list(func=eventfun, time = evtime))
plot(LV.out)

希望对您有所帮助!