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
Required: Yesmatrix1
Required: Yesmatrix2MINVERSE
Required: YesmatrixMDETERM
Required: YesmatrixMUNIT
Required: YesdimensionRANDARRAY
Required: Norows
Required: Nocolumns
Required: Nomin
Required: Nomax
Required: Nowhole_number
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.
| Function | Returns | Behaviour | Form |
|---|---|---|---|
MMULT | grid | The product of the two grids | MMULT([[1, 2], [3, 4]], [[1], [1]]) |
MINVERSE | grid | The inverse grid. A grid that has no inverse is refused with HTQL-2002 | MINVERSE([[2, 1], [1, 3]]) |
MDETERM | decimal | The determinant. A grid that is not square is refused with HTQL-8004 | MDETERM([[2, 1], [1, 3]]) |
MUNIT | grid | The identity grid: 1 on the diagonal and 0 elsewhere | MUNIT(3) |
RANDARRAY | grid | A grid of random numbers. A new grid on each call | RANDARRAY(2, 3) |
Errors and exceptions
| Error | What happened | How to recover |
|---|---|---|
HTQL-5001 | The function was given the wrong number of arguments. The message names the function and the counts | Give it the arguments listed under Parameters |
HTQL-1004 Unsupported function | The name is not a function this engine runs | Check the name and its spelling against this entry |
HTQL-2002 | MMULT was given grids whose sizes do not fit, or MINVERSE a grid that is not square or has no inverse | Check the sizes, and the determinant first |
HTQL-8004 | MDETERM was given a grid that is not square or is empty (#NUM!) | Pass a square grid |
HTQL-8003 | MUNIT was given a dimension below 1 (#VALUE!) | Pass 1 or more |
Limitations
MMULTneeds the first grid's columns to equal the second grid's rows; otherwise it is refused withHTQL-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
minbelowmaxinRANDARRAY.
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.