APMonitor Equations

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.

Operations

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.

OperandDescriptionExample
!,#,%Comment% equation #1
0 = x[1] + x[2] ! eqn1
&Line Continuation0 = x[1] &
+ x[2]
=Equalityx=y
<Less thanx<y
<=Less than or equalx<=y
>Greater thanx>y
>=Greater than or equalx>=y
-Unary minus-(x-y) = 0
+Additionx+y = 0
-Subtractionx-y=0
*Multiplicationx*y=0
/Divisionx/y=0
^Powerx^y=0
abs()Absolute valueabs(x*y)=0
exp()Exponentiationexp(x*y)=0
log10()Base-10 Loglog10(x*y)=0
log()Natural Loglog(x*y)=0
sqrt()Square Rootsqrt(x*y)=0
sinh()Hyperbolic Sinesinh(x*y)=0
cosh()Hyperbolic Cosinecosh(x*y)=0
tanh()Hyperbolic Tangenttanh(x*y)=0
sin()Sinesin(x*y)=0
cos()Cosinecos(x*y)=0
tan()Tangenttan(x*y)=0
asin()Arc-sineasin(x*y)=0
acos()Arc-cosacos(x*y)=0
atan()Arc-tangentatan(x*y)=0
erf()Error functionerf(x*y)=0
erfc()Complementary error functionerfc(x*y)=0
sigmd()Sigmoid functionsigmd(x*y)=0
$Differential$x = -x + y

All trigonometric functions are in radians (not degrees).

Example

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