Operators

<< Click to Display Table of Contents >>

Navigation:  Using GeNIe > Equation-based and hybrid models > Writing equations in GeNIe >

Operators

GeNIe allows the following operators in the definition of continuous nodes:

Arithmetic operators

+        addition, e.g., if x=3 and y=2, x+y produces 5

-        subtraction and unary minus, e.g., if x=3 and y=2, x-y produces 1 and -x produces -3

^        exponentiation (a^b means ab), e.g., if x=3 and y=2, x^y produces 9

*        multiplication, e.g., if x=3 and y=2, x*y produces 6

/        division, e.g., if x=3 and y=2, x/y produces 1.5

Comparison operators

>        greater than, e.g., if x=3 and y=2, x>y produces 1

<        smaller than, e.g., if x=3 and y=2, x<y produces 0

>=        greater or equal than, e.g., if x=3 and y=2, x>=y produces 1

<=        smaller or equal than, e.g., if x=3 and y=2, x<=y produces 0

<>        not equal, e.g., if x=3 and y=2, x<>y produces 1

=        equal, e.g., if x=3 and y=2, x=y produces 0

Conditional selection operator

? :        ternary conditional operator like in C, C++ or Java programming languages.

This operator is essentially a shortcut to the If() function. For example, a=b?5:3 is equivalent to If(a=b, 5, 3).

Order of calculation, operator precedence, and parentheses

Expressions in GeNIe are evaluated from left to right, according to the precedence order specified below (1 denotes the highest precedence).

Precedence order

Operator

1

- (unary minus)

2

^ (exponentiation)

3

* and / (multiplicative operators)

4

+ and - (additive operators)

5

>, <, >=, <=, = (comparison operators)

6

?: (conditional selection)

To change the order of calculation, enclose in parentheses those parts of the formula that should be calculated first. This can be done recursively, i.e., parentheses can be nested indefinitely. For example, if x=3 and y=2, 2*y+x/3-y+1 produces 4, 2*(y+x)/(3-y)+1 produces 11, and 2*((y+x)/(3-y)+1) produces 12.