## 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*. For equations may be in the form of equalities (=) or inequalities (>,<). For inequalities, the equation may be bounded between lower and upper limits that are also functions of variables.

Operand | Description | Example |
---|---|---|

!,#,% | Comment | % equation #1 0 = x[1] + x[2] ! eqn1 |

& | Line Continuation | 0 = x[1] & + x[2] |

= | Equality | x=y |

< | Less than | x<y |

<= | Less than or equal | x<=y |

> | Greater than | x>y |

>= | Greater than or equal | x>=y |

- | Unary minus | -(x-y) = 0 |

+ | Addition | x+y = 0 |

- | Subtraction | x-y=0 |

* | Multiplication | x*y=0 |

/ | Division | x/y=0 |

^ | Power | x^y=0 |

abs() | Absolute value | abs(x*y)=0 |

exp() | Exponentiation | exp(x*y)=0 |

log10 | Base-10 Log | log10(x*y)=0 |

log | Natural Log | log(x*y)=0 |

sqrt() | Square Root | sqrt(x*y)=0 |

sinh() | Hyperbolic Sine | sinh(x*y)=0 |

cosh() | Hyperbolic Cosine | cosh(x*y)=0 |

tanh() | Hyperbolic Tanget | tanh(x*y)=0 |

sin() | Sine | sin(x*y)=0 |

cos() | Cosine | cos(x*y)=0 |

tan() | Tangent | tan(x*y)=0 |

asin() | Arc-sine | asin(x*y)=0 |

acos() | Arc-cos | acos(x*y)=0 |

atan() | Arc-tangent | atan(x*y)=0 |

erf() | Error function | erf(x*y)=0 |

erfc() | Complementary error function | erfc(x*y)=0 |

$ | Differential | $x = -x + y |

### 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 |