User Tools

Site Tools


expression_syntax

Expression syntax

Here follows a description of often-used operators, functions and the most important syntax rules.

Operators

==== Mathematical Operators ====
Plus +
Minus -
Times *
Power ^
Divide /
==== Relational Operators ====
Equal ==
Not equal ~=
Less than <
Greater than >
Less than or equal
Greater than or equal >=
==== Logical Operators ====
And &&
Or ||

Conventions

  • The “.” (dot-symbol) is used as decimal symbol.
  • The default angle unit is radians.

Conditions

NoteIf you want a statement like Time==100, testing if Time is exactly equal to 100, you will have to make sure the solver is forced to include the time point 100 by specifying this in the simulation settings. This is because the variable step-size solver is not guaranteed to solve the states of the system at exactly time = 100. This is not a problem when using a fixed step-size solver where the step-size of the solver corresponds to the required time being included exactly.

AFRY Intelligent Scenario Modelling allows you to enter conditions directly in equations. There are two ways to enter conditions: using multiplication (classic) or by using the if() function (since AFRY Intelligent Scenario Modelling 5).

Conditions using the if() function

The if() function has the following syntax:

if( condition, value if true[, value if false] ) The last argument is optional and will default to 0 if not specified.

Example 1: Simple condition

IF a>b THEN    0.5 ELSE    0.2 if( a>b, 0.5, 0.2 )

Example 2: Nested condition

IF a>b THEN    IF c>d THEN       0.5    ELSE       0.2 ELSE    0.0if( a>b, if( c>d, 0.5, 0.2 ), 0.0 )

Example 3: Using logical operators

IF a>b AND c>d THEN    0.5 ELSE    0.2 if( a>b && c>d, 0.5, 0.2 )

Conditions using multiplication

When a logical operator is used in an expression, the expression will evaluate to either 0 (if false) or 1 (if true). If the logical operator is used in a statement within parenthesis, the parenthesis will evaluate to either 0 or 1. This is the approach used in ancient versions of AFRY Intelligent Scenario Modelling and is also the approach used in MATLAB.

Example 1: Simple condition

IF a>b THEN    0.5 ELSE    0.2 (a>b)*0.5+(a⇐b)*0.2

Avoiding division by zero

It is common that conditions are used to avoid division by zero (which will abort a simulation).

Example:

The expression k*Reservoir/time will result in a division by zero at time=0. To avoid the division, change the expression to:

if(time>0, k*Reservoir/time) Note: When using multiplication (see above) instead of the if() function, it is important that the whole expression that might cause a division of zero is placed within parenthesis:

(time>0)*(Comp1/time)

Help the solver!

For conditions that control the transfer to compartments it is important to notify the solver when the condition changes. This is done by using a discrete event block.

Index specific data

If you want to use the value for specific index of a vectorised parameter or inventory, the notation is the parameter name followed by the material name in brackets (e.g. Kd_clay[Cs-137], Dose[Cs][Man])

See also

expression_syntax.txt · Last modified: 2024/06/13 16:45 by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki