dyn_solve | R Documentation |
The function computes numerical solutions for a system of ordinary differential equations
given an initial state, parameters, and a sequence of time points t_1, ..., t_T
.
dyn_solve(odefun, times, param, init, method)
odefun |
function defining the ODE system. It should return a list where the first element is a numeric vector of derivatives. |
times |
numeric vector of time points where the solution is computed. |
param |
numeric scalar or vector of parameters to be passed to |
init |
numeric vector or a single-row matrix specifying the initial state values. Each element corresponds to a state variable. |
method |
character specifying the numerical solver. Default is |
This function numerically integrates a system of ODEs using solvers available in the
deSolve
package. The ODE system is defined by the user through odefun
,
which specifies the rate of change for each state variable.
The solver computes the values of the state variables at each time step, producing a trajectory of the system's evolution over time.
The ODE system must be written in first-order form:
\frac{dy}{dt} = f(t, y, p)
where:
- y
is the vector of state variables,
- t
is time,
- p
is a set of model parameters,
- f
is a function returning the derivatives.
This function simplifies the process of solving ODEs by managing input formatting and output structure, making it easier to extract and analyze results.
For details, see "ode
".
A list containing:
times
: copy of times
<state variable>
: Numeric vectors of computed values for each state variable.
library(deSolve)
### Lotka-Volterra equations ###
LVmod0D <- function(Time, State, Pars) {
with(as.list(c(State, Pars)),{
IngestC <- rI * P * C
GrowthP <- rG * P * (1 - P/K)
MortC <- rM * C
dP <- GrowthP - IngestC
dC <- IngestC * AE - MortC
return(list(c(dP, dC)))
})
}
### Define parameters ###
pars <- c(rI = 1.5, rG = 1.5, rM = 2, AE = 1, K = 10)
### Define time sequence ###
times <- seq(0, 30, by = 0.01)
### Initial conditions ###
state <- c(P = 1, C = 2)
### Solve ODE ###
dyn_solve(LVmod0D, times, pars, state)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.