[R] Ask for help with Error: Object not found
Duncan Murdoch
murdoch.duncan at gmail.com
Mon Sep 20 22:27:24 CEST 2010
On 20/09/2010 3:07 PM, 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
>
> }
In the else clause, you didn't define dIN, so it will not be found below.
Duncan Murdoch
>
>
> 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 at 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.
More information about the R-help
mailing list