Department of Mathematics
University of Manitoba*
As I have already pointed out, 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
So you are benefiting from years and year of experience: ODEPACK is a set of Fortran (77!) solvers developed at Lawrence Livermore National Laboratory (LLNL) starting in the late 70s
Other good solvers are also included, those written in C
Refer to the package help for details
As with more 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
This also works: add p
to arguments of as.list
and thus use without p$
prefix
library(deSolve)
rhs_logistic <- function(t, x, p) {
with(as.list(c(x, p)), {
dN <- r * N *(1-N/K)
return(list(dN))
})
}
params = list(r = 0.1, K = 100)
IC = c(N = 50)
times = seq(0, 100, 1)
sol <- ode(IC, times, rhs_logistic, params)
In this case, beware of not having a variable and a parameter with the same name..
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)
ode(y, times, func, parms,
method = "ode45")
See the code practicum_01_fitting.R, which we will go over now