Matrix functions

Multiply, invert and measure grids of numbers.

Syntax

Write a grid as a list of rows, each row a list of numbers: [[1, 2], [3, 4]]. A grid is also what another matrix function returns, so the calls nest.

MMULT(matrix1, matrix2)
MINVERSE(matrix)
MDETERM(matrix)
MUNIT(dimension)
RANDARRAY([rows], [columns], [min], [max], [whole_number])

Parameters and arguments

Arguments are written in brackets, separated by commas. An argument in square brackets is optional.

  • MMULT

    matrix1

    Required: Yes
  • matrix2

    Required: Yes
  • MINVERSE

    matrix

    Required: Yes
  • MDETERM

    matrix

    Required: Yes
  • MUNIT

    dimension

    Required: Yes
  • RANDARRAY

    rows

    Required: No
  • columns

    Required: No
  • min

    Required: No
  • max

    Required: No
  • whole_number

    Required: No

Examples

Two products use two materials in different amounts, and each material has a price. One multiplication gives the material cost of each product, and a second shows how two grids combine.

Return type and behaviour

Each function returns one value. The table shows its type, what it does and one way to write it; the examples use the functions in realistic statements.

FunctionReturnsBehaviourForm
MMULTgridThe product of the two gridsMMULT([[1, 2], [3, 4]], [[1], [1]])
MINVERSEgridThe inverse grid. A grid that has no inverse is refused with HTQL-2002MINVERSE([[2, 1], [1, 3]])
MDETERMdecimalThe determinant. A grid that is not square is refused with HTQL-8004MDETERM([[2, 1], [1, 3]])
MUNITgridThe identity grid: 1 on the diagonal and 0 elsewhereMUNIT(3)
RANDARRAYgridA grid of random numbers. A new grid on each callRANDARRAY(2, 3)
Errors and exceptions
ErrorWhat happenedHow to recover
HTQL-5001The function was given the wrong number of arguments. The message names the function and the countsGive it the arguments listed under Parameters
HTQL-1004 Unsupported functionThe name is not a function this engine runsCheck the name and its spelling against this entry
HTQL-2002MMULT was given grids whose sizes do not fit, or MINVERSE a grid that is not square or has no inverseCheck the sizes, and the determinant first
HTQL-8004MDETERM was given a grid that is not square or is empty (#NUM!)Pass a square grid
HTQL-8003MUNIT was given a dimension below 1 (#VALUE!)Pass 1 or more
Limitations
  • MMULT needs the first grid's columns to equal the second grid's rows; otherwise it is refused with HTQL-2002.
  • A flat list such as [1, 2, 3] is read as one row.
  • Every row of a grid must have the same length, and every entry must be a number.
  • Keep min below max in RANDARRAY.
Permissions and security

These functions read nothing from your tables and write nothing.

When a function is applied to a column or a variable, the statement that reads the data needs read access, as its own entry says.

Best practices
  • Check MDETERM before MINVERSE: a determinant of zero means there is no inverse.
  • Use MMULT to apply a grid of rates or usages to a column of prices or quantities in one call.