Overview

All Math Minion calculations are defined by formulas. These can be as simple as a scalar constant or can be a complex multiline expressions involving matrices and functions.

Every formula evaluates to a minion value.

Numbers

Numbers can be entered in either normal or scientific notation. For example:

• 123.45
• 1.2345e2
• -0.00012345
• -1.2345e-4

Complex numbers can be created and manipulated using the techniques described on the complex number page.

Conversion Units

A number can be followed by a conversion unit:

123.45 km

If the formula consists of more than just number and a unit and the unit contains a -, / or ^ symbol, then the unit must be in double quotes.

Not Okay

123.45 km/h * 12 min

Okay

123.45 "km/h" * 12 min
123.45 km / 12 min
123.45 km/h

When you are editing a formula, you can request a unit browser to help you select a conversion unit. See the formula editor page for details and see the units page for more information on using units.

Operators

The binary operators are:

• - Minus
• * Multiply
• / Divide
• ^ Power
• % Modulus
• : Range (see the Indices section below)

The precedence is (from higher to lower):

1. unary minus (i.e. -3)
2. :
3. ^
4. * / %
5. + -

Parenthesis can be used as required to specify the calculation order:

(2 + 3) * 4

Array Operations

When operators are used with arrays or matrices, the result will be a matrix with a number of columns equal to the larger of the number of columns of the operands and the number of rows equal to the larger of the number of rows of the operands. Thus adding a 2x8 matrix to a 4x3 matrix will result that is 4x8.

Each result cell is calculated by performing the arithmetic operation on the cells of the operands with indices corresponding to that of the result cell. If either of these indices would be too large for the operand, the modulus of its value with respect to the maximum size is used.

In effect this means the smaller operand's values are reused in order as needed.

Tool references

The names of other tools in the same model can be used in a formula to reference their calculated values. In the simplest case, if a model had an expression named first and another named second then the formula:

first + second

Tools other than expressions, matrices and data tables don't have single calculated results, but rather a number of parameters that can be accessed by separating the parameter name from the tool name with a dot:

graph.maxx

In addition to checking the help pages for the specific type of tool when you are editing a formula, you can see what parameters are available for a tool by using the value browser. See the formula editor page for details.

The symbol \$ can be used as a proxy for the name of the tool containing the formula. Thus a minimum X formula in a graph could be:

\$.maxx - 100

If the formula for an expression consists solely of the name of a tool and it isn't an expression, matrix or data table, then that expression becomes a reference for the named tool and the expression can be used in formulas as if it were the referenced tool.

This is mainly used in input and output expressions to pass entire tools into or out of models.

Indices

Specific elements or subranges of Math Minion values can be accessed with the square bracket index operator. For example:

a[2,3]

would result in the value in the second row and third column of the "a" value. (Recall that all Math Minion numeric and string values are matrices and scalars are just 1x1 matrices).

If only a single index is supplied, then the entire row corresponding to that index is returned.

If an array of values is supplied as one of the indices, then the result will be an array of values that are chosen from the indexed object according to the values in the index array. Either or both indices can be arrays.

The range operator : can be used to generate an array of integers that starts with the first operand and increments by one up to the second operand. Thus:

2:4

would produce an array with the elements 2, 3 and 4. The range operator can also work backwards, such that:

5:2

would produce an array with elements 5,4,3,2.

Range operators are handy to use for producing subsets of a matrix:

a[ 2:4, 3:9 ]

would produce a 3x7 matrix with the elements of a's rows 2 through 4 and columns 3 through 9. A more complicated example:

Finally a row index of 0 can be used to select all rows, if also used with a column index. Thus:

x[0, 2]

would produce a column array equivalent to column 2 of x.

Anything in a formula following a single quote character is considered a comment:

a + b ' this is just a comment

If the formula has new line characters in it, the comment must still be at the end of the formula. In other words you cannot have a comment on each line of a single formula. The comment itself can have multiple lines though.

Strings

A string scalar is simply some text enclosed in double quote marks:

"This is a string"

The string can also contain newline characters.

Like numbers, string variables are always matrices and can have an arbitrary number of rows and columns. You cannot mix numbers and strings in a single variable, although table values (see below) can have both numeric and string columns.

If the entire formula is a comment, that is it starts with a single quote, then everything after that quote will be considered a single string value.

Strings can be added using the plus sign, which will concatenate the elements. You can also multiply a string by a number, which will cause the string to be repeated that number of times in the result.

See the string functions in the function browser for operations that can be performed on strings.

Table Values

The data table tool, as well as some functions and parameters of other tools, return table values. These can be thought of as a collection of column arrays, all with the same number of rows, but with possibly differing column value types.

The index operator will work on table values in the same manner as with matrices and can also accept a string scalar or array of column names as the column index.

The arithmetic operators also work with table values, as long as there are no unit conflicts. The result will itself be a table value, unless the operation is between a table value and a number value which has more than one column, in which case an attempt will be made to convert the table to a number value.

There are a number of functions that allow for creating, selecting and manipulating table data. See the function browser for details.

Functions

Math Minion has a number of mathematical and utility functions available. Functions are always enclosed in curly braces, with the function name immediately following the opening brace and any parameters following as a comma separated list. Some examples might be:

{sin a}

{max a, b}

{if test, a, b}

When you are editing a formula, you can request a function browser to help you select a function. The functions are listed below, but for details use the function browser.

• exp
• ln
• log

• sin
• cos
• tan
• asin
• acos
• atan
• pi
• polar
• cart

• sinh
• cosh
• tanh
• asinh
• acosh
• atanh

• complex
• cmult
• cdiv
• cpow
• cabs
• cexp
• cln
• csin
• ccos
• ctan
• casin
• cacos
• catan
• csinh
• ccosh
• ctanh
• casinh
• cacosh
• catanh

• min
• minrows
• mincols
• max
• maxrows
• maxcols
• sum
• sumrows
• sumcols

• if
• eq
• ne
• lt
• le
• gt
• ge
• not
• and
• or

• append
• array
• cc
• concat
• cell
• col
• cross
• dot
• eigval
• eigvect
• invert
• ncols
• nrows
• row
• redim
• tr
• transpose

• average
• median
• geomean
• harmmean
• var
• factorial
• lngamma
• permut
• combin
• normdist
• norminv
• binomdist
• chidist
• chitest
• ttest
• tptest

• table
• colnames
• groupsum
• groupmin
• groupmax

• lookup
• indexof
• select

• fmt
• join
• split
• match
• replace
• strfind
• strlen
• substr
• lowercase
• uppercase
• utf8

• mktime
• date
• now
• timezone

• pitch
• roll
• yaw
• scale
• translate
• transform

• abs