Both the nonlinear regression and the dynamical systems model builders require the specification of mathematical expressions: for nonlinear regression models we must specify the relationship between the outcome and predictor variables, and for dynamical systems we must specify the differential equations defining the system. This page describes the syntax used for these expressions.
Literal numeric values are expressed using the normal integer or floating point forms familiar from most programming languages, e.g. 123, 3.14159, 6.02E23 and so on.
Identifiers for variables and parameters in equations should start with a letter (upper or lower case), and are composed of upper or lower case letters, digits and underscores. Some special rules exist governing the rendering of identifiers for display in the model builders. The following table covers the most common possibilities:
| Input syntax | Rendered form | |
|---|---|---|
x, y |
, | Single-letter identifiers |
age, price |
, | Multi-letter identifiers |
beta, Psi |
, | Greek letters |
x_0, beta_age |
, | Subscripted identifiers |
The identifiers t, e, pi are reserved -- they are used to stand for the time variable in dynamical systems, the base of natural logarithms, and the usual constant . In addition, the identifiers W, W1, W2, etc. are reserved for the representation of Wiener processes in stochastic differential equations.
The usual arithmetic operators are expressed as + (addition), - (subtraction), * (multiplication), / (division) and ^ (exponentiation) and parentheses are used for expression grouping. Here are some examples:
x + 1 ⇒ x - z ⇒ x * (y + 3) ⇒ 1 / (x + 1) ⇒ 3 * x^3 + 2 * x^2 + x - 4 ⇒ A number of common mathematical functions are built-in:
| Input syntax | Rendered form | |
|---|---|---|
sin(x), cos(x), tan(x) |
, , | Trigonometric functions |
asin(x), acos(x), atan(x) |
, , | Inverse trigonometric functions |
exp(x) |
Exponential function | |
log(x), log10(x) |
, | Natural and base-10 logarithms |
sqrt(x) |
Square root | |
abs(x) |
Absolute value | |
ceil(x), floor(x) |
, | Ceiling and floor functions |
atan2(x, y) |
Inverse tangent of | |
min(x, y) |
Minimum of and | |
max(x, y) |
Maximum of and |
In the dynamical systems builder, it is necessary to specify time derivatives of variables in order to define ordinary and stochastic differential equations. A simple example shows how this works: the input m * D^2 x + k * D x + \omega^2 x = A * cos(\Omega * t) results in the following rendered equation
Here, an expression of the form
D y represents the first time derivative of , , andD^n y, with n an integer, represents the th time derivative of , .It is important to note that we must write D x and not Dx. The space between the D and the variable name is important: Dx is a single identifer, D x is a derivative.
In stochastic differential equations, as well as ordinary derivatives, we need to be able to represent Wiener terms (increments of white noise stochastic processes). In order to maintain a consistent syntax between ODEs and SDEs, we adopt a slight abuse of notation, where for a Wiener process , we write D W to formally stand for the derivative of this process, which is itself a white noise process.
This means that the stochastic differential equation
is represented as D x = theta * (mu - x) + sigma * D W and is in fact rendered as
even though, strictly, Wiener processes are not differentiable.
For systems of SDEs requiring multiple Wiener processes, we use the symbols W1, W2, etc., as for example:
D S = mu * S + sqrt(nu) * S * D W1
D nu = kappa * (theta - nu) + xi * sqrt(nu) * D W2
representing the system of SDEs
Here and are two separate (but possibly correlated) Wiener processes.
In the dynamical systems builder, it is possible to make use of auxiliary functions to simplify the expression of differential equations. If we want to write the system
we can simply introduce the symbol f as a function into an equation, i.e.
m * D^2 x + k * D x + omega^2 * x = f(t)
and then fill in the right hand side of the auxiliary function f in the new field that appears in the builder window.