Mathematical builtins

The mathematical builtins perform mathematical operations on their input expressions, generating a result. Most commonly, you will use the mathematical functions to define converters which form the micro-logic of your model. Mathematical functions do a wide variety of operations, as detailed below.

This section describes the following builtins:

ABS(<expression>)

The ABS builtin returns the absolute value of expression. The expression value can be either a variable or a constant.

Example:

ABS(-1) equals 1

DERIVN(<input>, <order>)

The DERIVN builtin calculates the nth-order time derivative of input. The input value can be either a variable or a constant. order must be a non-negative integer. The software uses a recursive finite difference technique to calculate time derivatives. The basic equation used in the calculation is:

dx/dt = (xt - x(t-dt))/dt

where t is current simulation time, and dt is DT, the simulation solution interval.

Because the DERIVN builtin uses previous values of input for its calculations, the builtin return an initial value of 0.

Calculus cognoscenti will note that it is possible to use the chain rule to calculate dy/dx, where y and x are time-dependent model variables. Use this formula:

dy/dx = dy/dt ÷ dx/dt

Examples:

DERIVN(1,0) equals 1 (the zeroth-order derivative)

DERIVN(1,1) equals 0 (the first-order derivative)

DERIVN(SINWAVE(1,1),3) calculates the third-order derivative of a sine wave with period of 1 and amplitude of 1.

EXP(<expression>)

The EXP builtin gives e raised to the power of expression. The expression value can be either a variable or a constant. The base of the natural logarithm, e is also known as Euler's number. e is equal to 2.7182818... EXP is the inverse of the LN builtin (natural logarithm). To calculate powers of other bases, use the exponentiation operator (^).

Examples:

EXP(1) equals 2.7182818 (the value of Euler's constant)

EXP(LOGN(3)) equals 3

2^3 equals 8 (2 raised to the third power)

INT(<expression>)

The INT builtin gives the largest integer less than or equal to expression. The expression value can be either a variable or a constant.

Because of the internal calculations associated with the Runge-Kutta methods, the INT function does not always return integer values when you use the 2nd- or 4th-order Runge-Kutta computation methods. When your model constructs rely on the INT function, be sure to use Euler's method.

Examples:

INT(8.9) equals

INT(-8.9) equals -9

LN(<expression>)

The LN builtin calculates the natural logarithm of expression. The expression value can be either a variable or a constant. Natural logarithms use Euler's constant e, 2.7182818..., as a base. For LN to have meaningful results, expression must be positive. LN is the inverse of the EXP function, e raised to the power of expression.

Examples:

LN(2.7182818) equals 1

LN(EXP(3)) equals 3

LN(8)/LN(2) equals 3 (the base 2 logarithm of 8)

LN(-10) returns ? (undefined for non-positive numbers)

LOG10(<expression>)

The LOG10 builtin gives the base 10 logarithm of expression. The expression value can be either a variable or a constant. For LOG10 to be meaningful, expression must evaluate to a positive value. LOG10 is the inverse of the letter E in scientific notation, or base 10 exponentiation (10 raised to the power of expression).

Examples:

LOG10(10) equals 1

LOG10(1E5) equals 5

LOG10(8)/LOG10(2) equals 3 (the base 2 logarithm of 8)

LOG10(-10) returns ? (undefined for non-positive numbers)

MAX(<array or expression>, [<array or expression>])

The MAX builtin gives the maximum value among the arrayed entities or expressions contained within parentheses.

Because of the internal calculations associated with the Runge-Kutta methods, the MAX builtin does not always return the expected value when you use the 2nd- or 4th-order Runge-Kutta computation methods, and your inputs to the MAX calculation are variables. When your model constructs rely on the MAX builtin , be sure to use Euler's method.

Example:

Purchases = MAX(0,Desired_Purchases) returns the larger value among Desired Purchases and 0. In this example, the MAX function will prevent Purchases from taking on negative values.

To report the maximum value across a subset of the dimensions of an arrayed input entity, specify an asterisk (*) to include all of the elements across a dimension.

Example:

Maximum Value for Salary = MAX(Salaries[*,*])

MIN(<array or expression>, [<array or expression>])

The MIN builtin gives the minimum value among the arrayed entities or expressions contained within parentheses.

Because of the internal calculations associated with the Runge-Kutta methods, the MIN function will not always return the expected value when you use the 2nd- or 4th-order Runge-Kutta computation methods, and your inputs to the MIN calculation are variables. When your model constructs rely on the MIN builtin, be sure to use Euler's method.

Example:

Spending = MIN(Desired_Spending,Allowable_Spending) returns the smaller value among Desired Spending and Allowable Spending.

To report the minimum value across a subset of the dimensions of an arrayed input entity, select specify an asterisk (*) to include all of the elements across a dimension.

Example:

Minimum Value for Salary = MIN(Salaries[*,*])

MOD

The MOD builtin calculates the remainder.

Examples:

x MOD y equals the remainder when the value of x is divided by the value of y

5 MOD 3 equals 2

PERCENT(<fraction>)

The PERCENT builtin gives the value of fraction, expressed as a percentage. The fraction value can be either a variable or a constant.

Examples:

PERCENT(.65) equals 65

PERCENT(1.22) equals 122

PI

The PI builtin gives the number 3.14159..., an approximation of the constant p.

Example:

10*SIN(2*p*TIME/12)

generates a sinusoidal fluctuation with an amplitude of 10 and a period of 12. See also SIN and COS (see Trigonometric builtins).

ROUND(<expression>)

The ROUND builtin rounds expression to its nearest integer value.

Because of the internal calculations associated with the Runge-Kutta methods, the ROUND builtin does not always return integer values when you use the 2nd- or 4th-order Runge-Kutta computation methods. When your model constructs rely on the ROUND builtin, be sure to use Euler's method.

Examples:

ROUND(9.4) equals 9

ROUND(9.64) equals 10

SAFEDIV(<numerator>, <denominator>, [<onzero>])

The SAFEDIV builtin allows you to divide two things without first checking that the denominator in the expression is nonzero. It returns numerator/denominator as long as result of that computation is allowed and finite. If denominator is 0, or extremely close to 0, it will return 0 or, if onzero has been specified then onzero. SAFEDIV can be used to prevent divide by zero messages stopping the simulation and to allow other model values to be computed reasonably.

Examples:

SAFEDIV(10,5) returns 2

SAFEDIV(1,0) return 0

SAVEDIV(1,1E-150,1E9) return 1E150

SAFEDIV(1E150,1E-150,1E9) return 1E9

SQRT(<expression>)

The SQRT builtin gives the square root of expression. The expression value can be either a variable or a constant. For meaningful results, expression must be greater than or equal to 0.

Examples:

SQRT(144) returns 12

SQRT(-242) returns ? (undefined for negative numbers)

Concept Link IconSee Also