# dde: Solve Delay Differential Equations In PBSddesolve: Solver for Delay Differential Equations

## Description

A solver for systems of delay differential equations based on numerical routines from Simon Wood's solv95 program. This solver is also capable of solving systems of ordinary differential equations.

Please see the included demos for examples of how to use dde.

To view available demos run demo(package="PBSddesolve").
The supplied demos require that the R package PBSmodelling be installed.

## Usage

 1 2 dde(y, times, func, parms=NULL, switchfunc=NULL, mapfunc=NULL, tol=1e-08, dt=0.1, hbsize=10000)

## Arguments

 y Vector of initial values of the DDE system. The size of the supplied vector determines the number of variables in the system. times Numeric vector of specific times to solve. func A user supplied function that computes the gradients in the DDE system at time t. The function must be defined using the arguments: (t,y) or (t,y,parms), where t is the current time in the integration, y is a vector of the current estimated variables of the DDE system, and parms is any R object representing additional parameters (optional). The argument func must return one of the two following return types: 1) a vector containing the calculated gradients for each variable; or 2) a list with two elements - the first a vector of calculated gradients, the second a vector (possibly named) of values for a variable specified by the user at each point in the integration. parms Any constant parameters to pass to func, switchfunc, and mapfunc. switchfunc An optional function that is used to manipulate state values at given times. The switch function takes the arguments (t,y) or (t,y,parms) and must return a numeric vector. The size of the vector determines the number of switches used by the model. As values of switchfunc pass through zero (from positive to negative), a corresponding call to mapfunc is made, which can then modify any state value. mapfunc If switchfunc is defined, then a map function must also be supplied with arguments (t, y, switch_id) or t, y, switch_id, parms), where t is the time, y are the current state values, switch_id is the index of the triggered switch, and parms are additional constant parameters. tol Maximum error tolerated at each time step (as a proportion of the state variable concerned). dt Maximum initial time step. hbsize History buffer size required for solving DDEs.

## Details

The user supplied function func can access past values (lags) of y by calling the pastvalue function. Past gradients are accessible by the pastgradient function. These functions can only be called from func and can only be passed values of t greater or equal to the start time, but less than the current time of the integration point. For example, calling pastvalue(t) is not allowed, since these values are the current values which are passed in as y.

## Value

A data frame with one column for t, a column for every variable in the system, and a column for every additional value that may (or may not) have been returned by func in the second element of the list.

If the initial y values parameter was named, then the solved values column will use the same names. Otherwise y1, y2, ... will be used.

If func returned a list, with a named vector as the second element, then those names will be used as the column names. If the vector was not named, then extra1, extra2, ... will be used.