math.Matrix Extends
Class for representing and manipulating matrices. The entry that lies in the i-th row and the j-th column of a matrix is typically referred to as the i,j entry of the matrix. The m-by-n matrix A would have its entries referred to as: [ a0,0 a0,1 a0,2 ... a0,j ... a0,n ] [ a1,0 a1,1 a1,2 ... a1,j ... a1,n ] [ a2,0 a2,1 a2,2 ... a2,j ... a2,n ] [ . . . . . ] [ . . . . . ] [ . . . . . ] [ ai,0 ai,1 ai,2 ... ai,j ... ai,n ] [ . . . . . ] [ . . . . . ] [ . . . . . ] [ am,0 am,1 am,2 ... am,j ... am,n ]

Inheritance

Constructor

goog.math.Matrix(mopt_n)

Parameters

m : goog.math.Matrix | Array.<Array.<number>> | goog.math.Size | number
A matrix to copy, a 2D-array to take as a template, a size object for dimensions, or the number of rows.
opt_n : number=
Number of columns of the matrix (only applicable if the first argument is also numeric).

Instance Methods

Public Protected Private
add(m) !goog.math.Matrix
Returns a new matrix that is the sum of this and the provided matrix.
Arguments:
m : goog.math.Matrix
The matrix to add to this one.
Returns: !goog.math.Matrix  Resultant sum.
code »
appendColumns(m) !goog.math.Matrix
Appends the given matrix to the right side of this matrix.
Arguments:
m : goog.math.Matrix
The matrix to augment this matrix with.
Returns: !goog.math.Matrix  A new matrix with additional columns on the right.
code »
appendRows(m) !goog.math.Matrix
Appends the given matrix to the bottom of this matrix.
Arguments:
m : goog.math.Matrix
The matrix to augment this matrix with.
Returns: !goog.math.Matrix  A new matrix with added columns on the bottom.
code »
equals(mopt_tolerance) boolean
Returns whether the given matrix equals this matrix.
Arguments:
m : goog.math.Matrix
The matrix to compare to this one.
opt_tolerance : number=
The tolerance when comparing array entries.
Returns: boolean  Whether the given matrix equals this matrix.
code »
getCofactor_(ij) number
Returns the signed minor.
Arguments:
i : number
The row index.
j : number
The column index.
Returns: number  The cofactor C[i,j] of this matrix.
code »
getDeterminant() number
Returns the determinant of this matrix. The determinant of a matrix A is often denoted as |A| and can only be applied to a square matrix.
Returns: number  The determinant of this matrix.
code »
getDeterminant_() number
Returns the determinant of this matrix. The determinant of a matrix A is often denoted as |A| and can only be applied to a square matrix. Same as public method but without validation. Implemented using Laplace's formula.
Returns: number  The determinant of this matrix.
code »
getInverse() goog.math.Matrix
Returns the inverse of this matrix if it exists or null if the matrix is not invertible.
Returns: goog.math.Matrix  A new matrix which is the inverse of this matrix.
code »
getMinor_(ij) number
Returns the determinant of the submatrix resulting from the deletion of row i and column j.
Arguments:
i : number
The row to delete.
j : number
The column to delete.
Returns: number  The first minor M[i,j] of this matrix.
code »
getReducedRowEchelonForm() !goog.math.Matrix
Transforms this matrix into reduced row echelon form.
Returns: !goog.math.Matrix  A new matrix reduced row echelon form.
code »
getSize() !goog.math.Size
No description.
Returns: !goog.math.Size  The dimensions of the matrix.
code »
getSubmatrixByCoordinates_(i1j1opt_i2opt_j2) !goog.math.Matrix
Returns a submatrix contained within this matrix.
Arguments:
i1 : number
The upper row index.
j1 : number
The left column index.
opt_i2 : number=
The lower row index.
opt_j2 : number=
The right column index.
Returns: !goog.math.Matrix  The submatrix contained within the given bounds.
code »
getSubmatrixByDeletion_(ij) !goog.math.Matrix
Returns a new matrix equal to this one, but with row i and column j deleted.
Arguments:
i : number
The row index of the coordinate.
j : number
The column index of the coordinate.
Returns: !goog.math.Matrix  The value at the specified coordinate.
code »
getTranspose() !goog.math.Matrix
Return the transpose of this matrix. For an m-by-n matrix, the transpose is the n-by-m matrix which results from turning rows into columns and columns into rows
Returns: !goog.math.Matrix  A new matrix A^T.
code »
getValueAt(ij) ?number
Retrieves the value of a particular coordinate in the matrix or null if the requested coordinates are out of range.
Arguments:
i : number
The i index of the coordinate.
j : number
The j index of the coordinate.
Returns: ?number  The value at the specified coordinate.
code »
isInBounds_(ij) boolean
Returns whether the given coordinates are contained within the bounds of the matrix.
Arguments:
i : number
The i index of the coordinate.
j : number
The j index of the coordinate.
Returns: boolean  The value at the specified coordinate.
code »
isSquare() boolean
No description.
Returns: boolean  Whether the horizontal and vertical dimensions of this matrix are the same.
code »
matrixMultiply_(m) !goog.math.Matrix
Matrix multiplication is defined between two matrices only if the number of columns of the first matrix is the same as the number of rows of the second matrix. If A is an m-by-n matrix and B is an n-by-p matrix, then their product AB is an m-by-p matrix
Arguments:
m : goog.math.Matrix
Matrix to multiply the matrix by.
Returns: !goog.math.Matrix  Resultant product.
code »
multiply(m) !goog.math.Matrix
Performs matrix or scalar multiplication on a matrix and returns the resultant matrix. Matrix multiplication is defined between two matrices only if the number of columns of the first matrix is the same as the number of rows of the second matrix. If A is an m-by-n matrix and B is an n-by-p matrix, then their product AB is an m-by-p matrix Scalar multiplication returns a matrix of the same size as the original, each value multiplied by the given value.
Arguments:
m : goog.math.Matrix | number
Matrix/number to multiply the matrix by.
Returns: !goog.math.Matrix  Resultant product.
code »
scalarMultiply_(m) !goog.math.Matrix
Scalar multiplication returns a matrix of the same size as the original, each value multiplied by the given value.
Arguments:
m : number
number to multiply the matrix by.
Returns: !goog.math.Matrix  Resultant product.
code »
setValueAt(ijvalue)
Sets the value at a particular coordinate (if the coordinate is within the bounds of the matrix).
Arguments:
i : number
The i index of the coordinate.
j : number
The j index of the coordinate.
value : number
The new value for the coordinate.
code »
subtract(m) !goog.math.Matrix
Returns a new matrix that is the difference of this and the provided matrix.
Arguments:
m : goog.math.Matrix
The matrix to subtract from this one.
Returns: !goog.math.Matrix  Resultant difference.
code »
swapRows_(i1i2)
Swaps two rows.
Arguments:
i1 : number
The index of the first row to swap.
i2 : number
The index of the second row to swap.
code »
toArray() !Array.<!Array.<number>>
No description.
Returns: !Array.<!Array.<number>>  A 2D internal array representing this matrix. Not a clone.
code »
toString() string
Returns a string representation of the matrix. e.g.
[ 12  5  9  1 ]
[  4 16  0 17 ]
[ 12  5  1 23 ]
Returns: string  A string representation of this matrix.
code »

Instance Properties

array_ :
Internal array representing the matrix.
Code »
size_ : goog.math.Size
After construction the Matrix's size is constant and stored in this object.
Code »

Static Methods

goog.math.Matrix.createIdentityMatrix(n) !goog.math.Matrix
Creates a square identity matrix. i.e. for n = 3:
[ 1 0 0 ]
[ 0 1 0 ]
[ 0 0 1 ]
Arguments:
n : number
The size of the square identity matrix.
Returns: !goog.math.Matrix  Identity matrix of width and height n.
code »
goog.math.Matrix.createZeroPaddedArray_(mn) !Array.<!Array.<number>>
Creates a new zero padded matix.
Arguments:
m : number
Height of matrix.
n : number
Width of matrix.
Returns: !Array.<!Array.<number>>  The new zero padded matrix.
code »
goog.math.Matrix.forEach(matrixfnopt_obj)
Calls a function for each cell in a matrix.
Arguments:
matrix : goog.math.Matrix
The matrix to iterate over.
fn : Function
The function to call for every element. This function takes 4 arguments (value, i, j, and the matrix) and the return value is irrelevant.
opt_obj : Object=
The object to be used as the value of 'this' within fn.
code »
goog.math.Matrix.isValidArray(arr) boolean
Tests whether an array is a valid matrix. A valid array is an array of arrays where all arrays are of the same length and all elements are numbers.
Arguments:
arr : Array
An array to test.
Returns: boolean  Whether the array is a valid matrix.
code »
goog.math.Matrix.map(matrixfnopt_obj) !goog.math.Matrix
Calls a function for every cell in a matrix and inserts the result into a new matrix of equal dimensions.
Arguments:
matrix : goog.math.Matrix
The matrix to iterate over.
fn : Function
The function to call for every element. This function takes 4 arguments (value, i, j and the matrix) and should return something. The result will be inserted into a new matrix.
opt_obj : Object=
The object to be used as the value of 'this' within fn.
Returns: !goog.math.Matrix  A new matrix with the results from fn.
code »

Package math

Package Reference