| 1 |
\name{deSolve-internal} |
| 2 |
\alias{timestep} |
| 3 |
\title{Internal deSolve Functions} |
| 4 |
|
| 5 |
\description{ |
| 6 |
Internal deSolve functions, these are not to be called by the user. |
| 7 |
} |
| 8 |
|
| 9 |
\usage{ |
| 10 |
timestep(prev = TRUE) |
| 11 |
} |
| 12 |
|
| 13 |
\arguments{ |
| 14 |
\item{prev }{if \code{TRUE} will return the timestep previously used; |
| 15 |
when \code{FALSE} will return the time step to be currently tried by |
| 16 |
the integrator. |
| 17 |
} |
| 18 |
} |
| 19 |
|
| 20 |
\details{ |
| 21 |
Function \code{timestep} is intended to return the current or next |
| 22 |
timestep of the integration. It works only under specific |
| 23 |
circumstances and should not be used by the end user. |
| 24 |
|
| 25 |
Instead of this, please see the example below for a pure |
| 26 |
\R solution. |
| 27 |
} |
| 28 |
|
| 29 |
\seealso{ |
| 30 |
\code{\link{diagnostics}} for information about the time steps used,\cr |
| 31 |
\code{\link{lagvalue}} and \code{\link{lagderiv}} that can be used for DDEs. |
| 32 |
} |
| 33 |
|
| 34 |
\examples{ |
| 35 |
################################################### |
| 36 |
### This example shows how to retrieve information |
| 37 |
### about the used time steps. |
| 38 |
################################################### |
| 39 |
|
| 40 |
## a function closure ('lexical scoping') |
| 41 |
modelClosure <- function(t0) { |
| 42 |
t.old <- t.act <- t0 |
| 43 |
function(t, y, parms) { |
| 44 |
t.old <<- t.act |
| 45 |
t.act <<- t |
| 46 |
cat(t, "\t", t - t.old, "\n") |
| 47 |
with (as.list(c(y, parms)), { |
| 48 |
dP <- a * P - b * P * K |
| 49 |
dK <- b * P * K - c * K |
| 50 |
list(c(dP, dK)) |
| 51 |
}) |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
model <- modelClosure(0) # initialization |
| 56 |
|
| 57 |
parms <- c(a = 0.1, b = 0.1, c = 0.1) |
| 58 |
|
| 59 |
y <- c(P = 1, K = 2) |
| 60 |
|
| 61 |
out <- ode(y = y, func = model, times = c(0, 2), |
| 62 |
parms = parms, method = "lsoda") |
| 63 |
|
| 64 |
ls() # prove that t.old and t.new are local within 'model' |
| 65 |
} |
| 66 |
|
| 67 |
\keyword{ internal } |