Matrix¶
Overview¶
Arbitrary-dimensional matrix, based on Jama (http://math.nist.gov/javanumerics/jama/)
@author Jonathan Olson <jonathan.olson@colorado.edu>
Class Matrix¶
Constructor¶
new Matrix( m, n, filler, fast )¶
Instance Methods¶
copy()¶
@returns {Matrix}
getArray()¶
@returns {Array.<number>}
getArrayCopy()¶
@returns {Array.<number>}
getRowDimension()¶
@returns {number}
getColumnDimension()¶
@returns {number}
index( i, j )¶
TODO: inline this places if we aren't using an inlining compiler! (check performance) https://github.com/phetsims/dot/issues/96 @public
@param {number} i @param {number} j @returns {number}
get( i, j )¶
Get the matrix element (i,j) with the convention that row and column indices start at zero @public
@param {number} i - row index @param {number} j - column index @returns {number}
set( i, j, s )¶
Set the matrix element (i,j) to a value s with the convention that row and column indices start at zero @public
@param {number} i - row index @param {number} j - column index @param {number} s - value of the matrix element
getMatrix( i0, i1, j0, j1 )¶
@param {number} i0 @param {number} i1 @param {number} j0 @param {number} j1 @returns {Matrix}
getArrayRowMatrix( r, j0, j1 )¶
@param {Array.<number>} r @param {number} j0 @param {number} j1 @returns {Matrix}
transpose( result )¶
@param {Matrix} [result] - allow passing in a pre-constructed matrix @returns {Matrix}
norm1()¶
@returns {number}
norm2()¶
@returns {number}
normInf()¶
@returns {number}
normF()¶
@returns {number}
uminus()¶
@returns {Matrix}
plus( matrix )¶
@param {Matrix} matrix @returns {Matrix}
plusEquals( matrix )¶
@param {Matrix} matrix @returns {Matrix}
blendEquals( matrix, ratio )¶
A linear interpolation between this Matrix (ratio=0) and another Matrix (ratio=1). @public
@param {Matrix} matrix @param {number} ratio - Not necessarily constrained in [0, 1] @returns {Matrix}
minus( matrix )¶
@param {Matrix} matrix @returns {Matrix}
minusEquals( matrix )¶
@param {Matrix} matrix @returns {Matrix}
arrayTimes( matrix )¶
@param {Matrix} matrix @returns {Matrix}
arrayTimesEquals( matrix )¶
@param {Matrix} matrix @returns {Matrix}
arrayRightDivide( matrix )¶
@param {Matrix} matrix @returns {Matrix}
arrayRightDivideEquals( matrix )¶
@param {Matrix} matrix @returns {Matrix}
arrayLeftDivide( matrix )¶
@param {Matrix} matrix @returns {Matrix}
arrayLeftDivideEquals( matrix )¶
@param {Matrix} matrix @returns {Matrix}
times( matrixOrScalar )¶
@param {Matrix|number} matrixOrScalar @returns {Matrix}
timesEquals( s )¶
@param {number} s @returns {Matrix}
solve( matrix )¶
@param {Matrix} matrix @returns {Matrix}
solveTranspose( matrix )¶
@param {Matrix} matrix @returns {Matrix}
inverse()¶
@returns {Matrix}
det()¶
@returns {number}
rank()¶
@returns {number}
cond()¶
@returns {number}
trace()¶
@returns {number}
checkMatrixDimensions( matrix )¶
@param {Matrix} matrix
toString()¶
Returns a string form of this object @public
@returns {string}
extractVector2( column )¶
Returns a vector that is contained in the specified column @public
@param {number} column @returns {Vector2}
extractVector3( column )¶
Returns a vector that is contained in the specified column @public
@param {number} column @returns {Vector3}
extractVector4( column )¶
Returns a vector that is contained in the specified column @public
@param {number} column @returns {Vector4}
setVectors3( vectors )¶
Sets the current matrix to the values of the listed column vectors (Vector3). @public
@param {Array.<Vector3>} vectors @returns {Matrix}
Static Methods¶
hypot( a, b )¶
sqrt(a^2 + b^2) without under/overflow. @public
@param {number} a @param {number} b @returns {number}
identity( m, n )¶
Sets this matrix to the identity. @public
@param {number} m @param {number} n @returns {Matrix}
diagonalMatrix( diagonalValues )¶
Returns a square diagonal matrix, whose entries along the diagonal are specified by the passed-in array, and the other entries are 0. @public
@param {Array.<number>} diagonalValues @returns {Matrix}
rowVector2( vector )¶
@param {Vector2} vector @returns {Matrix}
rowVector3( vector )¶
@param {Vector3} vector @returns {Matrix}
rowVector4( vector )¶
@param {Vector4} vector @returns {Matrix}
rowVector( vector )¶
@param {Vector2|Vector3|Vector4} vector @returns {Matrix}
columnVector2( vector )¶
@param {Vector2} vector @returns {Matrix}
columnVector3( vector )¶
@param {Vector3} vector @returns {Matrix}
columnVector4( vector )¶
@param {Vector4} vector @returns {Matrix}
columnVector( vector )¶
@param {Vector2|Vector3|Vector4} vector @returns {Matrix}
fromVectors2( vectors )¶
Create a Matrix where each column is a vector @public
@param {Array.<Vector2>} vectors
fromVectors3( vectors )¶
Create a Matrix where each column is a vector @public
@param {Array.<Vector3>} vectors
fromVectors4( vectors )¶
Create a Matrix where each column is a vector @public
@param {Array.<Vector4>} vectors
Class EigenvalueDecomposition¶
Eigensystem decomposition, based on Jama (http://math.nist.gov/javanumerics/jama/)
Eigenvalues and eigenvectors of a real matrix. <P> If A is symmetric, then A = V*D*V' where the eigenvalue matrix D is diagonal and the eigenvector matrix V is orthogonal. I.e. A = V.times(D.times(V.transpose())) and V.times(V.transpose()) equals the identity matrix. <P> If A is not symmetric, then the eigenvalue matrix D is block diagonal with the real eigenvalues in 1-by-1 blocks and any complex eigenvalues, lambda + i*mu, in 2-by-2 blocks, [lambda, mu; -mu, lambda]. The columns of V represent the eigenvectors in the sense that A*V = V*D, i.e. A.times(V) equals V.times(D). The matrix V may be badly conditioned, or even singular, so the validity of the equation A = V*D*inverse(V) depends upon V.cond().
@author Jonathan Olson <jonathan.olson@colorado.edu>
Constructor¶
new EigenvalueDecomposition( matrix )¶
Instance Methods¶
getV()¶
Returns a square array of all eigenvectors arranged in a columnar format @public @returns {ArrayType.<number>} - a n*n matrix
getRealEigenvalues()¶
Returns an array that contains the real part of the eigenvalues @public @returns {ArrayType.<number>} - a one dimensional array
getImagEigenvalues()¶
Returns an array that contains the imaginary parts of the eigenvalues @public @returns {ArrayType.<number>} - a one dimensional array
getD()¶
Return the block diagonal eigenvalue matrix @public @returns {Matrix} - a n * n matrix
tred2()¶
Symmetric Householder reduction to tridiagonal form. @private
tql2()¶
Symmetric tridiagonal QL algorithm. @private
orthes()¶
Nonsymmetric reduction to Hessenberg form. @private
cdiv( xr, xi, yr, yi )¶
Complex scalar division. @private
@param {} xr @param {} xi @param {} yr @param {} yi
hqr2()¶
This methods finds the eigenvalues and eigenvectors of a real upper hessenberg matrix by the QR algorithm
Nonsymmetric reduction from Hessenberg to real Schur form. https://en.wikipedia.org/wiki/QR_algorithm
Class LUDecomposition¶
LU decomposition, based on Jama (http://math.nist.gov/javanumerics/jama/). Please note the arbitrary-precision copy LUDecompositionDecimal which should be maintained with this file.
@author Jonathan Olson <jonathan.olson@colorado.edu>
Constructor¶
new LUDecomposition( matrix )¶
Instance Methods¶
isNonsingular()¶
@returns {boolean}
getL()¶
@returns {Matrix}
getU()¶
@returns {Matrix}
getPivot()¶
@returns {Uint32Array}
getDoublePivot()¶
@returns {Float64Array}
det()¶
@returns {number}
solve( matrix )¶
@param {Matrix} matrix @returns {Matrix}
Class QRDecomposition¶
QR decomposition, based on Jama (http://math.nist.gov/javanumerics/jama/)
@author Jonathan Olson <jonathan.olson@colorado.edu>
Constructor¶
new QRDecomposition( matrix )¶
Instance Methods¶
isFullRank()¶
@returns {boolean}
getH()¶
@returns {Matrix}
getR()¶
@returns {Matrix}
getQ()¶
@returns {Matrix}
solve( matrix )¶
@param {Matrix} matrix @returns {Matrix}
Class SingularValueDecomposition¶
SVD decomposition, based on Jama (http://math.nist.gov/javanumerics/jama/)
@author Jonathan Olson <jonathan.olson@colorado.edu>
Constructor¶
new SingularValueDecomposition( matrix )¶
Instance Methods¶
getU()¶
@returns {Matrix}
getV()¶
@returns {Matrix}
getSingularValues()¶
@returns {Array.<number>}
getS()¶
@returns {Matrix}
norm2()¶
@returns {number}
cond()¶
@returns {number}
rank()¶
@returns {number}
Static Methods¶
pseudoinverse( matrix )¶
Constructs the Moore-Penrose pseudoinverse of the specified matrix, using the SVD construction. @public
See https://en.wikipedia.org/wiki/Moore%E2%80%93Penrose_pseudoinverse for details. Helpful for linear least-squares regression.
@param {Matrix} matrix, m x n @returns {Matrix} - n x m