Hi All:
      I found a mistake by myself. I should use "state" in the function
line.
      It is giving me the correct output now.
      Thanks,
Dabing

rm(list=ls())
library (deSolve)
library(ReacTran)


 advModel <- function(t, state, parms) {

     with (as.list(parms), {
         stomach <- state[1]
         intestine <- state[2:101]
          emptying <- 0.05+0.2*(tanh(t%%120-60)-tanh(t%%120-70))

         if(stomach <=0) gastric = 0 else gastric = emptying*stomach
         dstomach <- -gastric
         Tran <- advection.1D(C = intestine, flux.up = gastric, v = 1,
dx=1,adv.method="super")

       dintestine <- Tran$dC

         return (list(c(dstomach,dintestine)))
       })
}

times <- seq(1,1000,by =1)

state <- c(100,rep(0,100))

systime <- system.time(out <- ode.1D(func = advModel, y=state,times
=times,parms = 0,nspec=1))

#plot (out, xlab = "x", ylab = "Conc", main = "advection")
#image(out)

color = topo.colors
drug <- out[,2:101]
filled.contour(x = times, y = 1:100, drug, color = color, nlevels = 10,
               xlab = "time, min", ylab = "GIT distance, cm",main =
"drug",ylim=c(0,600), xlim=c(0,200))
write.csv(out,file="C:/BI-Chen/Research/R script/learning/plug.csv")


systime




On Mon, Jul 1, 2013 at 7:12 PM, Dabing Chen <dabing.c@gmail.com> wrote:

> Hello Daniel:
>
>             thanks for the help. Somehow, I still did not get the correct
> output. You can see that the values were not transmitted between different
> time points.
>
>   time 1 2 3 4  1 1 100 0 0 0  2 2 95 5 0 0  3 3 90 10 0 0  4 4 85 15 0 0
> 5 5 80 20 0 0  6 6 75 25 0 0  7 7 70 30 0 0  8 8 65 35 0 0  9 9 60 40 0 0
> 10 10 55 45 0 0  11 11 50 50 0 0  12 12 45 55 0 0  13 13 40 60 0 0  14 14
> 35 65 0 0  15 15 30 70 0 0  16 16 25 75 0 0  17 17 20 80 0 0  18 18 15 85
> 0 0  19 19 10 90 0 0  20 20 5 95 0 0  21 21 0 100 0 0  22 22 -5 105 0 0
> 23 23 -10 110 0 0  24 24 -15 115 0 0  25 25 -20 120 0 0  26 26 -25 125 0 0
> rm(list=ls())
> library (deSolve)
> library(ReacTran)
>
> state <- c(100,rep(0,100))
>
>  advModel <- function(t, C, parms) {
>
>      with (as.list(parms), {
>          stomach <- state[1]
>          intestine <- state[2:101]
>           emptying <- 0.05+0.2*(tanh(t%%120-60)-tanh(t%%120-70))
>
>          if(stomach <=0) gastric = 0 else gastric = emptying*stomach
>          dstomach <- -gastric
>          Tran <- advection.1D(C = intestine, flux.up = gastric, v = 0.3,
> dx=1,adv.method="super")
>
>        dintestine <- Tran$dC
>
>          return (list(c(dstomach,dintestine)))
>        })
> }
>
> times <- seq(1,1000,by =1)
>
>
>
> systime <- system.time(out <- ode.1D(func = advModel,y= state,times
> =times,parms = 0,nspec =1))
>
> #plot (out, xlab = "x", ylab = "Conc", main = "advection")
> #image(out)
> write.csv(out,file="C:/BI-Chen/Research/R script/learning/plug.csv")
>
>
> systime
>
>
> On Mon, Jul 1, 2013 at 6:29 PM, Daniel Reed <reeddc@umich.edu> wrote:
>
>> Hi Dabing:
>>
>> There's a typo in your return statement: it should be a lowercase C.
>>
>> Cheers,
>> Daniel
>>
>> _______________________________
>> Daniel C. Reed, PhD.
>> Postdoctoral Fellow,
>> Dept. of Earth & Environmental Sciences,
>> University of Michigan,
>> Ann Arbor, MI, USA.
>> email: reeddc@umich.edu
>> web: www.danielreed.org
>>
>> On Jul 1, 2013, at 4:30 PM, Dabing Chen <dabing.c@gmail.com> wrote:
>>
>> > Hello All:
>> >       I constantly ran into message like this:
>> >
>> >> systime <- system.time(out <- ode.1D(func = advModel, y=state,times
>> > =times,parms = 0,nspec=1))
>> > Error in levels(x) : argument "object" is missing, with no default
>> > Timing stopped at: 0 0 0
>> >
>> >      I am wondering what went wrong.
>> >      Thanks a lot in advance.
>> >
>> > Dabing Chen
>> >
>> >
>> > rm(list=ls())
>> > library (deSolve)
>> > library(ReacTran)
>> >
>> >
>> > advModel <- function(t, C, parms) {
>> >
>> >     with (as.list(parms), {
>> >         stomach <- state[1]
>> >         intestine <- state[2:101]
>> >          emptying <- 0.05+0.2*(tanh(t%%120-60)-tanh(t%%120-70))
>> >
>> >         if(stomach <=0) gastric = 0 else gastric = emptying*stomach
>> >         dstomach <- -gastric
>> >         Tran <- advection.1D(C = intestine, flux.up = gastric, v = 1,
>> > dx=1,adv.method="super")
>> >
>> >       dintestine <- Tran$dC
>> >
>> >         return (list(C(dstomach = dstomach,dintestine=dintestine)))
>> >       })
>> > }
>> >
>> > times <- seq(1,1000,by =1)
>> >
>> > state <- c(100,rep(0,100))
>> >
>> > systime <- system.time(out <- ode.1D(func = advModel, y=state,times
>> > =times,parms = 0,nspec=1))
>> >
>> > #plot (out, xlab = "x", ylab = "Conc", main = "advection")
>> > #image(out)
>> > write.csv(out,file="C:/BI-Chen/Research/R script/learning/plug.csv")
>> >
>> >
>> > systime
>> >
>> >       [[alternative HTML version deleted]]
>> >
>> > _______________________________________________
>> > R-sig-dynamic-models mailing list
>> > R-sig-dynamic-models@r-project.org
>> > https://stat.ethz.ch/mailman/listinfo/r-sig-dynamic-models
>>
>> _______________________________________________
>> R-sig-dynamic-models mailing list
>> R-sig-dynamic-models@r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-sig-dynamic-models
>>
>
>

	[[alternative HTML version deleted]]

