| StepEuler | R Documentation |
This function creates a function for advancing the state of an ODE model
using a simple Euler integration method. The resulting function
(closure) can be used in conjunction with other functions (such as
simTs) for simulating realisations of ODE models. This
function is intended to be pedagogic. See StepODE for a
more accurate integration function.
StepEuler(RHSfun,dt=0.01)
RHSfun |
A function representing the RHS of the ODE
model. |
dt |
Time step to be used by the simple Euler integration method. Defaults to 0.01. |
An R function which can be used to advance the state of the ODE model RHSfun by using an Euler method with step size dt. The function closure has interface function(x0,t0,deltat,...), 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, StepODE, simTs, simSample
# Build a RHS for the Lotka-Volterra system
LVrhs <- function(x,t,th=c(c1=1,c2=0.005,c3=0.6))
{
with(as.list(c(x,th)),{
c( c1*x1 - c2*x1*x2 ,
c2*x1*x2 - c3*x2 )
})
}
# create a stepping function
stepLV = StepEuler(LVrhs)
# step the function
print(stepLV(c(x1=50,x2=100),0,1))
# integrate the process and plot it
out = simTs(c(x1=50,x2=100),0,20,0.1,stepLV)
plot(out,plot.type="single",lty=1:2)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.