Title: | Solver for Delay Differential Equations |
---|---|
Description: | Functions for solving systems of delay differential equations by interfacing with numerical routines written by Simon N. Wood, including contributions from Benjamin J. Cairns. These numerical routines first appeared in Simon Wood's 'solv95' program. This package includes a vignette and a complete user's guide. 'PBSddesolve' originally appeared on CRAN under the name 'ddesolve'. That version is no longer supported. The current name emphasizes a close association with other 'PBS' packages, particularly 'PBSmodelling'. |
Authors: | Alex Couture-Beil [aut], Jon T. Schnute [aut], Rowan Haigh [aut, cre], Simon N. Wood [aut], Benjamin J. Cairns [aut], Nicholas Boers [ctb], Nick Fisch [ctb] |
Maintainer: | Rowan Haigh <[email protected]> |
License: | GPL (>= 2) |
Version: | 1.13.4 |
Built: | 2024-11-10 04:29:21 UTC |
Source: | https://github.com/pbs-software/pbs-ddesolve |
A solver for systems of delay differential equations based on numerical routines from
C source code solv95
by
Simon Wood.
This solver is also capable of solving systems of ordinary differential equations.
dde(y, times, func, parms=NULL, switchfunc=NULL, mapfunc=NULL, tol=1e-08, dt=0.1, hbsize=10000)
dde(y, times, func, parms=NULL, switchfunc=NULL, mapfunc=NULL, tol=1e-08, dt=0.1, hbsize=10000)
y |
|
times |
|
func |
|
parms |
|
switchfunc |
|
mapfunc |
|
tol |
|
dt |
|
hbsize |
|
Please see the included demos ('blowflies'
, 'cooling'
, 'icecream'
,
'lorenz'
) for examples of how to use dde
.
The demos can be run two ways:
Using the package utils
, run the command:demo(icecream, package="PBSddesolve", ask=FALSE)
Using the package PBSmodelling
, run the commands:require(PBSmodelling); runDemos()
The latter produces a GUI that shows all demos available from locally installed packages.
Choose PBSddesolve
.
Note that the examples are run in the temporary working environment .PBSddeEnv
.
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
.
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.
Alex Couture-Beil – Software Engineer, Earthly Technologies, Victoria BC
Maintainer: Rowan Haigh, Program Head – Offshore Rockfish
Pacific Biological Station (PBS), Fisheries & Oceans Canada (DFO), Nanaimo BC
locus opus: Offsite, Vancouver BC
Last modified Rd: 2024-01-04
################################################## ## This is just a single example of using dde. ## For more examples see demo(package="PBSddesolve") ## the demos require the package PBSmodelling ################################################## require(PBSddesolve) local(env=.PBSddeEnv, expr={ #create a func to return dde gradient yprime <- function(t,y,parms) { if (t < parms$tau) lag <- parms$initial else lag <- pastvalue(t - parms$tau) y1 <- parms$a * y[1] - (y[1]^3/3) + parms$m * (lag[1] - y[1]) y2 <- y[1] - y[2] return(c(y1,y2)) } #define initial values and parameters yinit <- c(1,1) parms <- list(tau=3, a=2, m=-10, initial=yinit) # solve the dde system yout <- dde(y=yinit,times=seq(0,30,0.1),func=yprime,parms=parms) # and display the results plot(yout$time, yout$y1, type="l", col="red", xlab="t", ylab="y", ylim=c(min(yout$y1, yout$y2), max(yout$y1, yout$y2))) lines(yout$time, yout$y2, col="blue") legend("topleft", legend = c("y1", "y2"),lwd=2, lty = 1, xjust = 1, yjust = 1, col = c("red","blue")) })
################################################## ## This is just a single example of using dde. ## For more examples see demo(package="PBSddesolve") ## the demos require the package PBSmodelling ################################################## require(PBSddesolve) local(env=.PBSddeEnv, expr={ #create a func to return dde gradient yprime <- function(t,y,parms) { if (t < parms$tau) lag <- parms$initial else lag <- pastvalue(t - parms$tau) y1 <- parms$a * y[1] - (y[1]^3/3) + parms$m * (lag[1] - y[1]) y2 <- y[1] - y[2] return(c(y1,y2)) } #define initial values and parameters yinit <- c(1,1) parms <- list(tau=3, a=2, m=-10, initial=yinit) # solve the dde system yout <- dde(y=yinit,times=seq(0,30,0.1),func=yprime,parms=parms) # and display the results plot(yout$time, yout$y1, type="l", col="red", xlab="t", ylab="y", ylim=c(min(yout$y1, yout$y2), max(yout$y1, yout$y2))) lines(yout$time, yout$y2, col="blue") legend("topleft", legend = c("y1", "y2"),lwd=2, lty = 1, xjust = 1, yjust = 1, col = c("red","blue")) })
A trivial function that sets the user's working directory to an old (previous) location before opening the Windows GUI that is now being closed.
.onClosePBSddeExamples()
.onClosePBSddeExamples()
setwd(.PBSddeEnv$oldwd)
Alex Couture-Beil – Software Engineer, Earthly Technologies, Victoria BC
Maintainer: Rowan Haigh, Program Head – Offshore Rockfish
Pacific Biological Station (PBS), Fisheries & Oceans Canada (DFO), Nanaimo BC
locus opus: Offsite, Vancouver BC
Last modified Rd: 2024-01-04
An environment set aside for PBSddesolve.
.PBSddeEnv
.PBSddeEnv
A new environment with a .GlobalEnv
parent.
The environment is created in 'zzz.r'
and can be used by
PBSmodelling
functions 'lisp'
, 'tget'
,
'tput'
, 'tprint'
, and 'tcall'
.
Generated by a call to the base function new.env()
.
In PBSmodelling:lisp
,
tget
These routines provides access to variable history at lagged times.
The lagged time must not be less than
, nor should it be greater
than the current time of gradient calculation.
The routine cannot be directly called by a user, and will only work during the
integration process as triggered by the
dde
routine.
pastvalue(t) pastgradient(t)
pastvalue(t) pastgradient(t)
t |
Access history at time |
Vector of variable history at time t
.
Alex Couture-Beil – Software Engineer, Earthly Technologies, Victoria BC
Maintainer: Rowan Haigh, Program Head – Offshore Rockfish
Pacific Biological Station (PBS), Fisheries & Oceans Canada (DFO), Nanaimo BC
locus opus: Regional Headquarters (RHQ), Vancouver BC
Last modified Rd: 2023-01-30
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 user guide PBSddesolve-UG.pdf
, located in R's
library directory ./library/PBSddesolve/doc
, for a
comprehensive overview.
Alex Couture-Beil – Software Engineer, Earthly Technologies, Victoria BC
Jon T. Schnute – Scientist Emeritus, DFO, Nanaimo BC
Nicholas M. Boers – Senior Software Engineer, Jobber, Edmonton AB
Maintainer: Rowan Haigh, Program Head – Offshore Rockfish
Pacific Biological Station (PBS), Fisheries & Oceans Canada (DFO), Nanaimo BC
locus opus: Regional Headquarters (RHQ), Vancouver BC
Last modified Rd: 2023-01-30
Wood, S.N. (1999) Solv95: a numerical solver for systems of delay differential equations with switches. Saint Andrews, UK. 10 pp.