Description Usage Arguments Value See Also Examples
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.
1 | StepODE(RHSfun)
|
RHSfun |
A function representing the RHS of the ODE model. |
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.
StepEulerSPN
, StepEuler
,
simTs
, ode
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)
|
Loading required package: abind
Loading required package: parallel
x1 x2
88.23202 76.59576
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.