ifference between revisions of "EMK:Formulae and Functions"
Line 81: | Line 81: | ||
| Avg || Average value of numbers in an array || Value Array (Exclude Value), Integer or Real || Real || Avg(Generator.Generation) || | | Avg || Average value of numbers in an array || Value Array (Exclude Value), Integer or Real || Real || Avg(Generator.Generation) || | ||
|- | |- | ||
− | | WgtAvg || Average of numbers in an array, weighted by numbers in another array || Value Array (Weights Array), Integer or Real || Real || WgtAvg(Generator.Generation,Generator.Cost) | + | | WgtAvg || Average of numbers in an array, weighted by numbers in another array || Value Array (Weights Array), Integer or Real || Real || WgtAvg(Generator.Generation,Generator.Cost) || |
|- | |- | ||
| Choke || Returns a collared value (i.e. the value of the referenced variable is returned if it falls within the specified range otherwise the relevant minimum or maximum value is returned) || Number, Integer or Real || Real || Choke(500,200,Generator.Generation)|| | | Choke || Returns a collared value (i.e. the value of the referenced variable is returned if it falls within the specified range otherwise the relevant minimum or maximum value is returned) || Number, Integer or Real || Real || Choke(500,200,Generator.Generation)|| |
Revision as of 09:07, 21 November 2012
Formulae can be entered as substitutes for specific values into most fields in EMarket to control the derivation of variable values at run time. A formula can contain any combination of:
- Constants
- Variables
- Operators
- Entities and Traits
- Functions
Constants
Constants can be:
- Numbers: Integers or Reals (e.g. 1, 2.5, -3), they can also be entered in scientific notation e.g. '3E+10'.
- Strings: Written inside double quotes e.g. "A Node"
- Dates: Must be enclosed in single quotes e.g '1/3/2004' or '14 April 2005'
Warning: The format for entering dates should compatible with the computer's local date (locality) setting
Variables
Variables can be regarded as user-defined Entity.Traits which can be defined in the Volatility Matrix or the Schedule. Previously defined variables can be used in formulae.
Note: EMarket provides a 'system' variable the user need not define: 'DateTime' which is of type 'Date' and gives the current simulation date as the model runs.
Operators
Operators are all pre-defined in EMarket. Their purpose is to separate a formula into parts that are then combined to give a single value.
The following operators are shown in descending order of precedence.
Operator | Meaning | Example | Parameter Type | Return Type |
---|---|---|---|---|
\ | Integer Division | 3\2 = 1 | Real; Int | Int |
% | Modulus | 7%5 = 2 | Real; Int | Int |
/ | Division | 3/2 = 1.5 | Real; Int | Real |
* | Multiplication | 5*4.2 = 21 | Real; Int | Real |
- | Subtraction | 7-3.2 = 3.8 | Real; Int | Real |
+ | Addition | 3.5+1.5 = 5 | Real; Int | Real |
Functions
Functions provide a powerful mechanism for deriving field and variable data values from input parameters.
A function has the form FunctionName(Parameter1, Parameter2, ...)
An operator is used in a Function in the following form: <Parameter1>Operator<Parameter2>.
EMarket provides the following function types:
- Arithmetic functions
- Logic functions
- Run information functions
- Time functions
- Other functions
Note: Logic operators and functions evaluate to one for a result that is true (for example 6 = 6), and zero for false.
Arithmetic Functions
The following table lists EMarket's Arithmetic functions:
Function | Purpose | Parameters (Description, Type) | Return Type | Example | Result |
---|---|---|---|---|---|
Sqrt | Square root of a number | Number, Integer or Real | Real | Sqrt(546.94) | 23.387 |
Abs | Absolute value of a number | Number, Integer or Real | Real | Abs(-19.1) | 19.1 |
Int | Integer portion of a number | Number, Integer or Real | Integer | Int(45.786) | 45 |
Sum | Total value of numbers in an array | Value Array (Exclude Value), Integer or Real | Real | Sum(Node.Price) | |
Max | Maximum value of numbers in an array, optionally excluding values with value over an exclude value | Value Array (Exclude Value), Integer or Real | Real | Max(Generator.Generation) | |
Min | Minimum value of numbers in an array | Value Array (Exclude Value), Integer or Real | Real | Min(Generator.Generation) | |
StdDev | Standard deviation of numbers in an array | Value Array (Exclude Value), Integer or Real | Real | StdDev(Generator.Generation) | |
Avg | Average value of numbers in an array | Value Array (Exclude Value), Integer or Real | Real | Avg(Generator.Generation) | |
WgtAvg | Average of numbers in an array, weighted by numbers in another array | Value Array (Weights Array), Integer or Real | Real | WgtAvg(Generator.Generation,Generator.Cost) | |
Choke | Returns a collared value (i.e. the value of the referenced variable is returned if it falls within the specified range otherwise the relevant minimum or maximum value is returned) | Number, Integer or Real | Real | Choke(500,200,Generator.Generation) |