Class Matrix
Represents 2D matrix of real (floating point) numbers
Defined in: jsmatrix.src.js.
Constructor Attributes | Constructor Name and Description |
---|---|
Matrix(nRows, nCols)
Matrix implementation
|
Field Attributes | Field Name and Description |
---|---|
number of columns of receiver
|
|
number of rows of receiver
|
Method Attributes | Method Name and Description |
---|---|
add(mat)
Returns sum of receiver and matrix ( ret = this + mat )
|
|
Anti-symmetrize receiver ( this = this - .5*(this+this^T) ).
|
|
Returns anti-symetric part of receiver ( ret = this - .5*(this+this^T) ).
|
|
appendCols(cols)
Appends vector(s)/matrix(s) as column(s) to receiver
|
|
appendRows(rows)
Appends vector(s)/matrix(s) as row(s) to receiver
|
|
assemble(mat, rows, cols)
assemble receiver to given matrix ( mat[rows][cols] += this )
|
|
backwardSubstitution(vec, saveOrig)
Returns vector x as a solution of this*ret = vec, receiver is assumed to be upper triangular matrix
|
|
Modifies receiver to become anti-symmetric part of given matrix (this = mat - .5*(mat+mat^T) ).
|
|
beCopyOf(mat)
Modifies receiver to become copy of given matrix (this = mat).
|
|
beDifferenceOf(mat1, mat2)
Modifies receiver to become difference of two matrices ( this = mat1 - mat2 ).
|
|
beDyadicProductOf(vec1, vec2)
Modifies receiver to become dyadic product of two vectors (this = vec1*vec2^T ).
|
|
Sets all elements of receiver to 1.0
|
|
beInverseOf(mat, method, precompDecomps)
Sets receiver as an inversion of given matrix
|
|
beNegativeOf(mat)
Modifies receiver to become negative of given matrix (this = -vec).
|
|
beProductOf(mat1, mat2)
Modifies receiver to become product of two matrices (this = mat1*mat2 ).
|
|
beProductTOf(mat1, mat2)
Modifies receiver to become product of two matrices (this = mat1*mat2^T )
|
|
beSubMatrixOf(mat, rows, cols)
Sets receiver to be submatrix of given matrix ( this = mat[rows][cols] )
|
|
beSumOf(mat1, mat2)
Modifies receiver to become sum of two matrices ( this = mat1 + mat2 ).
|
|
beSymmetricPartOf(mat)
Modifies receiver to become symmetric part of given matrix (this = .5*(mat+mat^T) ).
|
|
beTProductOf(mat1, mat2)
Modifies receiver to become product of two matrices (this = mat1^T*mat2 )
|
|
beTProductTOf(mat1, mat2)
Modifies receiver to become product of two matrices (this = mat1^T*mat2^T )
|
|
beTranspositionOf(mat)
Modifies receiver to become transposition of given matrix (this = mat^T ).
|
|
beUnitMatrix(newSize)
Modifies receiver to be unit matrix
|
|
canMultiplyMat(mat)
Testing if receiver can multiply given matrix ( this * mat )
|
|
canMultiplyVec(vec)
Testing if receiver can multiply given vector ( this * vec )
|
|
chol()
Alias for Cholesky decomposition, see Matrix#choleskyDecomposition
|
|
choleskyDecomposition(saveOrig, checkSymm)
Returns lower triangular matrix of Cholesky decomposition of receiver.
|
|
Alias for isOne(), see Matrix#isOne
|
|
Alias for isZero(), see Matrix#isZero
|
|
copied()
Returns copy of receiver
|
|
copy()
Alias for copied(), see Matrix#copied
|
|
<static> |
Matrix.create(arry)
Constructs new Matrix from given 2D array
|
decrCol(c, vec)
Decerements one column of receiver
|
|
decrRow(r, vec)
Decerements one row of receiver
|
|
decrsm()
Alias for decrSubMatrix, see Matrix#decrSubMatrix
|
|
decrSubMatrix(rows, cols, mat)
Decrement submatrix at defined positions of receiver ( this[rows][cols] -= mat )
|
|
det()
Alias for determinant, see Matrix#determinant
|
|
determinant(method, precompDecomps)
Returns determinant of receiver.
|
|
diag()
Alias for diagonalToVector(), see Matrix#diagonalToVector
|
|
<static> |
Matrix.Diagonal(arry)
Constructs new diagonal matrix from given 1D array
|
Returns vector containing receiver's diagonal elements
|
|
Returns product of diagonal elements of the receiver
|
|
diagSum()
Alias for trace, see Matrix#trace
|
|
dprod()
Alias for diagProduct, see Matrix#diagProduct
|
|
eigenDecomposition(method, precompSchurDecomp)
Returns orthogonal matrix Q and diagonal matrix L of eigendecomposition of the receiver such that this=P*L*P^-1 (obtained from eigenvalue equation this*P = P*L).
|
|
eigSymmetric(params)
Returns eigenvalues (L) and eigenvectors (P) of symmetric receiver ( (this-lambda*mat)*phi = 0 ).
|
|
eigVals(method)
Returns eigenvalues of receiver (this*x = ret*x)
|
|
empty()
Empties receiver (resizes it to size 0)
|
|
forwardSubstitution(vec, saveOrig)
Returns vector x as a solution of this*ret = vec, receiver is assumed to be lower triangular matrix
|
|
fromArray(arry)
Sets elements of receiver form given Array object
|
|
gaussianElimination(rhs, pivoting, saveOrig)
Returns vector as a solution of system of linear equations using gaussian elimination method (this * ret = rhs --> ret )
|
|
gaussJordanElimination(rhs, pivoting, saveOrig)
Returns matrix, whose columns are solutions of system of equations this*ret = rhs
|
|
get(r, c)
Coefficient access function, returns one element of receiver ( ret = this[r][c] ).
|
|
getCol(c)
Returns one column of receiver
|
|
getRow(r)
Returns one row of receiver
|
|
getsm()
Alias for getSubMatrix, see Matrix#getSubMatrix
|
|
getSubMatrix(rows, cols)
Returns submatrix of receiver ( ret = this[rows][cols] )
|
|
Alias for symetrized(), see Matrix#antiSymmetrized
|
|
Alias for determinant, see Matrix#determinant
|
|
Alias for symmetrized(), see Matrix#symmetrized
|
|
<static> |
Matrix.Householder(vec=0, precompI)
Creates a Householder matrix from given vector (ret = I - 2*v*v^T/(v^T*v).
|
<static> |
Matrix.I()
Alias for Matrix.Identity(), see Matrix#Identity
|
iadd(mat)
Add given matrix to receiver ( this += mat )
|
|
<static> |
Matrix.Identity(size)
Constructs new identity matrix of given size
|
implicitPartialPivotPermutation(saveOrig)
Returns row permutation matrix using implicit partial pivoting (for each column find row with relatively highest element at that column and place that line to the position such that the highest element is on diagonal.
|
|
imulf(f)
Multiply receiver by float f ( this *= f )
|
|
incr(r, c, val)
Coefficient access function, increment one element of receiver ( this[r][c] += val ).
|
|
incrCol(c, vec)
Incerements one column of receiver
|
|
incrRow(r, vec)
Incerements one row of receiver
|
|
incrsm()
Alias for incrSubMatrix, see Matrix#incrSubMatrix
|
|
incrSubMatrix(rows, cols, mat)
Increment submatrix at defined positions of receiver ( this[rows][cols] += mat )
|
|
ineg()
Alias for neagete(), see Matrix#negate
|
|
inv()
Alias for inversion, see Matrix#inversed
|
|
inversed(method, precompDecomps)
Returns inversion of receiver
|
|
isEmpty()
Tests if receiver is empty (has size 0,0)
|
|
isEqualTo(mat)
Testing matrix equality
|
|
Test if receiver is identity matrix
|
|
Tests receiver's involutariness (if this*this=I -> this^-1=this)
|
|
Testing if receiver is lower triangular matrix
|
|
isOne()
Test if receiver is matrix full of ones
|
|
Tests receiver's orthogonality (i.e.
|
|
Tests receiver's positive definitness
|
|
isSameSizeAs(mat)
Testing matrix size equality
|
|
Test receiver's singularity
|
|
isSquare()
Testing if receiver is square
|
|
Testing if receiver is symmetric
|
|
isTranspositionOf(mat)
Testing if receiver is transposition of given matrix
|
|
isub(mat)
Subtract given matrix to receiver ( this -= mat )
|
|
Alias for isIdentity, see Matrix#isIdentity
|
|
Testing if receiver is upper triangular matrix
|
|
isZero()
Test if receiver is zero matrix (full of zeroes)
|
|
lduDecomposition(pivoting)
Returns lower triangular (L), diagonal (D) and upper triangular (U) matrix of the receiver such that L*D*U=this.
|
|
linSolve(rhs, method, saveOrig, precompDecomps)
Returns vector/array of vectors/matrix as a solution of system of linear equations (this*ret=rhs --> ret).
|
|
Alias for Cholesky decomposition, see Matrix#choleskyDecomposition
|
|
luDecomposition(pivoting)
Returns lower (L) and upper (U) triangular matrix of the receiver such that L*U=this.
|
|
mul(what)
Returns product of receiver and given multiplier (Matrix, Vector or float)
|
|
mulf(f)
Returns receiver multiplied by float f ( ret = this * f )
|
|
mulm(mat)
Returns product of receiver and given matrix ( ret = this * mat )
|
|
mulv(vec)
Returns product of receiver and given vector ( ret = this * vec )
|
|
neg()
Alias for neageted(), see Matrix#negated
|
|
negate()
Negate receiver ( ret *= -1.
|
|
negated()
Returns negative of receiver ( ret = -this )
|
|
one()
Alias for beFullOfOnes(), see Matrix#beFullOfOnes
|
|
<static> |
Matrix.Ones(nRows, nCols)
Creates a matrix of given size full of ones
|
permuteRows(coeffs, backward)
Permute rows of receiver according to given coefficients
|
|
polarDecomposition(precompSvd)
Returns orthogonal matrix R and symmetric matrix U of polar decomposition of the receiver such that this=R*U.
|
|
resize(nRows, nCols)
Resize receiver according to given size (delete extra elements or add zero elements)
|
|
resized(nRows, nCols)
Returns resized copy of receiver according to given size (delete extra elements or add zero elements)
|
|
rowPermutation(coeffs, backward)
Returns copy of receiver with rows permutated according to given coefficients
|
|
schurDecomposition(saveOrig, maxiter)
returns orthogonal matrix Q and upper triangular matrix S as Schur decomposition of receiver such that this=Q*S*Q^-1.
|
|
schurForm(saveOrig, maxiter)
returns Schur form of receiver (upper triangular matrix with eigenvalues of the receiver on the diagonal).
|
|
set(r, c, val)
Coefficient access function, sets one element of receiver ( this[r][c] = val ).
|
|
setCol(c, vec)
Sets one column of receiver
|
|
setRow(r, vec)
Sets one row of receiver
|
|
setsm()
Alias for setSubMatrix, see Matrix#setSubMatrix
|
|
setSubMatrix(rows, cols, mat)
Sets submatrix at defined positions of receiver ( this[rows][cols] = mat )
|
|
Returns orthogonal matrix U, diagonal matrix S and orthogonal matrix V of singular value decomposition (SVD) of receiver such that this = U*S*V^T.
|
|
size()
Returns size of receiver as [nRows,nCols]
|
|
Returns spectral decomposition of receiver, identical to Matrix#eigenDecomposition
|
|
sub(mat)
Returns difference of receiver and matrix ( ret = this - mat )
|
|
svd()
Alias for singular value decomposition, see Matrix.singularValueDecomposition
|
|
swapCols(c1, c2)
Swaps two columns of receiver
|
|
swapRows(r1, r2)
Swaps two rows of receiver
|
|
Symmetrize receiver ( this = .5*(this+this^T) ).
|
|
Returns symmetric part of receiver ( ret = .5*(this+this^T) ).
|
|
T()
Alias for transposed(), see Matrix#transposed
|
|
toArray()
Returns elements of receiver as an Array object
|
|
toString()
Returns string representation of receiver
|
|
trace()
Returns trace (sum of diagonal elements) of the receiver
|
|
Modifies receiver to become transposition of itself ( this = this^T )
|
|
Returns transposition of receiver ( ret = this^T )
|
|
<static> |
Matrix.UnitMatrix()
Alias for Matrix.Identity(), see Matrix#Identity
|
x()
Alias for mul(), see Matrix#mul
|
|
zero()
Zeroes all elements of receiver
|
|
<static> |
Matrix.Zeros(nRows, nCols)
Creates a matrix of given size full of zeros
|
Class Detail
Matrix(nRows, nCols)
Matrix implementation
- Parameters:
- {int} nRows Optional, Default: 0
- number or rows of newly created Matrix
- {int} nCols Optional, Default: 0
- number or columns of newly created Matrix
Field Detail
{int}
nCols
number of columns of receiver
- Default Value:
- 0
{int}
nRows
number of rows of receiver
- Default Value:
- 0
Method Detail
{Matrix}
add(mat)
Returns sum of receiver and matrix ( ret = this + mat )
m1 = mat([[1,2],[3,4]]); m2 = mat([[2,5],[3,2]]); m3 = m1.add(m2); // m3 = Matrix([[3,7],[6,6]])
- Parameters:
- {Matrix} mat
- matrix to be added
- Returns:
- {Matrix} sum of receiver and matrix
antiSymmetrize()
Anti-symmetrize receiver ( this = this - .5*(this+this^T) ). Receiver must be square
m = mat([[1,2,3],[0,-1,5],[-1,1,7]]) m.antiSymmetrize(); // m = Matrix([[0,1,2],[-1,0,2],[-2,-2,0]])
antiSymmetrized()
Returns anti-symetric part of receiver ( ret = this - .5*(this+this^T) ). Receiver must be square
m1 = mat([[1,2,3],[0,-1,5],[-1,1,7]]) m2 = m1.antiSymmetrized(); // m2 = Matrix([[0,1,2],[-1,0,3],[-2,0,0]])
appendCols(cols)
Appends vector(s)/matrix(s) as column(s) to receiver
m = mat([[1,2],[3,4]]); m.appendCols(vec([7,6])); // m = Matrix([[1,2,7],[3,4,6]]) m.appendCols(mat([[1,3],[2,4]])); // m = Matrix([[1,2,7,1,3],[3,4,6,2,4]]) m = mat([[1,2],[3,4]]); m.appendCols([vec([2,1]),vec([33,44])]); // m = Matrix([[1,2,2,33],[3,4,1,44]]) m = mat([[1,2],[3,4]]); m.appendCols([mat([[11,12],[21,22]]),mat([[9,8],[7,6]])]); // m = Matrix([[1,2,11,12,9,8],[3,4,21,22,7,6]])
appendRows(rows)
Appends vector(s)/matrix(s) as row(s) to receiver
m = mat([[1,2],[3,4]]); m.appendRows(vec([7,6])); // m = Matrix([[1,2],[3,4],[7,6]]) m.appendRows(mat([[1,3],[2,4]])); // m = Matrix([[1,2],[3,4],[7,6],[1,3],[2,4]]) m = mat([[1,2],[3,4]]); m.appendRows([vec([2,1]),vec([33,44])]); // m = Matrix([[1,2],[3,4],[2,1],[33,44]]) m = mat([[1,2],[3,4]]); m.appendRows([mat([[11,12],[21,22]]),mat([[5,6],[7,8]])]); // m = Matrix([[1,2],[3,4],[11,12],[21,22],[5,6],[7,8]])
assemble(mat, rows, cols)
assemble receiver to given matrix ( mat[rows][cols] += this )
m1 = mat([[11,12,13,14],[21,22,23,24],[31,32,33,34],[41,42,43,44]]); m2 = mat([[66,77],[88,99]]); m2.assemble(m1,[1,2],[0,2]); // m1 = Matrix([11,12,13,14],[87,22,100,24],[119,32,132,34],[41,42,43,44]])
- Parameters:
- {Matrix} mat
- matrix where receiver is assembled
- {[floats]|Vector} rows
- array containing row coefficients of mat to be incremented
- {[floats]|Vector} cols
- array containing column coefficients of mat to be incremented
{Vector}
backwardSubstitution(vec, saveOrig)
Returns vector x as a solution of this*ret = vec, receiver is assumed to be upper triangular matrix
a = mat([[1,2,3,4],[0,5,6,7],[0,0,8,9],[0,0,0,10]]); y = vec([20,34,25,10]); x = a.backwardSubstitution(y); // x = Vector([4,3,2,1]) // y = Vector([20,34,25,10]) check = a.mul(x); // check = Vector([20,34,25,10]) // x = Vector([4,3,2,1]) // y = Vector([20,34,25,10]) yy = y.copy(); // yy = Vector([20,34,25,10]) a.backwardSubstitution(yy,false); // yy = Vector([4,3,2,1])
- Parameters:
- {Vector} vec
- right hand side
- {bool} saveOrig Optional, Default: true
- if true, returns vec will be unchanged and new vector will be returned. If false, solution will be saved to vec and vec will be returned
- Returns:
- {Vector} solution of this*ret = vec
beAntiSymmetricPartOf(mat)
Modifies receiver to become anti-symmetric part of given matrix (this = mat - .5*(mat+mat^T) ). mat has to be square
m1 = mat([[1],[3]]); m2 = mat([[1,2,3],[0,-1,5],[-1,1,7]]) m1.beAntiSymmetricPartOf(m2); // m1 = Matrix([[0,1,2],[-1,0,3],[-2,0,0]])
- Parameters:
- {Matrix} mat
- given matrix
beCopyOf(mat)
Modifies receiver to become copy of given matrix (this = mat). Receiver's size is adjusted
m1 = mat([[4],[5]]); m2 = mat([[1,2,3],[4,5,6]]); m1.beCopyOf(m2); // m1 = Matrix([[1,2,3],[4,5,6]])
- Parameters:
- {Matrix} mat
- matrix to be copied to receiver
beDifferenceOf(mat1, mat2)
Modifies receiver to become difference of two matrices ( this = mat1 - mat2 ). Receiver's size is adjusted
m = mat([[5],[9]]); m1 = mat([[1,2],[3,4]]); m2 = mat([[2,5],[3,2]]); m.beDifferenceOf(m1,m2); // m = Matrix([[-1,-3],[0,2]])
beDyadicProductOf(vec1, vec2)
Modifies receiver to become dyadic product of two vectors (this = vec1*vec2^T ). Receiver's size is adjusted
m = mat([[4],[5]]); v1 = vec([1,2,3]); v2 = vec([4,5,6]); m.beDyadicProductOf(v1,v2); // m = Matrix([[4,5,6],[8,10,12],[12,15,18]])
beFullOfOnes()
Sets all elements of receiver to 1.0
m = mat([[2,3,4],[5,6,7]]); m.beFullOfOnes(); // m = Matrix([[1,1,1],[1,1,1]])
beInverseOf(mat, method, precompDecomps)
Sets receiver as an inversion of given matrix
m1 = mat([[1],[2]]); m2 = mat([[1,2,2],[1,0,1],[1,2,1]]); m1.beInverseOf(m2); // m1 = Matrix([[2.3,-1.4,-0.8],[-1.4,1.2,0.4],[-0.8,0.4,0.8]])
- Parameters:
- {Matrices} mat
- given matrix
- {string} method Optional, Default: "default"
- see Matrix#inversed for details}
- {[Matrices]} precompDecomps Optional, Default: undefined
- precomputed matrix decompositions if we want to use some
beNegativeOf(mat)
Modifies receiver to become negative of given matrix (this = -vec). Receiver's size is adjusted
m1 = mat([[2],[3]]); m2 = mat([[1,2,3],[4,5,6]]); m1.beNegativeOf(m2); // m1 = Matrix([[-1,-2,-3],[-4,-5,-6]])
- Parameters:
- {Matrix} mat
- given matrix
beProductOf(mat1, mat2)
Modifies receiver to become product of two matrices (this = mat1*mat2 ). Receiver's size is adjusted
m1 = mat([[1],[2]]); m2 = mat([[11,12],[21,22]]); m3 = mat([[1,2],[3,4]]); m1.beProductOf(m2,m3); // m1 = Matrix([[47,70],[87,130]])
beProductTOf(mat1, mat2)
Modifies receiver to become product of two matrices (this = mat1*mat2^T )
m1 = mat([[1],[2]]); m2 = mat([[11,12],[21,22]]); m3 = mat([[1,3],[2,4]]); m1.beProductTOf(m2,m3); // m1 = Matrix([[47,70],[87,130]])
{Matrix}
beSubMatrixOf(mat, rows, cols)
Sets receiver to be submatrix of given matrix ( this = mat[rows][cols] )
m1 = mat([[11,12,13,14],[21,22,23,24],[31,32,33,34],[41,42,43,44]]); m2 = mat([[1],[2]]); m2.beSubMatrixOf(m1,[1,2],[0,2]); // m2 = Matrix([[21,23],[31,33]])
- Parameters:
- {Matrix} mat
- matrix to get submatrix from
- {[floats]|Vector} rows
- array containing rows coefficients of desired submatrix
- {[floats]|Vector} cols
- array containing columns coefficients of desired submatrix
- Returns:
- {Matrix} desired submatrix
beSumOf(mat1, mat2)
Modifies receiver to become sum of two matrices ( this = mat1 + mat2 ). Receiver's size is adjusted
m = mat([[5],[9]]); m1 = mat([[1,2],[3,4]]); m2 = mat([[2,5],[3,2]]); m.beSumOf(m1,m2); // m = Matrix([[3,7],[6,6]])
beSymmetricPartOf(mat)
Modifies receiver to become symmetric part of given matrix (this = .5*(mat+mat^T) ). mat has to be square
m1 = mat([[1],[3]]); m2 = mat([[1,2,3],[0,-1,5],[-1,1,7]]) m1.beSymmetricPartOf(m2); // m1 = Matrix([[1,1,1],[1,-1,3],[1,3,7]])
- Parameters:
- {Matrix} mat
- given matrix. Receiver's size is adjusted
beTProductOf(mat1, mat2)
Modifies receiver to become product of two matrices (this = mat1^T*mat2 )
m1 = mat([[1],[2]]); m2 = mat([[11,21],[12,22]]); m3 = mat([[1,2],[3,4]]); m1.beTProductOf(m2,m3); // m1 = Matrix([[47,70],[87,130]])
beTProductTOf(mat1, mat2)
Modifies receiver to become product of two matrices (this = mat1^T*mat2^T )
m1 = mat([[1],[2]]); m2 = mat([[11,21],[12,22]]); m3 = mat([[1,3],[2,4]]); m1.beTProductTOf(m2,m3); // m1 = Matrix([[47,70],[87,130]])
beTranspositionOf(mat)
Modifies receiver to become transposition of given matrix (this = mat^T ). Receiver's size is adjusted
m1 = mat([[4],[5]]); m2 = mat([[1,2,3],[4,5,6]]); m1.beTranspositionOf(m2) // m1 = mat([[1,4],[2,5],[3,6]])
- Parameters:
- {Matrix} mat
- matrix of transposition
beUnitMatrix(newSize)
Modifies receiver to be unit matrix
m = mat([[1],[2]]); m.beUnitMatrix(); // m = Matrix([[1],[2]]) /// nothing happened, m is not square m.beUnitMatrix(2); // m = Matrix([[1,0],[0,1]]) m = mat([[2,3],[4,5]]); m.beUnitMatrix(); // m = Matrix([[1,0],[0,1]])
- Parameters:
- {int} newSize Optional, Default: 0
- new size or receiver. If omitted or 0, current size is considered (then required square matrix), else resized to newSize
{bool}
canMultiplyMat(mat)
Testing if receiver can multiply given matrix ( this * mat )
m1 = mat([[1,2,3],[4,5,6]]); m2 = mat([[7,8,9],[10,11,12]]); m3 = mat([[11,12],[21,22],[31,32]]); t1 = m1.canMultiplyMat(m2); // t1 = false t2 = m1.canMultiplyMat(m3); // t2 = true
- Parameters:
- {Matrix} mat
- matrix to be tested
- Returns:
- {bool} true if the multiplication is possible, false otherwise
{bool}
canMultiplyVec(vec)
Testing if receiver can multiply given vector ( this * vec )
m = mat([[1,2,3],[4,5,6]]); v1 = vec([1,2,3]); v2 = vec([4,5]); t1 = m.canMultiplyVec(v1); // t1 = true t2 = m.canMultiplyVec(v2); // t2 = false
- Parameters:
- {Vector} vec
- vector to be tested
- Returns:
- {bool} true if the multiplication is possible, false otherwise
chol()
Alias for Cholesky decomposition, see Matrix#choleskyDecomposition
{Matrix}
choleskyDecomposition(saveOrig, checkSymm)
Returns lower triangular matrix of Cholesky decomposition of receiver. Receiver must be square, symmetric and positive definite. ( ret * ret^T = this )
a = mat([[1,2,4],[2,13,23],[4,23,77]]); l = a.choleskyDecomposition(); // l = Matrix([[1,0,0],[2,3,0],[4,5,6]]) check = l.x(l.T()); // check = Matrix([[1,2,4],[2,13,23],[4,23,77]]);
- Parameters:
- {bool} saveOrig Optional, Default: true
- if true, receiver is not changed. If false, solution will be saved to receiver
- {bool} checkSymm Optional, Default: false
- if true, test of receiver symmetricity is performed, otherwise not
- Returns:
- {Matrix} lower triangular Cholesky matrix
containsOnlyOnes()
Alias for isOne(), see Matrix#isOne
containsOnlyZeros()
Alias for isZero(), see Matrix#isZero
{Matrix}
copied()
Returns copy of receiver
m1 = mat([[11,12],[21,22]]); m2 = m1; m3 = m1.copied(); m1.set(1,0,6); // m1 = Matrix([[11,12],[6,22]]) // m2 = Matrix([[11,12],[6,22]]) // m3 = Matrix([[11,12],[21,22]])
- Returns:
- {Matrix} copy of receiver
copy()
Alias for copied(), see Matrix#copied
<static>
{Matrix}
Matrix.create(arry)
Constructs new Matrix from given 2D array
m = Matrix.create([[1,2,3],[4,5,6],[7,8,9]]) // m = Matrix([[1,2,3],[4,5,6],[7,8,9]])
- Parameters:
- {[floats](2D)} arry Optional, Default: []
- array containing elements of new matrix
- Returns:
- {Matrix} new Matrix object
decrCol(c, vec)
Decerements one column of receiver
m = mat([[1,2,3],[4,5,6],[7,8,9]]); m.decrCol(1,vec([11,12,13])); // m = Matrix([[1,-9,3],[4,-7,6],[7,-5,9]])
- Parameters:
- {int} c
- index of column to set
- {Vector} vec
- vector to be decremented from c-th column
decrRow(r, vec)
Decerements one row of receiver
m = mat([[1,2,3],[4,5,6],[7,8,9]]); m.decrRow(1,vec([11,12,13])); // m = Matrix([[1,2,3],[-7,-7,-7],[7,8,9]])
- Parameters:
- {int} r
- index of row to set
- {Vector} vec
- vector to be decremented from r-th row
decrsm()
Alias for decrSubMatrix, see Matrix#decrSubMatrix
decrSubMatrix(rows, cols, mat)
Decrement submatrix at defined positions of receiver ( this[rows][cols] -= mat )
m = mat([[11,12,13,14],[21,22,23,24],[31,32,33,34],[41,42,43,44]]); m.decrSubMatrix([1,2],[0,2],mat([[66,77],[88,99]])); // m = Matrix([11,12,13,14],[-45,22,-54,24],[-57,32,-66,34],[41,42,43,44]])
- Parameters:
- {[floats]|Vector} rows
- array containing rows coefficients to be decrementes
- {[floats]|Vector} cols
- array containing columns coefficients to be decremented
- {Matrix} mat
- matrix to be decremented on desired positions
det()
Alias for determinant, see Matrix#determinant
{float}
determinant(method, precompDecomps)
Returns determinant of receiver.
a = mat([[4,2,1],[2,5,3],[1,3,6]]); d = a.determinant(); // d = 67 d = a.determinant('schur'); // d = 67 d = a.determinant('schurdecomposition'); // d = 67 d = a.determinant('eigen'); // d = 67
- Parameters:
- {string} method Optional, Default: "default"
- used method. Options are "default" and "lu" for using LU decomposition, "schurForm" or "schur" for using schur form, "schurDecomposition" for using schur decomposition, "eigen" or "eigenDecomposition" for using eigendecomposition
- {[Matrices]} precompDecomps
- precomputed matrix decompositions if we want to use some
- Returns:
- {float} determinant of receiver
diag()
Alias for diagonalToVector(), see Matrix#diagonalToVector
<static>
{Matrix}
Matrix.Diagonal(arry)
Constructs new diagonal matrix from given 1D array
m1 = Matrix.Diagonal([1,2,3]); // m1 = Matrix([[1,0,0],[0,2,0],[0,0,3]]) m2 = Matrix.Diagonal(vec([1,2,3])); // m2 = Matrix([[1,0,0],[0,2,0],[0,0,3]])
- Parameters:
- {[floats]|Vector} arry
- array or vector containing elements of new matrix
- Returns:
- {Matrix} new Matrix object
{Vector}
diagonalToVector()
Returns vector containing receiver's diagonal elements
m = mat([[1,2,3],[4,5,6],[7,8,9]]); v = m.diag(); // v = Vector([1,5,9])
- Returns:
- {Vector} vector containing receiver's diagonal elements
{float}
diagProduct()
Returns product of diagonal elements of the receiver
m = mat([[1,2,3],[4,5,6],[7,8,9]]); p = m.diagProduct(); // p = 45
- Returns:
- {float} product of diagonal elements of the receiver
diagSum()
Alias for trace, see Matrix#trace
dprod()
Alias for diagProduct, see Matrix#diagProduct
Returns orthogonal matrix Q and diagonal matrix L of eigendecomposition of the receiver such that this=P*L*P^-1 (obtained from eigenvalue equation this*P = P*L). If receiver is symmetric, P is orthogonal. Columns of P are eigenvectors of this and diagonal elements of L are corresponding eigenvalues
m1 = mat([[4,2,3,1],[3,6,5,7],[5,3,8,1],[2,3,4,5]]); pl = m1.eigenDecomposition() p = pl[0] l = pl[1] // p = // l = c = p.mulm(l).mulm(p.inv()) // c =
- Parameters:
- {string} method Optional, Default: "default"
- method of eigenvalues solution. See Matrix#eig
- precompSchurDecomp
{[[floats]|[Vectors]]}
eigSymmetric(params)
Returns eigenvalues (L) and eigenvectors (P) of symmetric receiver ( (this-lambda*mat)*phi = 0 ). Eigenvectors are normalized with respect to mat
k = mat([[9,3,0,0],[3,8,2,0],[0,2,7,2],[0,0,2,8]]); m = Matrix.Diagonal([3,2,4,3]); e = k.eigSymmetric({mat:m,nEigModes:2,highest:false}); ls = e[0]; ps = e[1]; l1 = ls[0]; // l1 = 1.2504038497315775 l2 = ls[1]; // l2 = 2.279120228657416 p1 = ps[0]; // p1 = Vector([ 0.1288306767139194, -0.22540165581364102, 0.4265175098731745, -0.20077135620035116 ]) p2 = ps[1]; // p2 = Vector([ 0.4514687335612619, -0.32545467450354726, -0.11713473474653795, 0.2014979513549984 ]) // e = k.eigSymmetric({mat:m,nEigModes:2,highest:true,method:'subspace'}); ls = e[0]; ps = e[1]; l3 = ls[1]; // l3 = 2.948867853467429 l4 = ls[0]; // l4 = 4.938274734810245 p3 = ps[1]; // p3 = Vector([ 0.14681878659487543, -0.007507144503266177, -0.21233717286242818, -0.5016212772448967 ]) p4 = ps[0]; // p4 = Vector([ 0.3022519091588433, 0.585847242190032, 0.09630780190740544, 0.028264211960396433 ]) // c1 = k.x(p1).sub(m.x(p1).x(l1)); // c1 = Vector([0,0,0,0]) c2 = k.x(p2).sub(m.x(p2).x(l2)); // c2 = Vector([0,0,0,0]) c3 = k.x(p3).sub(m.x(p3) .x(l3)); // c3 = Vector([0,0,0,0]) c4 = k.x(p4).sub(m.x(p4).x(l4)); // c4 = Vector([0,0,0,0])
- Parameters:
- {Object} params
- object of parameters
- {Matrix} params.mat Optional, Default: Matrix.Identity
- mat in (this-lambda*mat)*phi = 0 ). If mat==Matix.Identity, then the "classical" eigenvalue problem is solved ( (this-lambda*I)*phi = 0 -> this*phi=lambda*phi)
- {int|string("all")} params.nEigModes Optional, Default: 'all'
- number of first eigenvalues and eigenvectors to be returned. if "all" is, then all eigenvalues are returned
- {string} params.method Optional, Default: "default"
- method of the solution. "default" and "invit" stands for Stodola's inverse iterations methods with Gramm-Schmidt orthogonalization, "subspace" for subspace iterations
- {bool} params.highest Optional, Default: true
- find params.nEigModes highest eigenvalues if true, params.nEigModes lowest eigenvalues otherwise
- {int} params.maxiter Optional, Default: 1000
- maximum number of iterations
- Returns:
- {[[floats]|[Vectors]]} [[lambda1,lambda2,...,lambdaN],[phi1,phi2,...,phiN]], oi is i-th eigenvalue, vi is i-th eigenvector. N = nEigModes //
{[floats]}
eigVals(method)
Returns eigenvalues of receiver (this*x = ret*x)
m1 = mat([[4,2,3,1],[3,6,5,7],[5,3,8,1],[2,3,4,5]]); v1 = m1.schurForm().diag().toArray(); // v1 = [15.6072, 4.1916, 2.2012, 1 ] v2 = m1.eigVals(); // v2 = [15.6072, 4.1916, 2.2012, 1 ]
- Parameters:
- {string} method Optional, Default: "default"
- method of solution. "default and "schur" stand for similar transformation of receiver into schur form
- Returns:
- {[floats]} eigenvalues of receiver
empty()
Empties receiver (resizes it to size 0)
m = mat([[1,2],[3,4]]); m.empty(); // m = Matrix([])
{Vector}
forwardSubstitution(vec, saveOrig)
Returns vector x as a solution of this*ret = vec, receiver is assumed to be lower triangular matrix
a = mat([[1,0,0,0],[2,3,0,0],[4,5,6,0],[7,8,9,10]]); y = vec([4,17,43,80]); x = a.forwardSubstitution(y); // x = Vector([4,3,2,1]) // y = Vector([4,17,43,80]) check = a.mul(x); // check = Vector([4,17,43,80]) // x = Vector([4,3,2,1]) // y = Vector([4,17,43,80]) yy = y.copy(); // yy = Vector([4,17,43,80]) a.forwardSubstitution(yy,false); // yy = Vector([4,3,2,1])
- Parameters:
- {Vector} vec
- right hand side
- {bool} saveOrig Optional, Default: true
- if true, returns vec will be unchanged and new vector will be returned. If false, solution will be saved to vec and vec will be returned
- Returns:
- {Vector} solution of this*ret = vec
fromArray(arry)
Sets elements of receiver form given Array object
m = mat([[3,2],[1,1]]) m.fromArray([[1,2,3],[4,5,6],[7,8,9]]); // m = Matrix([[1,2,3],[4,5,6],[7,8,9]])
- Parameters:
- {[floats](2D)} arry
- array containing new receiver elements
{Vector}
gaussianElimination(rhs, pivoting, saveOrig)
Returns vector as a solution of system of linear equations using gaussian elimination method (this * ret = rhs --> ret )
a = mat([[1,2,9],[8,3,2],[3,7,3]]); b = vec([32,20,26]); x = a.gaussianElimination(b); // x = Vector([1,2,3]) x = a.gaussianElimination(b,'partpivot'); // x = Vector([1,2,3]) a.gaussianElimination(b,'nopivot',false); // a = Matrix([[1,2,9],[8,-13,-70],[3,1,-29.384615384615387]]) // b = Vector([1,2,3])
- Parameters:
- {Vector} rhs
- vector of right hand sides
- {string} pivoting Optional, Default: "default"
- what type of pivoting to use. "default" and "nopivot" stands for no pivoting, "partpivot" for implicit partial pivoting (only row interchanges)
- saveOrig
- Returns:
- {Vector} vector of solution
{Matrix}
gaussJordanElimination(rhs, pivoting, saveOrig)
Returns matrix, whose columns are solutions of system of equations this*ret = rhs
a = mat([[1,2,9],[8,3,2],[3,7,3]]); b1 = vec([32,20,26]); b2 = vec([16,32,26]); b3 = [b1.copy(),b2.copy()]; b4 = mat([b1.toArray(),b2.toArray()]).T(); x1 = a.gaussJordanElimination(b1); // x1 = Vector([ 1, 2, 3 ]) x2 = a.gaussJordanElimination(b2); // x2 = Vector([ 3, 2, 1 ]) x3 = a.gaussJordanElimination(b3); // x3 = [Vector([ 1, 2, 3 ]) ,Vector([ 3, 2, 1 ])] x4 = a.gaussJordanElimination(b4); // x4 = Matrix([[ 1, 3 ], [ 2, 2 ], [ 3, 1 ]]) x5 = a.gaussJordanElimination(b1,'nopivot');; // x5 = Vector([ 1, 2, 3 ]) x6 = a.gaussJordanElimination(b2,'nopivot'); // x6 = Vector([ 3, 2, 1 ]) x7 = a.gaussJordanElimination(b3,'nopivot'); // x7 = Vector([ 1, 2, 3 ]) ,Vector([ 3, 2, 1 ]) x8 = a.gaussJordanElimination(b4,'nopivot'); // x8 = Matrix([[ 1, 3 ], [ 2, 2 ], [ 3, 1 ]]) a.gaussJordanElimination(b4,'nopivot',false); // b4 = Matrix([[ 1, 3 ], [ 2, 2 ], [ 3, 1 ]])
- Parameters:
- {Matrix|[Vectors]|Vector} rhs
- matrix/vector/array of vectors representing right hand sides
- {string} pivoting Optional, Default: "default"
- what type of pivoting to use. "default" and "nopivot" stands for no pivoting, "partpivot" for implicit partial pivoting (only row interchanges)
- {bool} saveOrig Optional, Default: true
- if true, receiver is not changed. If false, solution will be saved to rhs and rhs will be returned
- Returns:
- {Matrix} matrix, whose columns are solution for particular right hand sides
{float}
get(r, c)
Coefficient access function, returns one element of receiver ( ret = this[r][c] ). Matrix.get(r,c) is much safer than direct Matrix[r][c] access method
m = mat([[11,12,13],[21,22,23],[31,32,33]]); g = m.get(1,2); // g = 23 g = m[1][2]; // g = 23 /// c out of bounds g = m.get(1,5); // g = null g = m[1][5]; // g = undefined /// r out of bounds g = m.get(6,5) // g = null /// g = m[6][5]; would be error (m[6] is not defined)
- Parameters:
- {int} r
- index of row of element to be returned
- {int} c
- index of column of element to be returned
- Returns:
- {float} value of the element at r-th row and c-th column
{Vector}
getCol(c)
Returns one column of receiver
m = mat([[1,2,3],[4,5,6],[7,8,9]]); v = m.getCol(1); // v = Vector([2,5,8])
- Parameters:
- {int} c
- index of column to return
- Returns:
- {Vector} c-th column of receiver as vector
{Vector}
getRow(r)
Returns one row of receiver
m = mat([[1,2,3],[4,5,6],[7,8,9]]); v = m.getRow(1); // v = Vector([4,5,6])
- Parameters:
- {int} r
- index of row to return
- Returns:
- {Vector} r-th row of receiver as vector
getsm()
Alias for getSubMatrix, see Matrix#getSubMatrix
{Matrix}
getSubMatrix(rows, cols)
Returns submatrix of receiver ( ret = this[rows][cols] )
m1 = mat([[11,12,13,14],[21,22,23,24],[31,32,33,34],[41,42,43,44]]); m2 = m1.getSubMatrix([1,2],[0,2]); // m2 = Matrix([[21,23],[31,33]])
- Parameters:
- {[floats]|Vector} rows
- array containing rows coefficients of desired submatrix
- {[floats]|Vector} cols
- array containing columns coefficients of desired submatrix
- Returns:
- {Matrix} desired submatrix
giveAntiSymmetricPart()
Alias for symetrized(), see Matrix#antiSymmetrized
giveDeterminant()
Alias for determinant, see Matrix#determinant
giveSymmetricPart()
Alias for symmetrized(), see Matrix#symmetrized
<static>
{Matrix}
Matrix.Householder(vec=0, precompI)
Creates a Householder matrix from given vector (ret = I - 2*v*v^T/(v^T*v). Householder matrix is symmetric, orthogonal and involutary
m1 = Matrix.Householder(vec([0,1,0])) // m1 = Matrix([[1,0,0],[0,-1,0],[0,0,1]]) b1 = m1.isSymmetric() // b1 = true b2 = m1.isOrthogonal() // b2 = true b3 = m1.isInvolutary() // b3 = true m2 = mat([[1,2,3],[4,5,6],[7,8,9]]); v = m2.getCol(0); q = Matrix.Householder(v.sub(vec([1,0,0]).mulf(v.norm()))); m3 = q.mulm(m2); // m3 =
- Parameters:
- {Vector} vec=0
- Householder vector to form Householder matrix
- {Matrix} precompI Optional, Default: undefined
- precomputed identity matrix to save some time of creation
- Returns:
- {Matrix} Householder matrix
<static>
Matrix.I()
Alias for Matrix.Identity(), see Matrix#Identity
iadd(mat)
Add given matrix to receiver ( this += mat )
m1 = mat([[1,2],[3,4]]); m2 = mat([[2,5],[3,2]]); m1.iadd(m2); // m1 = Matrix([[3,7],[6,6]])
- Parameters:
- {Matrix} mat
- matrix to be added
<static>
{Matrix}
Matrix.Identity(size)
Constructs new identity matrix of given size
m = Matrix.Identity(4) // m = Matrix([[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]])
- Parameters:
- {int} size
- size of returned matrix
- Returns:
- {Matrix} identity matri
{[Matrix|[ints]]}
implicitPartialPivotPermutation(saveOrig)
Returns row permutation matrix using implicit partial pivoting (for each column find row with relatively highest element at that column and place that line to the position such that the highest element is on diagonal. Lines that are placed in this way are not considered for further steps)
m1 = mat([[1,2,4,9],[1,8,1,1],[9,4,5,3],[1,2,6,2]]); m2 = m1.implicitPartialPivotPermutation(); // m2[0] = Matrix([[9,4,5,3],[1,8,1,1],[1,2,6,2],[1,2,4,9]]) // m2[1] = [2,1,3,0] // m1 = Matrix([[1,2,4,9],[1,8,1,1],[9,4,5,3],[1,2,6,2]]) m3 = m1.rowPermutation(m2[1]); // m3 = Matrix([[9,4,5,3],[1,8,1,1],[1,2,6,2],[1,2,4,9]]) m4 = m2[0].rowPermutation(m2[1],true); // m4 = Matrix([[1,2,4,9],[1,8,1,1],[9,4,5,3],[1,2,6,2]]) m1 = m1.implicitPartialPivotPermutation(false)[0]; // m1 = Matrix([[9,4,5,3],[1,8,1,1],[1,2,6,2],[1,2,4,9]])
- Parameters:
- {bool} saveOrig Optional, Default: true
- if true, returns permutated copy of receiver. If false, permutate receiver and return this
- Returns:
- {[Matrix|[ints]]} permutated matrix and array containing coefficients of original matrix according to position in the permutated one ( such that this.rowPermutation(coeffs) = ret )
imulf(f)
Multiply receiver by float f ( this *= f )
m = mat([[1,2,3],[4,5,6]]); m.imulf(3); // m = Matrix([[3,6,9],[12,15,18]])
- Parameters:
- {float} f
- float multiplier
incr(r, c, val)
Coefficient access function, increment one element of receiver ( this[r][c] += val ). Matrix.incr(r,c,val) is much safer than direct Matrix[r][c]+=val access method
m = mat([[11,12,13],[21,22,23],[31,32,33]]); m.incr(1,2,3.45); // m = Matrix([[11,12,13],[21,22,26.45],[31,32,33]]) m[1][2] += 3.45; // m = Matrix([[11,12,13],[21,22,29.9],[31,32,33]]) /// c out of bounds m.incr(1,5,3.45); // m = Matrix([[11,12,13],[21,22,29.9],[31,32,33]]) /// m[1][5] += 3.45); would be error (m[1][5] is not defined) /// r out of bounds m.incr(6,5,3.45); // m = Matrix([[11,12,13],[21,22,29.9],[31,32,33]]) /// m[6][5] += 3.45; would be error (m[6] is not defined)
- Parameters:
- {int} r
- index of row of element to be incremented
- {int} c
- index of column of element to be incremented
- {float} val
- value to be add
incrCol(c, vec)
Incerements one column of receiver
m = mat([[1,2,3],[4,5,6],[7,8,9]]); m.incrCol(1,vec([11,12,13])); // m = Matrix([[1,13,3],[4,17,6],[7,21,9]])
- Parameters:
- {int} c
- index of column to set
- {Vector} vec
- vector to be incremented to c-th column
incrRow(r, vec)
Incerements one row of receiver
m = mat([[1,2,3],[4,5,6],[7,8,9]]); m.incrRow(1,vec([11,12,13])); // m = Matrix([[1,2,3],[15,17,19],[7,8,9]])
- Parameters:
- {int} r
- index of row to set
- {Vector} vec
- vector to be incremented to r-th row
incrsm()
Alias for incrSubMatrix, see Matrix#incrSubMatrix
incrSubMatrix(rows, cols, mat)
Increment submatrix at defined positions of receiver ( this[rows][cols] += mat )
m = mat([[11,12,13,14],[21,22,23,24],[31,32,33,34],[41,42,43,44]]); m.incrSubMatrix([1,2],[0,2],mat([[66,77],[88,99]])); // m = Matrix([11,12,13,14],[87,22,100,24],[119,32,132,34],[41,42,43,44]])
- Parameters:
- {[floats]|Vector} rows
- array containing rows coefficients to be incrementes
- {[floats]|Vector} cols
- array containing columns coefficients to be incremented
- {Matrix} mat
- matrix to be incremented on desired positions
ineg()
Alias for neagete(), see Matrix#negate
inv()
Alias for inversion, see Matrix#inversed
{Matrix}
inversed(method, precompDecomps)
Returns inversion of receiver
a = mat([[1,2,2],[1,0,1],[1,2,1]]); i1 = a.inversed(); // i1 = c = a.mulm(i1) // c = Matrix([[1,0,0],[0,1,0],[0,0,1]]) i2 = a.inversed('lu') // i2 = Matrix([[-1,1,1],[0,-0.5,0.5],[1,0,-1]]) i3 = a.inversed('eigen') // i3 = Matrix([[-1,1,1],[0,-0.5,0.5],[1,0,-1]]) i4 = a.inversed('svd') // i4 = Matrix([[-1,1,1],[0,-0.5,0.5],[1,0,-1]]) check = a.x(i1); // check = Matrix([[1,0,0],[0,1,0],[0,0,1]])
- Parameters:
- {string} method Optional, Default: "default"
- method used for solution. Options are "default" and "gaussjordan" for Gauss-Jordan method, "lu" for solution with LU decomposition, "eigen" with eigen decomposition, "symmeigen" with eigen decomposition when receiver is symmetric, "svd" for SVD decomposition
- {[Matrices]} precompDecomps Optional, Default: undefined
- precomputed matrix decompositions if we want to use some
- Returns:
- {Matrix} inversion of receiver
isEmpty()
Tests if receiver is empty (has size 0,0)
v1 = new Matrix(2,3); v2 = new Matrix(); b1 = v1.isEmpty(); // b1 = false b2 = v2.isEmpty(); // b2 = true
- Returns:
- true if receiver is empty, false otherwise
{bool}
isEqualTo(mat)
Testing matrix equality
a = mat([[1,2,3],[4,5,6],[7,8,9]]); b = mat([[1,2,2.999999999],[4.0000000000002,5,6],[7,8,8.9999999999]]); c = mat([[1,2,3],[4,5,6],[7,8,9],[10,11,12]]); t1 = a.isEqualTo(b); // t1 = true t2 = a.isEqualTo(c); // t2 = false
- Parameters:
- {Matrix} mat
- matrix to be compared with receiver
- Returns:
- {bool} true if this==mat, false otherwise
{bool}
isIdentity()
Test if receiver is identity matrix
m1 = mat([[1,0,0],[0,1,0],[0,0,-1]]); m2 = mat([[1,0,0],[0,1,0],[0,0,1]]); i1 = m1.isIdentity() // i1 = false i2 = m2.isIdentity() // i2 = true
- Returns:
- {bool} true if receiver is identity, false otherwise
{bool}
isInvolutary()
Tests receiver's involutariness (if this*this=I -> this^-1=this)
m = mat([[1,0,0],[0,-1,0],[0,0,-1]]) t = m.isInvolutary() // t = true
- Returns:
- {bool} true if receiver is involutary, false otherwise
{bool}
isLowerTriangular()
Testing if receiver is lower triangular matrix
m1 = mat([[1,2,3],[4,5,6],[7,8,9]]); m2 = mat([[1,0,0],[4,5,0],[7,8,9]]); t1 = m1.isLowerTriangular(); // t1 = false t2 = m2.isLowerTriangular(); // t2 = true
- Returns:
- {bool} true if receiver is lower triangular, false otherwise
{bool}
isOne()
Test if receiver is matrix full of ones
m1 = mat([[1,1,1],[1,.999999999999,1],[1,1,1]]); m2 = mat([[1,0,0],[0,1,0],[0,0,1]]); i1 = m1.isOne() // i1 = true i2 = m2.isOne() // i2 = false
- Returns:
- {bool} true if receiver is full of ones, false otherwise
{bool}
isOrthogonal()
Tests receiver's orthogonality (i.e. this*this^T = I => this^-1 = this^T)
m1 = Matrix.Householder(vec([0,1,0])) // m1 = Matrix([[1,0,0],[0,-1,0],[0,0,1]]); m2 = mat([[0,0,1],[1,0,0],[0,1,0]]) m3 = mat([[1,2,3],[4,5,6],[7,8,9]]) m4 = mat([[0.8,0,0.6],[0,1,0],[-0.8,0,0.6]]); b1 = m1.isOrthogonal() // b1 = true b2 = m2.isOrthogonal() // b2 = true b3 = m3.isOrthogonal() // b3 = false b4 = m4.isOrthogonal() // b4 = true
- Returns:
- {bool} true if receiver is orthogonal, false otherwise
{bool}
isPositiveDefinite()
Tests receiver's positive definitness
m1 = mat([[9,2,1],[2,8,3],[1,3,7]]) m2 = mat([[-9,2,1],[2,8,3],[1,3,7]]) b1 = m1.isPositiveDefinite() // b1 = true b2 = m2.isPositiveDefinite() // b2 = false
- Returns:
- {bool} true if receiver is positive definite (if Cholesky decomposition can be performed), false otherwise
{bool}
isSameSizeAs(mat)
Testing matrix size equality
a = mat([[1,2,3],[4,5,6]]); b = mat([[5,6,7],[8,9,10],[11,12,13]]); c = mat([[14,15,16],[17,18,19]]); t1 = a.isSameSizeAs(b); // t1 = false t2 = a.isSameSizeAs(c); // t2 = true
- Parameters:
- {Matrix} mat
- matrix to be tested
- Returns:
- {bool} true if mat and receiver has same size, false otherwise
{bool}
isSingular()
Test receiver's singularity
a = mat([[1,2,3],[2,4,6],[4,5,6]]); b = mat([[4,2,1],[2,5,3],[1,3,6]]); s1 = a.isSingular(); // s1 = true s2 = b.isSingular(); // s2 = false
- Returns:
- {bool} true if receiver is singular (if abs(this.det()) < JSM_TOL), false otherwise
{bool}
isSquare()
Testing if receiver is square
m1 = mat([[1,2,3],[4,5,6]]); m2 = mat([[1,2,3],[4,5,6],[7,8,9]]); t1 = m1.isSquare(); // t1 = false t2 = m2.isSquare(); // t2 = true
- Returns:
- {bool} true if receiver is square matrix, false otherwise
{bool}
isSymmetric()
Testing if receiver is symmetric
m1 = mat([[11,12,13],[21,22,23],[31,32,33]]); m2 = mat([[11,12,13],[12,22,23],[13,23,33]]); t1 = m1.isSymmetric(); // t1 = false t2 = m2.isSymmetric(); // t2 = true
- Returns:
- {bool} true if receiver is symmetric, false otherwise
{bool}
isTranspositionOf(mat)
Testing if receiver is transposition of given matrix
m1 = mat([[1,2,3],[4,5,6]]); m2 = mat([[1,4],[2,5],[3,6]]); m3 = mat([[1,2],[4,5]]); b1 = m1.isTranspositionOf(m2); // b1 = true b2 = m1.isTranspositionOf(m3); // b2 = false
- Parameters:
- {Matrix} mat
- given matrix
- Returns:
- {bool} true if this==mat^T, false otherwise
isub(mat)
Subtract given matrix to receiver ( this -= mat )
m1 = mat([[1,2],[3,4]]); m2 = mat([[2,5],[3,2]]); m1.isub(m2); // m1 = Matrix([[-1,-3],[0,2]])
- Parameters:
- {Matrix} mat
- matrix to be added
isUnitMatrix()
Alias for isIdentity, see Matrix#isIdentity
{bool}
isUpperTriangular()
Testing if receiver is upper triangular matrix
m1 = mat([[1,2,3],[4,5,6],[7,8,9]]); m2 = mat([[1,2,3],[0,5,6],[0,0,9]]); t1 = m1.isUpperTriangular(); // t1 = false t2 = m2.isUpperTriangular(); // t2 = true
- Returns:
- {bool} true if receiver is upper triangular, false otherwise
{bool}
isZero()
Test if receiver is zero matrix (full of zeroes)
m1 = mat([[0,0,0],[0,1e-16,0],[0,0,0]]); m2 = mat([[1,0,0],[0,1,0],[0,0,1]]); i1 = m1.isZero() // i1 = true i2 = m2.isZero() // i2 = false
- Returns:
- {bool} true if receiver is zero, false otherwise
Returns lower triangular (L), diagonal (D) and upper triangular (U) matrix of the receiver such that L*D*U=this. Diagonal elements of both L and U are all 1. Receiver must be square.
a = mat([[2,10,8],[4,23,22],[6,42,52]]); ldu = a.lduDecomposition(); l = ldu[0]; // l = Matrix([[1,0,0],[2,1,0],[3,4,1]]) d = ldu[1]; // d = Vector([2,3,4]) u = ldu[2]; // u = Matrix([[1,5,4],[0,1,2],[0,0,1]]) check = l.x(d.diag()).x(u) // check = Matrix([[2,10,8],[4,23,22],[6,42,52]]);
- Parameters:
- {string} pivoting Optional, Default: "default"
- what type of pivoting to use. "default" and "nopivot" stands for no pivoting, "partpivot" for implicit partial pivoting (only row interchanges)
{Vector|[Vectors]|Matrix}
linSolve(rhs, method, saveOrig, precompDecomps)
Returns vector/array of vectors/matrix as a solution of system of linear equations (this*ret=rhs --> ret). Receiver must be square. TODO: solution with LU decomposition with permutation
a = mat([[1,2,9],[8,3,2],[3,7,3]]); b = vec([32,20,26]); x1 = a.linSolve(b); // x1 = Vector([1,2,3]) x2 = a.linSolve(b,'gauss'); // x2 = Vector([1,2,3]) x3 = a.linSolve(b,'gaussjordan'); // x3 = Vector([1,2,3]) x4 = a.linSolve(b,'lu'); // x4 = Vector([1,2,3]) x5 = a.linSolve(b,'ldu'); // x5 = Vector([1,2,3]) x7 = a.linSolve(b,'qr'); // x7 = Vector([1,2,3]) a2 = mat([[1,2,4],[2,13,23],[4,23,77]]); b2 = vec([17,97,281]); x6 = a2.linSolve(b2,'cholesky'); // x6 = Vector([1,2,3])
- Parameters:
- {Vector|[Vectors]|Matrix} rhs
- vector of right hand sides. Array of vectors or Matrix as rhs is supported only with "gaussjordan" method
- {string} method Optional, Default: "default"
- method of the solution. Implemented methods are "default" and "gauss" for gaussian elimination, "gaussjordan" for Gauss-Jordan elimination (supporting more than one right hand sides in form of array of vectors or matrix with columns as rhs), "lu" for using LU decomposition, "ldu" for using LDU decomposition, "cholesky" for using Cholesky decomposition, "qr" for using QR decomposition
- {bool} saveOrig Optional, Default: true
- if true, receiver and rhs is not changed. If false, solution will be saved to rhs and rhs will be returned and receiver will be changed
- {[Matrices]} precompDecomps Optional, Default: undefined
- array of Matrices objects, used for solution using matrix decomposition as precomputed values (the decomposition is performed within linSolve function if args parameter is not specified)
- Returns:
- {Vector|[Vectors]|Matrix} vector/array of vectors/matrix of solution
lltDecomposition()
Alias for Cholesky decomposition, see Matrix#choleskyDecomposition
Returns lower (L) and upper (U) triangular matrix of the receiver such that L*U=this. Diagonal elements of L are all 1. Receiver must be square.
a = mat([[6,5,4],[12,13,10],[18,27,21]]); lu = a.luDecomposition(); l = lu[0]; // l = Matrix([[1,0,0],[2,1,0],[3,4,1]]) u = lu[1]; // u = Matrix([[6,5,4],[0,3,2],[0,0,1]]) check = l.x(u); // check = Matrix([[6,5,4],[12,13,10],[18,27,21]])
- Parameters:
- {string} pivoting Optional, Default: "default"
- what type of pivoting to use. "default" and "nopivot" stands for no pivoting, "partpivot" for implicit partial pivoting (only row interchanges)
Returns product of receiver and given multiplier (Matrix, Vector or float)
m1 = mat([[1,2,3],[4,5,6]]); m2 = m1.mul(3); // m2 = Matrix([[3,6,9],[12,15,18]]) // m3 = mat([[11,12,13],[21,22,23],[31,32,33]]); v1 = vec([1,2,3]); v2 = m3.mul(v1) // v2 = Vector([74,134,194]); // m4 = mat([[11,12],[21,22]]); m5 = mat([[1,2],[3,4]]); m6 = m4.mul(m5); // m6 = Matrix([[47,70],[87,130]])
{Matrix}
mulf(f)
Returns receiver multiplied by float f ( ret = this * f )
m1 = mat([[1,2,3],[4,5,6]]); m2 = m1.mulf(3); // m2 = Matrix([[3,6,9],[12,15,18]])
- Parameters:
- {float} f
- float multiplier
- Returns:
- {Matrix} copy of receiver multiplied by f
{Matrix}
mulm(mat)
Returns product of receiver and given matrix ( ret = this * mat )
m1 = mat([[11,12],[21,22]]); m2 = mat([[1,2],[3,4]]); m3 = m1.mulm(m2); // m3 = Matrix([[47,70],[87,130]])
- Parameters:
- {Matrix} mat
- matrix to multiply
- Returns:
- {Matrix} copy of receiver multiplied by mat
{Vector}
mulv(vec)
Returns product of receiver and given vector ( ret = this * vec )
m = mat([[11,12,13],[21,22,23],[31,32,33]]); v1 = vec([1,2,3]); v2 = m.mulv(v1); // v2 = Vector([74,134,194])
- Parameters:
- {Vector} vec
- vector to multiply
- Returns:
- {Vector} copy of receiver multiplied by vec
neg()
Alias for neageted(), see Matrix#negated
negate()
Negate receiver ( ret *= -1., ret = -ret )
m1 = mat([[1,2,3],[4,5,6]]); m1.negate(); // m1 = Matrix([[-1,-2,-3],[-4,-5,-6]])
{Matrix}
negated()
Returns negative of receiver ( ret = -this )
m1 = mat([[1,2,3],[4,5,6]]); m2 = m1.negated(); // m2 = Matrix([[-1,-2,-3],[-4,-5,-6]])
- Returns:
- {Matrix} negative of receiver
one()
Alias for beFullOfOnes(), see Matrix#beFullOfOnes
<static>
{Matrix}
Matrix.Ones(nRows, nCols)
Creates a matrix of given size full of ones
m = Matrix.Ones(2,3); // m = Matrix([[1,1,1],[1,1,1]])
- Parameters:
- {int} nRows Optional, Default: 0
- number of rows
- {int} nCols Optional, Default: 0
- number of columns
- Returns:
- {Matrix} new vector full of zero
permuteRows(coeffs, backward)
Permute rows of receiver according to given coefficients
m = mat([[11,12,13],[21,22,23],[31,32,33]]); m.permuteRows([1,2,0]); // m = Matrix([[21,22,23],[31,32,33],[11,12,13]]) m.permuteRows([1,2,0],true); // m = mat([[11,12,13],[21,22,23],[31,32,33]])
- Parameters:
- {[ints]|Vector} coeffs
- coefficients of row permutation
- {bool} backward Optional, Default: false
- if false, receiver's rows is permutated to given coefficients (forward). If true, from given coefficients (backward)
Returns orthogonal matrix R and symmetric matrix U of polar decomposition of the receiver such that this=R*U. The decomposition is computed from SVD decomposition (this = U*S*V^T -> R = U*V^T, U = V*S*V^T
m = mat([[1.6,.6,0],[-1.2,0.8,0],[0,0,3]]) ru = m.polarDecomposition(); r = ru[0]; // r = Matrix([[0.8,0.6,0],[-0.6,0.8,0],[0,0,1]]) u = ru[1]; // u = Matrix([[2,0,0],[0,1,0],[0,0,3]]) b1 = r.isOrthogonal(); // b1 = true b2 = u.isSymmetric(); // b2 = true c = r.mulm(u); // c = Matrix([[1.6,.6,0],[-1.2,0.8,0],[0,0,3]])
- Parameters:
- {[Matrix|Matrix|Matrix]} precompSvd Optional, Default: undefined
- precomputed SVD decomposition
- Returns:
- {[Matrix|Matrix]} [R,U] orthogonal matrix R and symmetric matrix U of polar decomposition of receiver
resize(nRows, nCols)
Resize receiver according to given size (delete extra elements or add zero elements)
m1 = mat([[11,12,13,14],[21,22,23,24],[31,32,33,34],[41,42,43,44]]); m2 = mat([[11,12],[21,22]]); m1.resize(3,3); // m1 = Matrix([[11,12,13],[21,22,23],[31,32,33]]) m2.resize(3,3); // m2 = Matrix([[11,12,0],[21,22,0],[0,0,0]])
- Parameters:
- {int} nRows
- new number of rows
- {int} nCols
- new number of columns
{Matrix}
resized(nRows, nCols)
Returns resized copy of receiver according to given size (delete extra elements or add zero elements)
m1 = mat([[11,12,13],[21,22,23],[31,32,33]]); m2 = m1.resized(2,4); // m2 = Matrix([[11,12,13,0],[21,22,23,0]]) m3 = m1.resized(4,2); // m3 = Matrix([[11,12],[21,22],[31,32],[0,0]])
- Parameters:
- {int} nRows
- new number of rows
- {int} nCols
- new number of columns
- Returns:
- {Matrix} resized copy of receiver
{Matrix}
rowPermutation(coeffs, backward)
Returns copy of receiver with rows permutated according to given coefficients
m1 = mat([[11,12,13],[21,22,23],[31,32,33]]); m2 = m1.rowPermutation([1,2,0]); // m2 = Matrix([[21,22,23],[31,32,33],[11,12,13]]) m3 = m1.rowPermutation([1,2,0],true); // m3 = mat([[31,32,33],[11,12,13],[21,22,23]])
- Parameters:
- {[ints]|Vector} coeffs
- coefficients of permutation.
- {bool} backward Optional, Default: false
- if false, receiver is permutated to given coefficients (forward). If true, from given coefficients (backward)
- Returns:
- {Matrix} copy of receiver with permutated rows
returns orthogonal matrix Q and upper triangular matrix S as Schur decomposition of receiver such that this=Q*S*Q^-1. Columns of Q are eigenvectors of receiver and diagonal elements of S are eigenvalues of receiver
m1 = mat([[4,2,3,1],[3,6,5,7],[5,3,8,1],[2,3,4,5]]); qs = m1.schurDecomposition(); q = qs[0]; s = qs[1]; // s = Matrix([[ 15.6072, -3.6605, -0.7006, 2.3149 ], [ 0, 4.1916, 3.3807, 2.0775 ], [ 0, 0, 2.2012, 0.0769 ], [ 0, 0, 0, 1 ]]) qr = s.qrDecomposition(); q1 = qr[0]; r = qr[1]; // q1 = Matrix([[ 1, 0, 0, 0 ], [ 0, 1, 0, 0 ], [ 0, 0, 1, 0 ], [ 0, 0, 0, 1 ]]) // r = Matrix([[ 15.6072, -3.6605, -0.7006, 2.3149 ], [ 0, 4.1916, 3.3807, 2.0775 ], [ 0, 0, 2.2012, 0.0769 ], [ 0, 0, 0, 1 ]]) b1 = q.isOrthogonal() // b1 = true b2 = s.isUpperTriangular() // b2 = true c = q.mulm(s).mulm(q.inv()); // c = Matrix([[4,2,3,1],[3,6,5,7],[5,3,8,1],[2,3,4,5]])
- Parameters:
- {bool} saveOrig Optional, Default: true
- if true, returns new matrices, if false, S is formed into original matrix
- {int} maxiter Optional, Default: 1000
- maximum number of iterations
{Matrix}
schurForm(saveOrig, maxiter)
returns Schur form of receiver (upper triangular matrix with eigenvalues of the receiver on the diagonal). QR algorithm is used for calculation
m1 = mat([[4,2,3,1],[3,6,5,7],[5,3,8,1],[2,3,4,5]]); m2 = m1.schurForm(); // m2 = Matrix([[ 15.6072, -3.6605, -0.7006, 2.3149 ], [ 0, 4.1916, 3.3807, 2.0775 ], [ 0, 0, 2.2012, 0.0769 ], [ 0, 0, 0, 1 ]]) b = m2.isUpperTriangular(); // b = true
- Parameters:
- {bool} saveOrig Optional, Default: true
- if true, returns new matrix, if false the Schur form is formed on original matrix
- {int} maxiter Optional, Default: 1000
- maximum number of iterations
- Returns:
- {Matrix} Schur form of receiver (upper triangular matrix with eigenvalues on diagonal)
set(r, c, val)
Coefficient access function, sets one element of receiver ( this[r][c] = val ). Matrix.set(r,c,val) is much safer than direct Matrix[r][c]=val access method
m = mat([[11,12,13],[21,22,23],[31,32,33]]); m.set(1,2,3.45); // m = Matrix([[11,12,13],[21,22,3.45],[31,32,33]]) m[1][2] = 3.45; // m = Matrix([[11,12,13],[21,22,3.45],[31,32,33]]) m = mat([[11,12,13],[21,22,23],[31,32,33]]); /// c out of bounds (nothing is done by both appraches) m.set(1,5,8.45); // m = Matrix([[11,12,13],[21,22,3.45],[31,32,33]]) m[1][5] = 8.45; // m = Matrix([[11,12,13],[21,22,3.45],[31,32,33]]) /// r out of bounds m.set(6,5,8.45); // m = Matrix([[11,12,13],[21,22,3.45],[31,32,33]]) /// m[6][5] = 8.45; would be error (m[6] is not defined)
- Parameters:
- {int} r
- index of row of element to be set
- {int} c
- index of column of element to be set
- {float} val
- value to be set
setCol(c, vec)
Sets one column of receiver
m = mat([[1,2,3],[4,5,6],[7,8,9]]); m.setCol(1,vec([11,12,13])); // m = Matrix([[1,11,3],[4,12,6],[7,13,9]])
- Parameters:
- {int} c
- index of column to set
- {Vector} vec
- vector to be set as new c-th column
setRow(r, vec)
Sets one row of receiver
mat([[1,2,3],[4,5,6],[7,8,9]]); m.setRow(1,vec([11,12,13])); // m = Matrix([[1,2,3],[11,12,13],[7,8,9]])
- Parameters:
- {int} r
- index of row to set
- {Vector} vec
- vector to be set as new r-th row
setsm()
Alias for setSubMatrix, see Matrix#setSubMatrix
setSubMatrix(rows, cols, mat)
Sets submatrix at defined positions of receiver ( this[rows][cols] = mat )
m = mat([[11,12,13,14],[21,22,23,24],[31,32,33,34],[41,42,43,44]]); m.setSubMatrix([1,2],[0,2],mat([[66,77],[88,99]])); // m = Matrix([[11,12,13,14],[66,22,77,24],[88,32,99,34],[41,42,43,44]])
- Parameters:
- {[floats]|Vector} rows
- array containing rows coefficients to be set
- {[floats]|Vector} cols
- array containing columns coefficients to be set
- {Matrix} mat
- matrix to be set on desired positions
Returns orthogonal matrix U, diagonal matrix S and orthogonal matrix V of singular value decomposition (SVD) of receiver such that this = U*S*V^T. U is computed as orthonormalized iegenvectors of this^T*this, V as orhonormalized eigenvectors of this*this^T and diagonal components of S as square roots of eigenvalues of this^T*this (TODO faster algorithm). this*V = U*S, A^T*U = V*S. Current implementation allows only square matrices (TODO gegeral-shape dmatrices)
m1 = mat([[3,2,1],[2,5,2],[1,2,6]]); m1 = mat([[1.6,0.6,0.],[-1.2,0.8,0.],[0.,0.,3.]]) svd = m1.singularValueDecomposition(); u = svd[0]; // u = Matrix([[0.6,0.8,0],[0.8,-0.6,0],[0,0,1]]) s = svd[1]; // s = Vector([1,2,3]) v = svd[2]; // v = Matrix([[0,1,0],[1,0,0],[0,0,1]]) b1 = u.isOrthogonal() // b1 = true b2 = v.isOrthogonal() // b2 = true c = u.mulm(s.diag()).mulm(v.transposed()); // c = mat([[1.6,0.6,0.],[-1.2,0.8,0.],[0.,0.,3.]])
- Returns:
- {[Matrix|Vector|Matrix]} [U,S,V] orthogonal matrix U, diagonal of matrix S and orthogonal matrix V of svd decomposition of receiver
{[int|int]}
size()
Returns size of receiver as [nRows,nCols]
m = mat([[1,2,3],[4,5,6]]); s = m.size(); // s = [2,3]
- Returns:
- {[int|int]} size of receiver
spectralDecomposition()
Returns spectral decomposition of receiver, identical to Matrix#eigenDecomposition
{Matrix}
sub(mat)
Returns difference of receiver and matrix ( ret = this - mat )
m1 = mat([[1,2],[3,4]]); m2 = mat([[2,5],[3,2]]); m3 = m1.sub(m2); // m3 = Matrix([[-1,-3],[0,2]])
- Parameters:
- {Matrix} mat
- matrix to be added
- Returns:
- {Matrix} sum of receiver and matrix
svd()
Alias for singular value decomposition, see Matrix.singularValueDecomposition
swapCols(c1, c2)
Swaps two columns of receiver
m = mat([[11,12,13],[21,22,23],[31,32,33]]); m.swapCols(0,2); // m = Matrix([[13,12,11],[23,22,21],[33,32,31]])
- Parameters:
- {int} c1
- index of first row to swap
- {int} c2
- index of second row to swap
swapRows(r1, r2)
Swaps two rows of receiver
m = mat([[11,12,13],[21,22,23],[31,32,33]]); m.swapRows(0,2); // m = Matrix([[31,32,33],[21,22,23],[11,12,13]])
- Parameters:
- {int} r1
- index of first row to swap
- {int} r2
- index of second row to swap
symmetrize()
Symmetrize receiver ( this = .5*(this+this^T) ). Receiver must be square
m = mat([[1,2,3],[0,-1,5],[-1,1,7]]) m.symmetrize(); // m = Matrix([[1,1,1],[1,-1,3],[1,3,7]])
symmetrized()
Returns symmetric part of receiver ( ret = .5*(this+this^T) ). Receiver must be square
m1 = mat([[1,2,3],[0,-1,5],[-1,1,7]]) m2 = m1.symmetrized(); // m2 = Matrix([[1,1,1],[1,-1,3],[1,3,7]])
T()
Alias for transposed(), see Matrix#transposed
{[floats](2D)}
toArray()
Returns elements of receiver as an Array object
m =mat([[11,12],[21,22]]); a = m.toArray(); // a = [[11,12],[21,22]]
- Returns:
- {[floats](2D)} array containing receiver's elements
{string}
toString()
Returns string representation of receiver
m = mat([[1,2,3],[4,5,6],[7,8,9]]); s = m.toString(); // s = 'Matrix([[1,2,3],[4,5,6],[7,8,9]])'
- Returns:
- {string} string representation of receiver
{float}
trace()
Returns trace (sum of diagonal elements) of the receiver
m = mat([[1,2,3],[4,5,6],[7,8,9]]) tr = m.trace() // tr = 15
- Returns:
- {float} trace of the receiver
transpose()
Modifies receiver to become transposition of itself ( this = this^T )
m = mat([[1,2,3],[4,5,6]]); m.transpose(); // m = Matrix([[1,4],[2,5],[3,6]]) m.transpose(); // m = Matrix([[1,2,3],[4,5,6]])
{Matrix}
transposed()
Returns transposition of receiver ( ret = this^T )
m1 = mat([[1,2,3],[4,5,6]]); m2 = m1.transposed(); // m2 = Matrix([[1,4],[2,5],[3,6]])
- Returns:
- {Matrix} transposed copy of receiver
<static>
Matrix.UnitMatrix()
Alias for Matrix.Identity(), see Matrix#Identity
x()
Alias for mul(), see Matrix#mul
zero()
Zeroes all elements of receiver
m = mat([[1,2,3],[4,5,6],[7,8,9]]); m.zero(); // m = Matrix([[0,0,0],[0,0,0],[0,0,0]])
<static>
{Matrix}
Matrix.Zeros(nRows, nCols)
Creates a matrix of given size full of zeros
m = Matrix.Zeros(2,3); // m = Matrix([[0,0,0],[0,0,0]])
- Parameters:
- {int} nRows Optional, Default: 0
- number of rows
- {int} nCols Optional, Default: 0
- number of columns
- Returns:
- {Matrix} new matrix full of zero