Search code examples
rode

ODE waring messages in simple ODE problem


I am working on a complicated model to study the population dynamics. I am getting some warning messages and not sure why? I am not sure does it have any effect on the solution.

I am reproducing the same error in a sample Lotka-Volterra Model. Please consider this as an example, it may not correspond to actual dynamics of the model.

(1) Could you pleases explain, how to eliminate these warnings?

(2) Does it have any effect on the output?

Thanks for reading. Here is the code:


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)))

I am getting following warnings and need to why it is happening:

*Warning messages:

1: In checkevents(events, times, Ynames, dllname, TRUE) : Not all event times 'events$time' are in output 'times' so they are automatically included.

2: In checkevents(events, times, Ynames, dllname, TRUE) : Some time steps were very close to events - only the event times are used in these cases.*


Solution

  • One method is to round both time vectors to the required precision:

    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)
    

    Hope it helps!