# specify_ode: Specify Ordinary Differential Equation (ODE) In targeted: Targeted Inference

 specify_ode R Documentation

## Specify Ordinary Differential Equation (ODE)

### Description

Define compiled code for ordinary differential equation.

### Usage

specify_ode(code, fname = NULL, pname = c("dy", "x", "y", "p"))


### Arguments

 code string with the body of the function definition (see details) fname Optional name of the exported C++ function pname Vector of variable names (results, inputs, states, parameters)

### Details

The model (code) should be specified as the body of of C++ function. The following variables are defined bye default (see the argument pname)

• dyVector with derivatives, i.e. the rhs of the ODE (the result).

• xVector with the first element being the time, and the following elements additional exogenous input variables,

• yVector with the dependent variable

• pParameter vector

y'(t) = f_{p}(x(t), y(t)) All variables are treated as Armadillo (http://arma.sourceforge.net/) vectors/matrices.

As an example consider the Lorenz Equations \frac{dx_{t}}{dt} = σ(y_{t}-x_{t}) \frac{dy_{t}}{dt} = x_{t}(ρ-z_{t})-y_{t} \frac{dz_{t}}{dt} = x_{t}y_{t}-β z_{t}

We can specify this model as ode <- 'dy(0) = p(0)*(y(1)-y(0)); dy(1) = y(0)*(p(1)-y(2)); dy(2) = y(0)*y(1)-p(2)*y(2);' dy <- specify_ode(ode)

As an example of model with exogenous inputs consider the following ODE: y'(t) = β_{0} + β_{1}y(t) + β_{2}y(t)x(t) + β_{3}x(t)\cdot t This could be specified as mod <- 'double t = x(0); dy = p(0) + p(1)*y + p(2)*x(1)*y + p(3)*x(1)*t;' dy <- specify_ode(mod)##'

### Value

pointer (externalptr) to C++ function

### Author(s)

Klaus Kähler Holst