The Formula block can evaluate an expression based on state or model information. You create variables (called input variables) to be used in the expression, and you formulate them into an expression that is evaluated every time a value is pulled from the Formula block’s OutValue port. The expression is also evaluated and pushed out the Formula block’s OutValue port every time input is pushed into one of the Formula block’s input value ports. The value that is associated with an input variable can come either from an entity attribute or from an input value port. If the source for an input variable is designated to be a port, an input value port is created on the block and is associated with the appropriate input variable. Whenever a value is requested from a Formula block or new input arrives at a Formula block, the Formula block first determines which values that are associated with its input variables need to be acquired (based on the setting for the To Acquire Port Values Only When Needed properties dialog box option) and then attempts to evaluate its expression. The result of this evaluation leaves through the OutValue port.
You use the Expression text box to enter the expression to be evaluated in the Formula block. Appendix F: Expressions. contains a complete list of available expressions. You define variables that are used in the expression in the Input Variables Table. The operators available for building expressions include Boolean (&&, ||, !), arithmetic (+, -, *, /, %), and comparison (<, >, , , ==, !=) operators. Available functions include arithmetic (abs), trigonometric (sin, cos, tan, asin, acos, atan, sinh, cosh, tanh), and logarithmic (exp, log, ln) functions, along with floor, ceil, round, min, max, and power functions. The min and max functions can be called with any number of numeric arguments. In addition, you can use the conversion functions degrees and radians to convert between degrees and radians. You can use the concat function to concatenate strings. Two logical functions, cond and switch, are also provided. The format for the cond function is cond(Boolean expression, true return value, false return value). The value returned by this function is determined by evaluating its Boolean expression. The format for the switch function is switch(Boolean expression1, value1, Boolean expression2, value2, ..., default value). The value returned by the switch function is the value that follows the first Boolean expression that evaluates to true. The default value is returned if none of the Boolean expressions is true. You can also use the minindex and maxindex functions, which return the zero-based index of the minimum (or maximum) value in the list of values passed into the function.
The Formula block also supports a dot (.) operator. When you use an input variable of type Observation, you can use the dot
operator to access the values of the observation’s member variables. For example, suppose an observation input variable named
Record
has member variables Name
and GPA
(so that the observation Record
is a row from a data set with columns Name
and GPA
). The expression Record.Name
returns the value of Name
for the current observation. Similarly, the following expression returns a string that depends on the value of GPA
: cond(Record.GPA
< 60.0, "Fail", "Pass").
Adds a new input variable with a default Name, Type, and Source to the Input Variables table. You can edit the Name, Type, and Source of the variable directly in the table. The variable names listed in the Formula block’s Input Variables table must be unique. You can change the Type through a drop-down box on the cell in the table. A variable Type cannot be changed in the table after the Apply button is clicked. If you want to change a variable Type after Apply has been clicked, you must remove the variable, add it again, and then modify the Type of the newly added variable before clicking Apply again.
Deletes the selected variable from the Input Variables table.
If this option is turned off, the Formula block always acquires values for all of its input variables. If this option is turned on, the Formula block acquires only the values for its input variables that are required in order to determine the result of the expression.
Contains the expression to be evaluated in the Formula block. Any variables used in the expression must be defined in the Input Variables table. Appendix F: Expressions. contains a complete list of available expressions.
Identifies the value type that results from evaluating the expression. The selected option specifies the output port type for the Formula block.
Validates the expression and saves the input variables, the expression, and the expression result. Input value ports are created or deleted and the type of the output value port is set as needed.