dyn_solve {dynemu}R Documentation

Solving ordinary (ODEs) differntial equations with a specified time squence.

Description

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.

Usage

dyn_solve(odefun, times, param, init, method)

Arguments

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 odefun.

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 "lsoda".

Details

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".

Value

A list containing:

Examples

### 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)


[Package dynemu version 1.0.0 Index]