Error originates in the customized function ode. When IN!=0, You did not assign a value to dIN which is required in list(c(dP1,dP2,dIN)).

On 2010-9-21 2:30, Tianchan Niu wrote:
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]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to