Methods
(static) addMatrix(A, B) → {Array.<Array.<number>>}
Adds matrix A to matrix B
Parameters:
Name | Type | Description |
---|---|---|
A |
Array.<Array.<number>> | Matrix input A |
B |
Array.<Array.<number>> | Matrix input B |
Returns:
Matrix result from adding A and B
- Type
- Array.<Array.<number>>
(static) addMatrixC(A, c) → {Array.<Array.<number>>}
Adds constant c to each item in the matrix
Parameters:
Name | Type | Description |
---|---|---|
A |
Array.<Array.<number>> | The matrix to add c to |
c |
number | Constant to add to each value |
Returns:
Matrix result from the adding C to each element of A
- Type
- Array.<Array.<number>>
(static) areMatriciesApproximatelyEqual(A, B, diff) → {boolean}
Compares a matrix against another one, but allows a small difference tolerance
Parameters:
Name | Type | Default | Description |
---|---|---|---|
A |
Array.<Array.<number>> | The matrix to compare | |
B |
Array.<Array.<number>> | The second matrix to compare | |
diff |
number | 0.01 | The maximum (exclusive) tolerated difference between A[i][j] and B[i][j] |
Returns:
Absolute equality comparison result, accounting for tolerance
- Type
- boolean
(static) areMatriciesEqual(A, B) → {boolean}
Compares a matrix against another one
Parameters:
Name | Type | Description |
---|---|---|
A |
Array.<Array.<number>> | The matrix to compare |
B |
Array.<Array.<number>> | The second matrix to compare |
Returns:
Absolute equality comparison result
- Type
- boolean
(static) cofactorMatrix(mat) → {Array.<Array.<number>>}
Determins a the matrix of cofactors. (+,-,+,-,+,- ...)
Parameters:
Name | Type | Description |
---|---|---|
mat |
Array.<Array.<number>> | The matrix to determine cofactors for |
Returns:
matrix of cofactors
- Type
- Array.<Array.<number>>
(static) describeMatrix(mat) → {MatrixDescription}
Describes a given matrix
Parameters:
Name | Type | Description |
---|---|---|
mat |
Array.<Array.<number>> | The matrix to describe |
Returns:
Description of the given matrix
- Type
- MatrixDescription
(static) determinantMatrix(A) → {number}
Computes the determinant of a matrix, returns NaN if det === 0
Parameters:
Name | Type | Description |
---|---|---|
A |
Array.<Array.<number>> | The matrix to find determinat for |
Returns:
determinant of A
- Type
- number
(static) divideMatrixC(A, c) → {Array.<Array.<number>>}
Divides constant c to each item in the matrix
Parameters:
Name | Type | Description |
---|---|---|
A |
Array.<Array.<number>> | The matrix to add c to |
c |
numbe | Constant to divide each value by |
Returns:
Matrix result from the multiplying c to each element of A
- Type
- Array.<Array.<number>>
(static) dotProductMatrix(A, B, row, col) → {number}
Computers the dot product at a given row and column
Note: A and B must be multiply-able
Inputs are 0-offset.
Parameters:
Name | Type | Description |
---|---|---|
A |
Array.<Array.<number>> | The matrix A |
B |
Array.<Array.<number>> | The matrix B |
row |
number | Row to find dot product for |
col |
number | Column to find dot product for |
Returns:
Numerical evaluation of the dot product matrix A and B @ (row,col)
- Type
- number
(static) duplicateMatrix(mat) → {Array.<Array.<number>>}
Duplicates a given matrix. I.e. new copy is created and returned
Original reference is maintained
Parameters:
Name | Type | Description |
---|---|---|
mat |
Array.<Array.<number>> | The matrix to duplicate |
Returns:
Duplicated matrix
- Type
- Array.<Array.<number>>
(static) getIdentityMatrix(size) → {Array.<Array.<number>>}
Returns an identity matrix of a given size
Parameters:
Name | Type | Description |
---|---|---|
size |
number | The size of matrix to generate |
Returns:
Identity matrix of a given size
- Type
- Array.<Array.<number>>
(static) getIdentityMatrixRC(rows, cols) → {Array.<Array.<number>>}
Returns an identity matrix of size R X C
Parameters:
Name | Type | Description |
---|---|---|
rows |
number | Number of rows in the matrix |
cols |
number | Number of columns in the matrix |
Returns:
Identity matrix of a given size
- Type
- Array.<Array.<number>>
(static) getMatrix(row, col, val) → {Array.<Array.<number>>}
Gets a random matrix of the given value
Parameters:
Name | Type | Description |
---|---|---|
row |
number | number of rows to generate |
col |
number | number of columns to generate |
val |
number | Option for random values |
Returns:
A matrix of the given value
- Type
- Array.<Array.<number>>
(static) getRandomMatrix(row, col, opt) → {Array.<Array.<number>>}
Gets a random matrix of given parameters
Parameters:
Name | Type | Description |
---|---|---|
row |
number | number of rows to generate |
col |
number | number of columns to generate |
opt |
Object | Option for random values |
Returns:
A matrix of random values given the options
- Type
- Array.<Array.<number>>
(static) getSubMatix(mat, idx) → {Array.<Array.<number>>}
Returns a sub matrix from mat[idx][idx] onwards
Original reference is maintained
Parameters:
Name | Type | Description |
---|---|---|
mat |
Array.<Array.<number>> | The matrix round |
idx |
number | The matrix offset |
Returns:
Matrix from mat[idx][idx] onwards
- Type
- Array.<Array.<number>>
(static) getVectorFromMatrix(mat, idx) → {Array.<number>}
Gets a matrix column as a vector
Parameters:
Name | Type | Description |
---|---|---|
mat |
Array.<Array.<number>> | The matrix get vector for |
idx |
Array.<Array.<number>> | The column to get matrix for |
Returns:
Vector from the matrix
- Type
- Array.<number>
(static) getZeroMatrix(row, col) → {Array.<Array.<number>>}
Returns an square zero matrix of a given size
Parameters:
Name | Type | Description |
---|---|---|
row |
number | The row size of matrix to generate |
col |
number | The column size of matrix to generate |
Returns:
Zero matrix of a given size
- Type
- Array.<Array.<number>>
(static) inverseMatrix(mat) → {Array.<Array.<number>>}
Computes the inverse of a matrix
Note: this method does not accept 1D matricies and the input must be square
Original reference is maintained
Parameters:
Name | Type | Description |
---|---|---|
mat |
Array.<Array.<number>> | The matrix to find inverse of |
Returns:
Inverse of the input matrix
- Type
- Array.<Array.<number>>
(static) isValidMatrixPair(A, B) → {bool}
Checks if a pair of matricies are equal in size
Parameters:
Name | Type | Description |
---|---|---|
A |
Array.<Array.<number>> | The matrix to check |
B |
Array.<Array.<number>> | The second to check |
Returns:
Result if the dimension of the given matricies are equal
- Type
- bool
(static) LuDecomposeMatrix(A) → {LU}
Computes the upper and lower matrix using crout's method
Implementation is from: https://en.wikipedia.org/wiki/Crout_matrix_decomposition
Parameters:
Name | Type | Description |
---|---|---|
A |
Array.<Array.<number>> | The matrix to decompose |
Returns:
LU decomposition result
- Type
- LU
(static) matrixEigenVector(mat, eigenvalue, options) → {Array.<Array.<number>>}
Performs the inverse power method on a matrix to find its eigenvector
Parameters:
Name | Type | Description |
---|---|---|
mat |
Array.<Array.<number>> | The matrix to find eigenvalues for |
eigenvalue |
number | A approximate eigenvalue |
options |
Object | Maximum iterations or maximum change in norms between b_k and b_k+1 before termination |
Returns:
Eigenvector corresponding to given eigenvector
- Type
- Array.<Array.<number>>
(static) matrixOpperation(A, B) → {Array.<Array.<number>>}
Operates on the given matricies with func (for 2D dim matrices)
Parameters:
Name | Type | Description |
---|---|---|
A |
Array.<Array.<number>> | The matrix to sum |
B |
Array.<Array.<number>> | The second to sum |
Returns:
Numerical evaluation of matrix A and B
- Type
- Array.<Array.<number>>
(static) matrixOpperation1D(A, B) → {Array.<number>}
Operates on the given matricies with func (for 1 dim matrices)
Parameters:
Name | Type | Description |
---|---|---|
A |
Array.<number> | The matrix to sum |
B |
Array.<number> | The second to sum |
Returns:
Numerical evaluation of matrix A and B
- Type
- Array.<number>
(static) multiplyMatrix(A, B) → {Array.<Array.<number>>}
Multiplies matrix A and B
Note: You must check if the matrices are actually multiply-able
Parameters:
Name | Type | Description |
---|---|---|
A |
Array.<Array.<number>> | Matrix input A |
B |
Array.<Array.<number>> | Matrix input B |
Returns:
Matrix result from A * B
- Type
- Array.<Array.<number>>
(static) multiplyMatrixC(A, c) → {Array.<Array.<number>>}
Multiplies constant c to each item in the matrix
Parameters:
Name | Type | Description |
---|---|---|
A |
Array.<Array.<number>> | The matrix to add c to |
c |
number | Constant to multiply each value by |
Returns:
Matrix result from the multiplying c to each element of A
- Type
- Array.<Array.<number>>
(static) ofMinorsMatrix(mat) → {Array.<Array.<number>>}
Computes the matrix of minors
Note: this method does not accept 1D matricies.
Original reference is maintained
Parameters:
Name | Type | Description |
---|---|---|
mat |
Array.<Array.<number>> | The matrix to find minors for |
Returns:
Matrix of minors
- Type
- Array.<Array.<number>>
(static) powerMatrixC(A, c) → {Array.<Array.<number>>}
Takes the power C for each element in the array
Parameters:
Name | Type | Description |
---|---|---|
A |
Array.<Array.<number>> | The matrix to take power for |
c |
number | Constant to take power for |
Returns:
Matrix result from power of c for each element in A
- Type
- Array.<Array.<number>>
(static) QrDecomposeMatrix(mat) → {Array.<Array.<number>>}
Performs QR decomposition on the matrix
Original reference is maintained
Parameters:
Name | Type | Description |
---|---|---|
mat |
Array.<Array.<number>> | The matrix round |
Returns:
Matrix with rounding applied
- Type
- Array.<Array.<number>>
(static) QReig(mat, mat) → {Array.<Array.<number>>}
Performs QR iteration to determine eigenvalues
Parameters:
Name | Type | Description |
---|---|---|
mat |
Array.<Array.<number>> | The matrix to find eigenvalues for |
mat |
iter | Number of iterations (default 20) |
Returns:
Eigenvalue matrix (eigenvalues in diagonal)
- Type
- Array.<Array.<number>>
(static) rankOfMatrix(mat) → {number}
Returns then rank of a matrix
Parameters:
Name | Type | Description |
---|---|---|
mat |
Array.<Array.<number>> | The matrix to get rank for |
Returns:
Matrix rank
- Type
- number
(static) removeRowAndColMatrix(mat, row, col) → {Array.<Array.<number>>}
Deletes a row and column of a given matrix
Original reference is maintained
This method only works on 2D matricies
Parameters:
Name | Type | Description |
---|---|---|
mat |
Array.<Array.<number>> | The matrix to modify |
row |
number | The row to remove |
col |
number | The col to remove |
Returns:
Matrix without the specified row and column
- Type
- Array.<Array.<number>>
(static) roundMatrix(mat, digits) → {Array.<Array.<number>>}
Rounds each element in the matrix to a given accuracy
Original reference is maintained
Parameters:
Name | Type | Description |
---|---|---|
mat |
Array.<Array.<number>> | The matrix round |
digits |
number | The number of digits to round to |
Returns:
Matrix with rounding applied
- Type
- Array.<Array.<number>>
(static) rowCanonicalMatrix(mat) → {Array.<Array.<number>>}
Computes the row canonical form of a matrix (Also known as reduced row echelon)
Implementation from pseudo code: https://rosettacode.org/wiki/Reduced_row_echelon_form
Note: this method does not accept 1D matricies
Original reference is maintained
Parameters:
Name | Type | Description |
---|---|---|
mat |
Array.<Array.<number>> | The matrix to find inverse of |
Returns:
Row canonical form of the given matrix
- Type
- Array.<Array.<number>>
(static) setSubMatix(mat, sub, idx) → {Array.<Array.<number>>}
Returns a matrix from mat[idx][idx] set as a submatrix
Original reference is maintained
Parameters:
Name | Type | Description |
---|---|---|
mat |
Array.<Array.<number>> | The matrix round |
sub |
Array.<Array.<number>> | The submatrix to plug into the original mat |
idx |
number | The matrix offset |
Returns:
Matrix reaplced mat[idx][idx] onwards with sub
- Type
- Array.<Array.<number>>
(static) subMatrix(A, B) → {Array.<Array.<number>>}
Subtracts matrix B from matrix A
Parameters:
Name | Type | Description |
---|---|---|
A |
Array.<Array.<number>> | Matrix input A |
B |
Array.<Array.<number>> | Matrix input B |
Returns:
Matrix result from A - B
- Type
- Array.<Array.<number>>
(static) subMatrixC(A, c) → {Array.<Array.<number>>}
Subtracts constant c to each item in the matrix
Parameters:
Name | Type | Description |
---|---|---|
A |
Array.<Array.<number>> | The matrix to sub c to |
c |
number | Constant to subtract from each value |
Returns:
Matrix result from the subtracting C to each element of A
- Type
- Array.<Array.<number>>
(static) transposeMatrix(mat) → {Array.<Array.<number>>}
Transposes a given matrix
Parameters:
Name | Type | Description |
---|---|---|
mat |
Array.<Array.<number>> | The matrix to transpose |
Returns:
Transposed matrix
- Type
- Array.<Array.<number>>
(static) vectorNorm(mat, idx) → {Array.<number>}
Gets a matrix column as a vector
Parameters:
Name | Type | Description |
---|---|---|
mat |
Array.<Array.<number>> | The matrix get vector for |
idx |
Array.<Array.<number>> | The column to get matrix for |
Returns:
Vector from the matrix
- Type
- Array.<number>