Dear All,

 

I am trying to use ode solver "rk4" to solve an ODE system, however, it
keeps saying: Error in eval(expr, envir, enclos) : object "dIN" not found.
The sample codes are enclosed as follows, please help me. Thank you very
much!

 

rm(list=ls())

 

library(odesolve)

 

# The ODE system

ode <- function(t,x,p){

 

  with(as.list(c(x,p)),{

     

     if(IN==0){

       dIN <- 1

       switch <- c

     }

     else {

       switch <- 0

     }

 

     dP1 <- a+b*P1-switch*P1

     dP2 <- a-b*P1+switch*P2

 

  list(c(dP1,dP2,dIN)) 

  })

}

 

# Parameters

a <- 0.1

b <- 0.2

c <- 0.5

 

parms <- c(a=a,b=b,c=c)

 

# Initial conditions

P10 <- 100.0

P20 <- 0.0

IN0 <- 0.0

 

xstart <- c(P1=P10,P2=P20,IN=IN0)

 

# Time points

times <- seq(0,10,by=1)

 

out <- as.data.frame(rk4(xstart,times,ode,parms))


	[[alternative HTML version deleted]]

