library(deSolve)
Department of Mathematics
University of Manitoba*
deSolve
:The functions provide an interface to the FORTRAN functions ‘lsoda’, ‘lsodar’, ‘lsode’, ‘lsodes’ of the ‘ODEPACK’ collection, to the FORTRAN functions ‘dvode’, ‘zvode’ and ‘daspk’ and a C-implementation of solvers of the ‘Runge-Kutta’ family with fixed or variable time steps
C
are also includedAs with most numerical solvers, you need to write a function returning the value of the right hand side of your equation (the vector field) at a given point in phase space, then call this function from the solver
First, we load the library
\[ \frac{d}{dt}N(t)= rN(t)\left(1-\frac{N(t)}{K}\right) \] or, omitting time dependence \[ N' = rN\left(1-\frac NK\right) \]
IC
is a named vectortimes
is a vector of times at which the solution is returned (not necessarily where it is computed, can be different from this)params
is a listIn this case, beware of not having a variable and a parameter with the same name..
Just to clarify:
and using with(as.list(c()))
makes these values available to the function with just the names (hence we do not need p$r
, for instance)
Just to make sure results are the same
lsoda
lsoda
switches automatically between stiff and nonstiff methods
You can also specify other methods: “lsode”, “lsodes”, “lsodar”, “vode”, “daspk”, “euler”, “rk4”, “ode23”, “ode45”, “radau”, “bdf”, “bdf_d”, “adams”, “impAdams” or “impAdams_d” ,“iteration” (the latter for discrete-time systems)