StepODE: Create a function for advancing the state of an ODE model by...

Description Usage Arguments Value See Also Examples

View source: R/StepODE.R

Description

This function creates a function for advancing the state of an ODE model using an integration method from the deSolve package. The resulting function (closure) can be used in conjunction with other functions (such as simTs) for simulating realisations of ODE models. This function is used similarly to StepEuler, but StepODE should be more accurate and efficient.

Usage

1
StepODE(RHSfun)

Arguments

RHSfun

A function representing the RHS of the ODE model. RHSfun should have prototype RHSfun(x,t,parms,...), with t representing current system time, x representing current system state and parms representing the model parameters. The value of the function should be a vector of the same dimension as x, representing the infinitesimal change in state.

Value

An R function which can be used to advance the state of the ODE model RHSfun by using an efficient ODE solver. The function closure has interface function(x0,t0,deltat,parms,...), where t0 and x0 represent the initial time and state, and deltat represents the amount of time by which the process should be advanced. The function closure returns a vector representing the simulated state of the system at the new time.

See Also

StepEulerSPN, StepEuler, simTs, ode

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
# Build a RHS for the Lotka-Volterra system
LVrhs <- function(x,t,parms)
{
        with(as.list(c(x,parms)),{
                c( c1*x1 - c2*x1*x2 ,
                      c2*x1*x2 - c3*x2 )
        })
}
# create a stepping function
stepLV = StepODE(LVrhs)
# step the function
print(stepLV(c(x1=50,x2=100),0,1,parms=c(c1=1,c2=0.005,c3=0.6)))
# integrate the process and plot it
out = simTs(c(x1=50,x2=100),0,50,0.1,stepLV,parms=c(c1=1,c2=0.005,c3=0.6))
plot(out,plot.type="single",lty=1:2)

Example output

Loading required package: abind
Loading required package: parallel
      x1       x2 
88.23202 76.59576 

smfsb documentation built on May 2, 2019, 5:13 a.m.