# Mathematical Functions

### ABS
DERIVN
EXP
INT
LOG10
LOGN
MAX
MEAN
MIN
MOD
PCT
PI
ROUND
SQRT
SUM

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.

#####
ABS(<expression>)

The ABS function returns the absolute value of expression. Expression can be variable or constant.

Example:

ABS(-1) equals 1

#####
DERIVN(<input>,< order>)

The DERIVN function calculates the nth-order time derivative of input. Input can be variable or 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 function uses previous values of input for its calculations, the function will 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. Simply use the 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 function gives e raised to the power of expression. Expression can be variable or 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 LOGN function (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 function gives the largest integer less than or equal to expression. Expression can be variable or constant.

Because of the internal calculations associated with the Runge-Kutta methods, the INT function will 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 8

INT(-8.9) equals -9

#####
LOG10(<expression>)

The LOG10 function gives the base 10 logarithm of expression. Expression can be variable or 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)

#####
LOGN(<expression>)

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

Examples:

LOGN(2.7182818) equals 1

LOGN(EXP(3)) equals 3

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

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

#####
MAX(<expression>,<expression>,...)

The MAX function gives the maximum value among the expressions contained within parentheses.

Because of the internal calculations associated with the Runge-Kutta methods, the MAX 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 MAX calculation are variables. When your model constructs rely on the MAX function, 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.

#####
MEAN(<expression>,<expression>,...)

The MEAN function returns the arithmetic mean of the expressions contained within parentheses. The expressions can be numbers or model variables.

Examples:

MEAN(1,1,1,1,1,1,1) equals 1

MEAN(1,2,3,4,5,6,7,8,9) equals 5

#####
MIN(<expression>,<expression>,...)

The MIN function gives the minimum value among the 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 function, be sure to use Euler's method.

Example:

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

#####
MOD(<expression>,<modulus>)

The MOD function computes the remainder (modulo) when expression is divided by the modulus.

Examples:

Excess_Components=MOD(Components,components_per_machine) calculates the number of components that will remain in inventory after machines have been assembled.

Time_of_Day=MOD(TIME,24) converts simulation time (in hours) to a 24-hour metric of time. Each 24 hours of simulation time, Time of Day will reset itself to 0. See the COUNTER Builtin for a more generalized way to create a cyclical clock based on simulation time.

#####
PCT(<fraction>)

The PCT function gives the value of fraction, expressed as a percentage. Fraction can be variable or constant.

Examples:

PCT(.65) equals 65

PCT(1.22) equals 122

#####
PI

The PI function gives the number 3.14159..., an approximation of the constant pi.

Example:

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

generates a sinusoidal fluctuation with an amplitude of 10 and a period of 12. See also SIN and COS.

#####
ROUND(<expression>)

The ROUND function rounds expression to its nearest integer value.

Because of the internal calculations associated with the Runge-Kutta methods, the ROUND function will 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 function, be sure to use Euler's method.

Examples:

ROUND(9.4) equals 9

ROUND(9.64) equals 10

#####
SQRT(<expression>)

The SQRT function gives the square root of expression. Expression can be variable or 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)

#####
SUM(<expression>,<expression>,...)

The SUM function returns the arithmetic summation of the expressions contained within parentheses.

Examples:

SUM(1,2,3,4,5,6,7,8,9) equals 45

SUM(a,b,c,d,e,f) equals (a+b+c+d+e+f)