Equations consist of a collection of parameters and variables that are related by operands (+,-,*,/,exp(),d()/dt, etc.). The equations define the relationship between variables.
Equations are declared in the Equations ... End Equations section of the model file. The equations may be defined in one section or in multiple declarations throughout the model. Equations are parsed sequentially, from top to bottom. However, implicit equations are solved simultaneously so the order of the equations does not change the solution.
Open-equation format is allowed for differential and algebraic equations. Open-equation means that the equation can be expressed in the least restrictive form. Other software packages require differential equations to be posed in the semi-explicit form: dx/dt = f(x). This is not required with APMonitor modelling language. All equations are automatically transformed into residual form.
The available operands are listed below with a short description of each and a simple example involving variable x and y. Equations may be in the form of equality (=) or inequality (>,>=,<,<=) constraints. For inequalities, the equation may be bounded between lower and upper limits that are also functions of variables.
|!,#,%||Comment||% equation #1 |
0 = x + x ! eqn1
|&||Line Continuation||0 = x & |
|<=||Less than or equal||x<=y|
|>=||Greater than or equal||x>=y|
|-||Unary minus||-(x-y) = 0|
|+||Addition||x+y = 0|
|erfc()||Complementary error function||erfc(x*y)=0|
|$||Differential||$x = -x + y|
A couple differential and algebraic equations are shown below. For steady-state solutions the differential variables ($x) are set to zero. Variables x, y, and z were not given initial values. In the absence of an initial condition, variables are set to a default value of 1.0.
! Example with three equality equations Model example Parameters p = 2 End Parameters Variables x y z End Variables Equations exp(x*p)=y z = p*$x + x (y+2/x)^(x*z) * & (log(tanh(sqrt(y-x+x^2))+3))^2 & = 2+sinh(y)+acos(x+y)+asin(x/y) End Equations End Model The steady-state solution is: p=2 x=-1.0445 y=0.1238 z=-1.0445.
! Example with an inequality Model example Variables x y z End Variables Equations x = 0.5 * y 0 = z + 2*x x < y < z End Equations End Model