Skip to content

Matrix

Overview

Arbitrary-dimensional matrix, based on Jama (http://math.nist.gov/javanumerics/jama/)

@author Jonathan Olson <jonathan.olson@colorado.edu>

Class Matrix

import { Matrix } from 'scenerystack/dot';

Constructor

new Matrix( m, n, filler, fast )

Instance Methods

copy()

@public

@returns {Matrix}

getArray()

@public

@returns {Array.<number>}

getArrayCopy()

@public

@returns {Array.<number>}

getRowDimension()

@public

@returns {number}

getColumnDimension()

@public

@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 )

@public

@param {number} i0 @param {number} i1 @param {number} j0 @param {number} j1 @returns {Matrix}

getArrayRowMatrix( r, j0, j1 )

@public

@param {Array.<number>} r @param {number} j0 @param {number} j1 @returns {Matrix}

transpose( result )

@public

@param {Matrix} [result] - allow passing in a pre-constructed matrix @returns {Matrix}

norm1()

@public

@returns {number}

norm2()

@public

@returns {number}

normInf()

@public

@returns {number}

normF()

@public

@returns {number}

uminus()

@public

@returns {Matrix}

plus( matrix )

@public

@param {Matrix} matrix @returns {Matrix}

plusEquals( matrix )

@public

@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 )

@public

@param {Matrix} matrix @returns {Matrix}

minusEquals( matrix )

@public

@param {Matrix} matrix @returns {Matrix}

arrayTimes( matrix )

@public

@param {Matrix} matrix @returns {Matrix}

arrayTimesEquals( matrix )

@public

@param {Matrix} matrix @returns {Matrix}

arrayRightDivide( matrix )

@public

@param {Matrix} matrix @returns {Matrix}

arrayRightDivideEquals( matrix )

@public

@param {Matrix} matrix @returns {Matrix}

arrayLeftDivide( matrix )

@public

@param {Matrix} matrix @returns {Matrix}

arrayLeftDivideEquals( matrix )

@public

@param {Matrix} matrix @returns {Matrix}

times( matrixOrScalar )

@public

@param {Matrix|number} matrixOrScalar @returns {Matrix}

timesEquals( s )

@public

@param {number} s @returns {Matrix}

solve( matrix )

@public

@param {Matrix} matrix @returns {Matrix}

solveTranspose( matrix )

@public

@param {Matrix} matrix @returns {Matrix}

inverse()

@public

@returns {Matrix}

det()

@public

@returns {number}

rank()

@public

@returns {number}

cond()

@public

@returns {number}

trace()

@public

@returns {number}

checkMatrixDimensions( matrix )

@public

@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 )

@public

@param {Vector2} vector @returns {Matrix}

rowVector3( vector )

@public

@param {Vector3} vector @returns {Matrix}

rowVector4( vector )

@public

@param {Vector4} vector @returns {Matrix}

rowVector( vector )

@public

@param {Vector2|Vector3|Vector4} vector @returns {Matrix}

columnVector2( vector )

@public

@param {Vector2} vector @returns {Matrix}

columnVector3( vector )

@public

@param {Vector3} vector @returns {Matrix}

columnVector4( vector )

@public

@param {Vector4} vector @returns {Matrix}

columnVector( vector )

@public

@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>

import { EigenvalueDecomposition } from 'scenerystack/dot';

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

@private

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>

import { LUDecomposition } from 'scenerystack/dot';

Constructor

new LUDecomposition( matrix )

Instance Methods

isNonsingular()

@public

@returns {boolean}

getL()

@public

@returns {Matrix}

getU()

@public

@returns {Matrix}

getPivot()

@public

@returns {Uint32Array}

getDoublePivot()

@public

@returns {Float64Array}

det()

@public

@returns {number}

solve( matrix )

@public

@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>

import { QRDecomposition } from 'scenerystack/dot';

Constructor

new QRDecomposition( matrix )

Instance Methods

isFullRank()

@public

@returns {boolean}

getH()

@public

@returns {Matrix}

getR()

@public

@returns {Matrix}

getQ()

@public

@returns {Matrix}

solve( matrix )

@public

@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>

import { SingularValueDecomposition } from 'scenerystack/dot';

Constructor

new SingularValueDecomposition( matrix )

Instance Methods

getU()

@public

@returns {Matrix}

getV()

@public

@returns {Matrix}

getSingularValues()

@public

@returns {Array.<number>}

getS()

@public

@returns {Matrix}

norm2()

@public

@returns {number}

cond()

@public

@returns {number}

rank()

@public

@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

Source Code

See the source for Matrix.js in the dot repository.