## Equations

## Main.Equations History

Hide minor edits - Show changes to markup

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

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

All trigonometric functions are in radians (not degrees).

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

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.

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.

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

## Equations

(:table border=1 width=50% align=left bgcolor=#EEEEEE cellspacing=0:)

(:table border=1 width=100% align=left bgcolor=#EEEEEE cellspacing=0:)

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

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

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

(y+2/x)^(x*z) * (log(tanh(sqrt(y-x+x^2))+3))^2 = 2+sinh(y)+acos(x+y)+asin(x/y)

(y+2/x)^(x*z) * & (log(tanh(sqrt(y-x+x^2))+3))^2 & = 2+sinh(y)+acos(x+y)+asin(x/y)

There are currently 26 operands for parameters or variables. They 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.

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.

!,#,% | Comment | ! equation #1 (:html:)<br>(:htmlend:) 0 = x[1] + x[2] ! comment |
---|

!,#,% | Comment | % equation #1 (:html:)<br>(:htmlend:) 0 = x[1] + x[2] ! eqn1 |

!,#,% | Comment | ! equation #1 (:html:)<br>(:htmlend:) 0 = x[1] + x[2] ! comment |

!,#,% | Comment | ! equation #1 (:html:)<br>(:htmlend:) 0 = x[1] + x[2] ! comment |
---|

!,#,% | Comment | ! comment |

!,#,% | Comment | ! equation #1 (:html:)<br>(:htmlend:) 0 = x[1] + x[2] ! comment |

= | Line Continuation | 0 = x[1] & (:html:)<br>(:htmlend:) + x[2] |

!,#,% | Comment | ! comment |

= | Equality | x=y |

& | Line Continuation | 0 = x[1] & (:html:)<br>(:htmlend:) + x[2] |

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

= | Line Continuation | 0 = x[1] & (:html:)<br>(:htmlend:) + x[2] |

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

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

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

There are currently 21 operands for parameters or variables. They are listed below with a short description of each and a simple example involving variable *x* and *y*.

There are currently 26 operands for parameters or variables. They 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.

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

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

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

A couple differential and algebraic equations are shown below. The steady-state solution is p=2, x=-1.0445, y=0.1238, and z=-1.0445. 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.

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 model that demonstrates a few equations

! Example with three equality equations

The steady-state solution is: p=2 x=-1.0445 y=0.1238 z=-1.0445.

(:cellnr:)

! 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

(:table class='markup horiz' align='left':) (:cellnr class='markup1':)

! Example model that demonstrates a few 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

(:table border=1 width=50% align=left bgcolor=#EEEEEE cellspacing=0:) (:cellnr:)

! Example model that demonstrates a few 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

### Equation operands

### Operations

### Equation Example

### Example

Operand | Description | Example |
---|

Operand | Description | Example |
---|

A couple differential and algebraic equations are shown below. The steady-state solution is p=2, x=-1.0445, y=0.1238, and z=-1.0445. For steady-state solutions the differential variables (*$x*) are set to zero.

A couple differential and algebraic equations are shown below. The steady-state solution is p=2, x=-1.0445, y=0.1238, and z=-1.0445. 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.

A couple differential and algebraic equations are shown below. The steady-state solution is p=2, x=-1.0445, y=0.1238, and z=-1.0445. For steady-state solutions the differential variables (*$x*) are set to zero.

# Steady state solution

# p = 2

# x = -1.0445

# y = 0.12380

# z = -1.0445

[@! Example model that demonstrates equation declarations

[@! Example model that demonstrates a few equations

# Steady state solution

# p = 2

# x = -1.0445

# y = 0.12380

# z = -1.0445E+00

*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.

*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.

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

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

### Equation Example

p = 1

p = 2

Equations ! The program tranforms all equations from the 'original form' to ! the 'residual form'. Sparse first derivatives ! of the residual are reported with respect to the variable values. x = y ! Original form x-y = 0 ! Residual form ! Below are examples of some of the types of variable operations that ! are possible. There is currently a limit of 100 unique variables per equation. -(x-y) = 0 ! Unary minus x+y=0 ! Addition x-y=0 ! Subtraction x*y=0 ! Multiplication x/y=0 ! Division x^y=0 ! Power abs(x*y)=0 ! Absolute value exp(x*y)=0 ! Exponentiation log10(x*y)=0 ! Log10 log(x*y)=0 ! Log (natural log) sqrt(x*y)=0 ! Square Root sinh(x*y)=0 ! Hyperbolic Sine cosh(x*y)=0 ! Hyperbolic Cosine tanh(x*y)=0 ! Hyperbolic Tanget sin(x*y)=0 ! Sine cos(x*y)=0 ! Cosine tan(x*y)=0 ! Tangent asin(x*y)=0 ! Arc-sine acos(x*y)=0 ! Arc-cos atan(x*y)=0 ! Arc-tangent ! Example of a more complex equation. There are 3 unique variables (x,y,z) and 1 residual. ! Exact first derivatives are reported for: ! d(res)/dx, d(res)/dy, d(res)/dz ! where: ! res = (y+2/x)^(x*z) * (log(tanh(sqrt(y-x+x^2))+3))^2 - (2+sinh(y)+acos(x+y)+asin(x/y)) (y+2/x)^(x*z) * (log(tanh(sqrt(y-x+x^2))+3))^2 = 2+sinh(y)+acos(x+y)+asin(x/y) ! Differential equation with $ indicating a differential with respect to time ! Sparsity pattern is augmented by n columns where n is the number of variables ! If x is the first variable and there are 3 variables then $x would be variable 4 ! x=1 ! y=2 ! z=3 ! $x=4 ! $y=5 ! $z=6 $x = -x + y ! Characters are not case specific $Z = -x + z*Y End Equations

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

# | Description | Example |
---|---|---|

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

2 | Addition | x+y = 0 |

3 | Subtraction | x-y=0 |

4 | Multiplication | x*y=0 |

5 | Division | x/y=0 |

6 | Power | x^y=0 |

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Description | Example |
---|

# | Description | Example |
---|

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 |

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

Exponentiation | exp(x*y)=0 |

Log10 | log10(x*y)=0 |

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

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

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

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

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

Sine | sin(x*y)=0 |

Cosine | cos(x*y)=0 |

Tangent | tan(x*y)=0 |

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

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

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

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

2 | Addition | x+y = 0 |

3 | Subtraction | x-y=0 |

4 | Multiplication | x*y=0 |

5 | Division | x/y=0 |

6 | Power | x^y=0 |

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

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

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

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

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

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

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

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

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

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

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

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

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

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

There are currently 21 operands for parameters or variables. They are listed below with a short description of each and a simple example involving variable *x* and optionally *y*.

There are currently 21 operands for parameters or variables. They are listed below with a short description of each and a simple example involving variable *x* and *y*.

Description | !Example |
---|

Description | Example |
---|

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

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 |

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

Exponentiation | exp(x*y)=0 |

Log10 | log10(x*y)=0 |

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

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

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

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

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

Sine | sin(x*y)=0 |

Cosine | cos(x*y)=0 |

Tangent | tan(x*y)=0 |

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

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

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

Description | !Example |
---|---|

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 |

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

Exponentiation | exp(x*y)=0 |

Log10 | log10(x*y)=0 |

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

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

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

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

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

Sine | sin(x*y)=0 |

Cosine | cos(x*y)=0 |

Tangent | tan(x*y)=0 |

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

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

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

Parameters are fixed values that represent model inputs, fixed constants, or any other value that does not change. Parameters are not modified by the solver as it searches for a solution. As such, parameters do not contribute to the number of degrees of freedom (DOF).

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.

*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.

### Equation operands

There are currently 21 operands for parameters or variables. They are listed below with a short description of each and a simple example involving variable *x* and optionally *y*.

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

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 |

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

Exponentiation | exp(x*y)=0 |

Log10 | log10(x*y)=0 |

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

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

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

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

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

Sine | sin(x*y)=0 |

Cosine | cos(x*y)=0 |

Tangent | tan(x*y)=0 |

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

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

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

Variables x = 0.2 y = 0.5 z = 1.5 End Variables

Parameters p = 1 End Parameters Variables x y z End Variables

## Equations

Parameters are fixed values that represent model inputs, fixed constants, or any other value that does not change. Parameters are not modified by the solver as it searches for a solution. As such, parameters do not contribute to the number of degrees of freedom (DOF).

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.

(:table class='markup horiz' align='left':) (:cellnr class='markup1':)

! Example model that demonstrates equation declarations Model example Variables x = 0.2 y = 0.5 z = 1.5 End Variables Equations ! The program tranforms all equations from the 'original form' to ! the 'residual form'. Sparse first derivatives ! of the residual are reported with respect to the variable values. x = y ! Original form x-y = 0 ! Residual form ! Below are examples of some of the types of variable operations that ! are possible. There is currently a limit of 100 unique variables per equation. -(x-y) = 0 ! Unary minus x+y=0 ! Addition x-y=0 ! Subtraction x*y=0 ! Multiplication x/y=0 ! Division x^y=0 ! Power abs(x*y)=0 ! Absolute value exp(x*y)=0 ! Exponentiation log10(x*y)=0 ! Log10 log(x*y)=0 ! Log (natural log) sqrt(x*y)=0 ! Square Root sinh(x*y)=0 ! Hyperbolic Sine cosh(x*y)=0 ! Hyperbolic Cosine tanh(x*y)=0 ! Hyperbolic Tanget sin(x*y)=0 ! Sine cos(x*y)=0 ! Cosine tan(x*y)=0 ! Tangent asin(x*y)=0 ! Arc-sine acos(x*y)=0 ! Arc-cos atan(x*y)=0 ! Arc-tangent ! Example of a more complex equation. There are 3 unique variables (x,y,z) and 1 residual. ! Exact first derivatives are reported for: ! d(res)/dx, d(res)/dy, d(res)/dz ! where: ! res = (y+2/x)^(x*z) * (log(tanh(sqrt(y-x+x^2))+3))^2 - (2+sinh(y)+acos(x+y)+asin(x/y)) (y+2/x)^(x*z) * (log(tanh(sqrt(y-x+x^2))+3))^2 = 2+sinh(y)+acos(x+y)+asin(x/y) ! Differential equation with $ indicating a differential with respect to time ! Sparsity pattern is augmented by n columns where n is the number of variables ! If x is the first variable and there are 3 variables then $x would be variable 4 ! x=1 ! y=2 ! z=3 ! $x=4 ! $y=5 ! $z=6 $x = -x + y ! Characters are not case specific $Z = -x + z*Y End Equations End Model

(:tableend:)