numbers.matrix

numbers.matrix.addition(M1, M2)

Add two matrices, M1 and M2, together.

Parameters

M1 : Array

First matrix.

M2 : Array

Second matrix.

Returns

M : Array

Addition of M1, M2.

Errors

An error is thrown if:

  • the dimensions of M1 and M2 do not match

numbers.matrix.affine(v, tx, ty)

Perform an affine transformation 2D vector, v, by factors tx and ty.

Parameters

v : Array

A 2D vector.

tx : Number

The x-factor.

ty : Number

The y-factor.

Returns

Vaff : Array

Affined v.

Errors

An error is thrown if:

  • v is not 2D (v.length !== 2)

numbers.matrix.deepCopy(M)

Create a deep copy of a matrix, M.

Parameters

M : Array

The matrix to copy.

Returns

Mnew : Array

Deep copy of M.

Errors

An error is thrown if:

  • M is not a matrix

numbers.matrix.determinant(M)

Calculates the determinant of a square matrix, M.

Parameters

M : Array

A square matrix.

Returns

num : Number

The determinant of M.

Errors

An error is thrown if:

  • M is not a square matrix

numbers.matrix.dotproduct(vA, vB)

Calculate the dot product of two vectors, vA and vB.

Parameters

vA : Array

First vector.

vB : Array

Second vector.

Returns

num : Array

Dot product of vA,vB.

Errors

An error is thrown if:

  • The dimensions of vA and vB are not the same (vA.length !== vB.length).

numbers.matrix.GaussJordanEliminate(M, eps)

Performs Gauss-Jordan elimination on the matrix M with an error bound of eps. eps is an optional argument.

Parameters

M : Array

A matrix.

eps : Number

The error bound.

Returns

Mnew : Array

The row-reduced version of M.

Errors

This function does not raise any errors.


numbers.matrix.getCol(M)

Gets the nth column of a matrix, M as a vector.

Parameters

M : Array

A matrix.

Returns

col : Array

nth column of M.

Errors

An error is thrown if:

  • n is less than zero
  • n is greater than or equal to the number of columns of M

numbers.matrix.identity(n)

Creates a n-by-n identity matrix.

Parameters

n : Int

The size of the identity matrix.

Returns

M : Array

Identity matrix of size n.

Errors

This function does not raise any errors.


numbers.matrix.inverse(M)

Calculates the inverse of a square matrix M.

Parameters

M : Array

A square matrix.

Returns

Mnew : Array

The inverse of M.

Errors

An error is thrown if:

  • M is not a square matrix.

numbers.matrix.isColumnDD(M)

Determines if a matrix, M, is (weak) column diagonally dominant.

Parameters

M : Array

The matrix to test.

Returns

bool : Boolean

true if M is column diagonally dominant, false otherwise.

Errors

An error is thrown if:

  • M is not a matrix.
  • M is not square.

numbers.matrix.isRowDD(M)

Determines if a matrix, M, is (weak) row diagonally dominant.

Parameters

M : Array

The matrix to test.

Returns

bool : Boolean

true if M is row diagonally dominant, false otherwise.

Errors

An error is thrown if:

  • M is not a matrix.
  • M is not square.

numbers.matrix.isSquare(M)

Determines if a matrix, M, is square.

Parameters

M : Array

The matrix to test.

Returns

bool : Boolean

true if M is square, false otherwise.

Errors

An error is thrown if:

  • M is not a matrix.

numbers.matrix.isStrictlyColumnDD(M)

Determines if a matrix, M, is strictly column diagonally dominant.

Parameters

M : Array

The matrix to test.

Returns

bool : Boolean

true if M is strictly column diagonally dominant, false otherwise.

Errors

An error is thrown if:

  • M is not a matrix.
  • M is not square.

numbers.matrix.isStrictlyRowDD(M)

Determines if a matrix, M, is strictly row diagonally dominant.

Parameters

M : Array

The matrix to test.

Returns

bool : Boolean

true if M is strictly row diagonally dominant, false otherwise.

Errors

An error is thrown if:

  • M is not a matrix.
  • M is not square.

numbers.matrix.lupDecomposition(M)

Calculates the LUP decomposition of a square matrix, M. An array containing the three matrices is returned.

Parameters

M : Array

A square matrix.

Returns

LUP : Array

An array containing L, U, P.

Errors

An error is thrown if:

  • M is not a square matrix.

numbers.matrix.map(M, f)

Applies a function, f, to every element in the matrix (or vector) M. f can only take one parameter.

Parameters

M : Array

A matrix or vector

f : Function

A one-parameter function.

Returns

Mmapped : Array

A copy of M, but with f applied to each element.

Errors

This function does not raise any errors.


numbers.matrix.multiply(M1, M2)

Multiply two matrices, M1 and M2, together.

Parameters

M1 : Array

First matrix.

M2 : Array

Second matrix.

Returns

M : Array

Multiplication of M1, M2.

Errors

An error is thrown if:

  • The number of rows of M1 and the number of columns of M2 do not match.

numbers.matrix.outer(vA, vB)

Calculate the outer product of two vectors, vA and vB.

Parameters

vA : Array

First vector.

vB : Array

Second vector.

Returns

M : Array

Outer product of vA,vB.

Errors

An error is thrown if:

  • The dimensions of vA and vB are not the same (vA.length !== vB.length).

numbers.matrix.reorderCols(M, L)

Reorders the columns of a matrix M as specified by a set of column indices, L.

Parameters

M : Array

The matrix to reorder.

L : Array

The set of column indices.

Returns

Mnew : Array

Reordered M.

Errors

An error is thrown if:

  • L is not defined
  • the number of columns in Mreorder will have a different number of columns as M (L.length !== M.length).
  • an element of L is less than zero or greater than or equal to the number of columns of M

numbers.matrix.reorderRows(M, L)

Reorders the rows of a matrix M as specified by a set of integers, L.

Parameters

M : Array

The matrix to reorder.

L : Array

The set of row indices.

Returns

Mnew : Array

Reordered M.

Errors

An error is thrown if:

  • L is not defined
  • the number of rows in Mreorder will have a different number of rows as M (L.length !== M.length).
  • an element of L is less than zero or greater than or equal to the number of rows of M

numbers.matrix.reverseCols(M)

Reverses the order the of columns of a matrix M.

Parameters

M : Array

The matrix to reverse.

Returns

Mnew : Array

Reversed M.

Errors

This function does not raise any errors.


numbers.matrix.reverseRows(M)

Reverses the order the of rows of a matrix M.

Parameters

M : Array

The matrix to reverse.

Returns

Mnew : Array

Reversed M.

Errors

This function does not raise any errors.


numbers.matrix.rotate(v, angle, dir)

Rotate a 2D vector, v, by angle degrees in a direction dir. dir is an optional argument.

Parameters

v : Array

A 2D vector.

angle : Number

An angle in degrees.

dir : String

A direction. Options are clockwise and counterclockwise. Default value is counterclockwise.

Returns

Vnew : Array

Rotated v.

Errors

An error is thrown if:

  • v is not 2D (v.length !== 2).

numbers.matrix.rowAddMultiple(M, fromRow, toRow, scale)

Add the multiple of a row, scale*fromRow, to another row, toRow, both of matrix M.

Parameters

M : Array

A matrix.

fromRow : Int

Row to be multiplied.

toRow : Int

Row to be added to.

scale : Number

Scaling factor.

Returns

Mnew : Array

Altered M.

Errors

This function does not raise any errors.


numbers.matrix.rowReduce(M, eps)

Row-reduces the matrix M with an error bound of eps. eps is an optional argument. Identical to matrix.GaussJordanElimination.

Parameters

M : Array

A matrix.

eps : Number

The error bound.

Returns

Mnew : Array

The row-reduced version of M.

Errors

This function does not raise any errors.


numbers.matrix.rowScale(M, row, k)

Scale row row of a matrix M by a factor k.

Parameters

M : Array

A matrix.

row : Int

The row number.

k : Number

Scaling factor.

Returns

Mnew : Array

Scaled M.

Errors

This function does not raise any errors.


numbers.matrix.rowSwitch(M, row1, row2)

Switch rows row1 and row2 of a matrix M with each other.

Parameters

M : Array

A matrix.

row1 : Int

First row number.

row2 : Int

Second row number.

Returns

Mnew : Array

Swapped M.

Errors

This function does not raise any errors.


numbers.matrix.scalar(M, a)

Multiply a matrix, M, by a scalar, a.

Parameters

M : Array

The matrix to multiply.

a : Number

The scalar value.

Returns

M : Array

Multiplication of a, M1.

Errors

This function does not raise any errors.


numbers.matrix.scale(v, x, y)

Scale a 2D vector, v, by scale factors x and y.

Parameters

v : Array

A 2D vector.

x : Number

The x-scaling.

y : Number

The y-scaling.

Returns

Vsca : Array

Scaled v.

Errors

An error is thrown if:

  • v is not 2D (v.length !== 2).

numbers.matrix.shear(v, k, dir)

Shear a 2D vector, v, by a shear factor k in a direction (x or y) dir.

Parameters

v : Array

A 2D vector.

k : Number

The shear factor.

dir : String

A direction. Options are 'xaxis' and 'yaxis'.

Returns

Vsh : Array

Sheared v.

Errors

An error is thrown if:

  • v is not 2D (v.length !== 2).

numbers.matrix.subtraction(M1, M2)

Subtract two matrices, M1 and M2, from one another.

Parameters

M1 : Array

First matrix.

M2 : Array

Second matrix.

Returns

M : Array

Subtraction of M2 from M1.

Errors

An error is thrown if:

  • the dimensions of M1 and M2 do not match

numbers.matrix.trace(M)

Calculates the trace of a square matrix, M.

Parameters

M : Array

A square matrix.

Returns

tr : Number

The trace of M.

Errors

An error is thrown if:

  • M is not a square matrix.

numbers.matrix.zeros(n, m)

Creates a n-by-m matrix filled with zeros.

Parameters

n : Int

Number of rows.

m : Int

Number of columns.

Returns

M : Array

A matrix of zeros.

Errors

An error is thrown if:

  • Either matrix dimension is less than 1.

numbers.matrix.zigzag(n, point, dir)

Creates a n-by-n zigzag matrix starting at a corner, point, and moving in an initial direction dir.

Parameters

n : Int

Dimension of zigzag matrix.

point : String

Corner to start at. Options are top-left ('TR'), top-right ('TR'), bottom-left ('BL') and bottom-right ('BR').

dir : String

Direction to start iterating. Options are vertical ('v') or horizontal ('H').

Returns

M : Array

A zigzag matrix.

Errors

An error is thrown if:

  • Matrix dimension is less than 2.