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:

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

A base other than 10 (between 2 and 36) can be input by preceding the value with a two digit radix value followed by an r and then the value. For instance 200 in hex would be 16rc8, in octal 08r310 and in binary 02r11001000.

See the Expression help for information on output formats.

Conversion Units

A number can be followed by a conversion unit:

123.45 km/h

The unit must be separated from the number by a space and must only contain unit names and the operators -, / and ^. There can only be a single /. Thus the following are all valid;

123 m/s^2 ' an acceleration
123 kj ' energy
123 n-km ' also 123 kJ
123000 kg-m^2/s^2 ' also 123 kJ

If the unit is to be followed by one of the operators that can appear in a unit (-, / or ^) there must be white space separating the unit from the operator. Thus:

2 kg/3 h

would result in an unidentified unit error.

2 kg*3 h

would be legal, but it might be best to just always separate units from operators with a space. Note that both

2 m^3
2 m ^3

are legal, but the first results in 2 cubic metres, while the second yields 8 metres.

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:

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

would add their calculated values.

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.

These are discussed in more detail here.

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.

The index operator can also be used with model tools to produce arrays of tool reference as discussed here.

Comments

Comments can be added to the end of formula lines by using a hash "#" character, as in:

{if needConversion,
  a * conversion, # need conversion
  a # just return value
}

A single quote character which isn't the first character of the formula and isn't contained in quotes, will cause the entire rest of the formula to be considered a comment, even if there are multiple lines:

a + b ' this is
just a comment

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.

Note that the transpose function can be used to flip the display so the columns are viewed as rows. This just affects the display of the value, not how you reference it or how it operations of functions work on it.

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. There is also a list of functions and their descriptions here.