This page contains some general information on how to write expressions in MODELS. An expression is a description of the method by which a value is determined. An expression can be used for specifying the value of a single element or of a group of array elements. The type of value (numerical or logical) resulting from the evaluation of an expression is determined by the type of the operators used in the expression.

The following forms of expressions can be used in MODELS:

- - regular expressions

- - sum expressions

- - derivative expressions

- - use of integrals

________________________________________

A regular expression is either a logical expression or a numerical expression depending on the operators used in the expression. The value of a regular expression is either a single value or an array of values depending on the value descriptions used in the expression.

Relational operators are:

> greater than

>= greater than or equal to

< less than

<= less than or equal to

= equal to

<> not equal to

Numerical operators:

+ add

- subtract

* multiply

/ divide

** power

MOD modulo

Logical operators

OR

AND

A sub-expression is a regular expression enclosed in parentheses (expr)

A function is called in the following way: y:=function-name(var1, var2,....varN)

Limits can be applied to all expressions. y:=expr {plainlimits}

Some examples of regular expressions follow:

________________________________________

An expression is specified as a sum expression when it is necessary to put in evidence the linearity of the expression with respect to the

A linear polynomial expression of the form

can be used for expressing the value of a variable

A linear polynomial is specified in MODELS as follows:

y:=sum(1|+0.3|x1-34.7|x2)

where

Minimum and maximum limits can be assigned to the value of the sum as follows:

The following are examples of sum terms:

1|+0.3|x1-34.7|x2 = 1 + 0.3*x - 34.7*x^2

____________________________________

References to the value of the first- and second-order time derivatives of an input or variable can be used in any expression of a model, by means of the functions deriv(x) and deriv2(x) (see residential functions). Alternately, a linear polynomial of the time derivatives can be used, of the form:

where D is the time derivative operator representing d/dt.

In MODELS, a derivative expression can be used for describing a linear polynomial of derivatives, as follows:

- where

- and where the polynomial is separated from the element to which it is applied by a vertical bar, the "applies to" operator of MODELS, with the meaning of "polynomial applied to x".

Minimum and maximum limit values can be assigned to a derivative polynomial as follows:

An expression is specified as a derivative expression when it is necessary to put in evidence the linearity of the expression with respect to the derivatives of x. It can be used as the right-hand side of any value assignment, but is required only in a COMBINE group of statements.

An example of a derivative polynomial is shown below, with its interpretation:

(

________________________________________

The time integral of any input or variable of a model is automatically calculated during the simulation whenever an integral expression is evaluated. The value of the integral of an element at a given time step is a cumulative value dependent on the previous value of the integral and on the present and previous value of the integrated element.

An integral expression is specified as follows:

where

Minimum and maximum limits can be assigned to the value of an integral as follows:

The limit applied to an integral is a "dynamic limit". While an external static limit would simply clip the value of the integral separately from the procedure by which it is calculated, a dynamic limit modifies the calculation procedure itself by recognizing that the past value used in a later calculation of the integral is the integral's limited value.

When more than one integral expressions affect the same element at a given time step of a simulation, the integral is re-evaluated each time it is used, to reflect possible changes in the value of the element to which it applies. Each new evaluation of the integral during the same time step also releases any previously-applied limit to that integral at that time step.

________________________________________

The value of an integral can be reset at any time of a simulation, using an integral value assignment. A single value can be assigned to the integral of a single element, of a single array element, or of a group of array elements sharing the same value, by using a single-value integral assignment as

integral(name):=expr

integral(x):=0, integral(x):=t*y+3/x

and an array of values can be assigned to the integral of a group of array elements, using an array-value integral assignment as follows:

integral ( name [ expr .. expr ] ) := array-value expr

integral(x[1..10]):=a[1..10]

Minimum and maximum limits can be attached to the value assigned to the integral, in the expression describing the value.

From the point where a reset value is assigned to an integral until the end of the execution of that model at that simulation time, the value of the integral becomes fixed, and is not influenced anymore by the value of the integrated variable.