’tau’: 1.0
}
2.2 Setting the history
The history of the variables is stored in the dictionary dde23.hist. The keys are the variable names and there
is an additional key ’t’ for the time array of the history.
There is a second dictionary dde23.Vhist where the time derivatives of the history is stored (this is needed for
the solver). When the solver is initialized, i.e.,:
dde = dde23(eqns, params)
the history of all variables (defined in eqns) is initialized to an array of length nn=101 filled with zeros. The
time array is evenly spaced in the interval [-maxdelay, 0].
It is possible to manipulate these arrays directly, however this is not recommended since one easily ends up with
an ill-defined history resulting for example in segfaults or false results.
Instead use the following methods to set the history.
hist_from_funcs(dic, nn=101)
Initialise the histories with the functions stored in the dictionary dic. The keys are the variable names. The
function will be called as f(t) for t in [-maxdelay, 0] on nn samples in the interval.
This function provides the simplest way to set the history. It is often convenient to use python lambda
functions for f. This way you can define the history function in place.
If any variable names are missing in the dictionaries, the history of these variables is set to zero and a
warning is printed. If the dictionary contains keys not matching any variables these entries are ignored and
a warning is printed.
Example: Initialise the history of the variables x and y with cos and sin functions using a finer sampling
resolution:
from math import sin, cos
histdic = {
’x’: lambda t: cos(0.2
*
t),
’y’: lambda t: sin(0.2
*
t)
}
dde.hist_from_funcs(histdic, 500)
hist_from_arrays(dic, useend=True)
Initialise the history using a dictionary of arrays with variable names as keys. Additionally a time array can
be given corresponding to the key t. All arrays in dic have to have the same lengths.
If an array for t is given the history is interpreted as points (t,var). Otherwise the arrays will be evenly
spaced out over the interval [-maxdelay, 0].
If useend is True the time array is shifted such that the end time is zero. This is useful if you want to use the
result of a previous simulation as the history.
If any variable names are missing in the dictionaries, the history of these variables is set to zero and a
warning is printed. If the dictionary contains keys not matching any variables (or ’t’) these entries are
ignored and a warning is printed.
Example::