This project is read-only.


A matrix object stores a rectangular table of floating point values. It also allows to perform various linear algebra operations.

Matrix literal

You can create a new matrix object by using the matrix literal:
var matr =
1 2 3
4 5 6
7 8 9

The literal defines several rules:
  • Each line in the matrix must contain the same number of items
  • Matrix literals can contain only values, variables and fields with an optional prefix minus sign. All other expressions must be surrounded by parens.
  • Empty lines and spaces are ignored and can be used to make the literal more readable
  • Matrix literals, being a 2D structure, cannot be used in expressions. They must be assigned to a variable first.


Matrices can be subject to the following operations:
  • Addition and subtraction with another matrix
  • Multiplication by a number
  • Multiplication by another matrix (their dimensions must satisfy the rules of matrix multiplication.
  • Raising to integer power (square matrices only)


  • void construct(int size): create a square zero-filled matrix
  • void construct(int width, int height): create a rectangular zero-filled matrix
  • void construct(int width, int height, float value): create a rectangular matrix filled with given number
  • matrix invert: inverts the matrix
  • matrix trans: transposes the matrix
  • float det: gets the matrix determinant
  • int rank: gets the matrix rank
  • matrix piece(int x, int y, int width, int height): gets a submatrix
  • matrix conj: gets a conjugate transpose of the matrix
  • float frob: gets the matrix Frobenius norm
  • float l1: gets the L1 norm of the matrix
  • float l2: gets the L2 norm of the matrix
  • float[] row(int id): gets a row
  • float[] col(int id): gets a column
  • void set_col(int index, float[] values): replaces a matrix column with given values
  • void set_row(int index, float[] values): replaces a matrix row with given values
  • matrix[2] lu: performs LU factorization
  • matrix[2] qr: performs QR factorization
  • matrix chol: performs Cholesky factorization
  • float[] flatten: pushes all matrix items into an array

The type also contains several static methods:
  • matrix identity(int size): makes an identity matrix of the given size
  • matrix pascal(int size): makes a matrix out of Pascal's triangle values
  • matrix inflate(float[] values, int width): creates a matrix from an array of values, given the matrix width

Last edited Mar 16, 2011 at 10:32 PM by impworks, version 3


No comments yet.