[R] deSolve output

Sébastien Bihorel pomchip at free.fr
Fri Aug 12 22:38:10 CEST 2011


Hi,

Try with the following ODE function. This should give you an extra
column with the derivative of G in your THAAC matrix.

degradation = function (t, state, parameters) {
 with(as.list(c(state, parameters)),
   {dG = (-a*(t+i)^b)*(G)
   list(c(dG),dG=dG)
   })
}

Any additional variables that you want to output from your ODE system
function need to be a separate level of the output list. For instance:

# Example taken from the deSolve vignette
parameters <- c(a = -8/3,b = -10, c = 28)

state <- c(X = 1,Y = 1, Z = 1)

Lorenz<-function(t, state, parameters) {
 with(as.list(c(state, parameters)),{
 # rate of change
 dX <- a*X + Y*Z
 dY <- b * (Y-Z)
 dZ <- -X*Y + c*Y - Z

 # return the rate of change
 list(c(dX, dY, dZ),dX=dX, dY=dY,Dummy=-X/Y)
 }) # end with(as.list ...
}

times <- seq(0, 100, by = 0.01)
library(deSolve)
out <- ode(y = state, times = times, func = Lorenz, parms = parameters)
head(out)

Sebastien



More information about the R-help mailing list