Hide menu
Loading...
Searching...
No Matches
Matrix

Base class for square matrices of arbitrary size.

Extended by

Constructors

Constructor

new Matrix(dimension): Matrix

Creates an identity matrix of the specified dimension.

Parameters

dimension

number

Matrix dimension.

Returns

Matrix

Properties

dimension

readonly dimension: number

Matrix dimension.

Accessors

elements

Get Signature

get elements(): number[]

Returns the matrix elements in row-major order.

Returns

number[]

Set Signature

set elements(elements): void

Sets the matrix elements from an array in row-major order.

Throws a RangeError if elements.length is not equal to dimension * dimension.

Parameters

elements

number[]

Matrix elements in row-major order.

Returns

void

Methods

add()

add(other): this

Adds the elements of other to this matrix.

Throws a RangeError if other.dimension is not equal to this.dimension.

Parameters

other

Matrix

Other matrix.

Returns

this


added()

added(other): Matrix

Returns a new matrix resulting from adding other to this matrix.

Parameters

other

Matrix

Other matrix.

Returns

Matrix


clone()

abstract clone(): Matrix

Creates a new matrix with the same elements as this matrix.

Returns

Matrix


column()

column(column): number[]

Returns the elements of column.

Throws a RangeError if column is outside the valid range.

Parameters

column

number

Column index.

Returns

number[]


copy()

copy(other): this

Copies the elements of other to this matrix.

Throws a RangeError if other.dimension is not equal to this.dimension.

Parameters

other

Matrix

Matrix to copy.

Returns

this


determinant()

abstract determinant(): number

Returns the determinant of this matrix.

Returns

number


diagonal()

diagonal(): number[]

Returns the diagonal elements.

Returns

number[]


divide()

divide(scalar): this

Divides the elements of this matrix by scalar.

Parameters

scalar

number

Scalar.

Returns

this


divided()

divided(scalar): Matrix

Returns a new matrix resulting from dividing this matrix by scalar.

Parameters

scalar

number

Scalar.

Returns

Matrix


fill()

fill(value): this

Fills the matrix with value.

Parameters

value

number

Value to fill matrix.

Returns

this


get()

get(index): number

Returns the element at index in the row-major array representation.

Throws a RangeError if index is outside the valid range.

Parameters

index

number

Element index in row-major order.

Returns

number


invert()

abstract invert(): this

Inverts this matrix.

Returns

this


inverted()

inverted(): Matrix

Returns a new matrix resulting from inverting this matrix.

Returns

Matrix


isEqual()

isEqual(other, tolerance?): boolean

Returns whether other has the same dimension as this matrix and all corresponding elements are equal within tolerance.

Parameters

other

Matrix

Other matrix.

tolerance?

number = Matrix.coincidenceTolerance

Comparison tolerance. The default is 1e-7.

Returns

boolean


isIdentity()

isIdentity(): boolean

Returns whether this matrix is the identity matrix.

Returns

boolean


isSingular()

isSingular(): boolean

Returns whether the determinant of this matrix is close to 0.

Returns

boolean


multiplied()

Call Signature

multiplied(other): Matrix

Returns a new matrix resulting from multiplying this matrix by other.

Parameters

other

Matrix

Other matrix.

Returns

Matrix

Call Signature

multiplied(scalar): Matrix

Returns a new matrix resulting from multiplying this matrix by scalar.

Parameters

scalar

number

Scalar.

Returns

Matrix


multiply()

Call Signature

multiply(other): this

Multiplies this matrix by other.

Throws a RangeError if this.dimension and other.dimension are not equal.

Parameters

other

Matrix

Other matrix.

Returns

this

Call Signature

multiply(scalar): this

Multiplies the elements of this matrix by scalar.

Parameters

scalar

number

Scalar.

Returns

this


power()

power(num): this

Raises this matrix to the power num.

Parameters

num

number

Power value.

Returns

this


powered()

powered(num): Matrix

Returns a new matrix resulting from raising this matrix to the power num.

Parameters

num

number

Power value.

Returns

Matrix


reset()

reset(): this

Resets this matrix to the identity matrix.

Returns

this


row()

row(row): number[]

Returns the elements of row.

Throws a RangeError if row is outside the valid range.

Parameters

row

number

Row index.

Returns

number[]


set()

set(index, value): this

Sets the element at index in the row-major array representation.

Throws a RangeError if index is outside the valid range.

Parameters

index

number

Element index in row-major order.

value

number

Element value.

Returns

this


setColumn()

setColumn(column, elements): this

Sets the elements of column.

Throws a RangeError if column is outside the valid range or elements.length is not equal to dimension.

Parameters

column

number

Column index.

elements

number[]

Column elements.

Returns

this


setDiagonal()

setDiagonal(elements): this

Sets the diagonal elements.

Throws a RangeError if elements.length is not equal to dimension.

Parameters

elements

number[]

Diagonal elements.

Returns

this


setElements()

setElements(elements): this

Sets the matrix elements from an array in row-major order.

Throws a RangeError if elements.length is not equal to dimension * dimension.

Parameters

elements

number[]

Matrix elements in row-major order.

Returns

this


setRow()

setRow(row, elements): this

Sets the elements of row.

Throws a RangeError if row is outside the valid range or elements.length is not equal to dimension.

Parameters

row

number

Row index.

elements

number[]

Row elements.

Returns

this


setScale()

setScale(scale): this

Resets this matrix to a diagonal scale matrix with scale on the diagonal.

Parameters

scale

number

Scale value.

Returns

this


setValue()

setValue(row, column, value): this

Sets the value at [row][column].

Throws a RangeError if row or column is outside the valid range.

Parameters

row

number

Row index.

column

number

Column index.

value

number

New value.

Returns

this


subtract()

subtract(other): this

Subtracts the elements of other from this matrix.

Throws a RangeError if other.dimension is not equal to this.dimension.

Parameters

other

Matrix

Other matrix.

Returns

this


subtracted()

subtracted(other): Matrix

Returns a new matrix resulting from subtracting other from this matrix.

Parameters

other

Matrix

Other matrix.

Returns

Matrix


toString()

toString(precision?): string

Returns a string representation of this matrix with the provided precision.

Parameters

precision?

number = 3

Precision.

Returns

string


transpose()

transpose(): this

Transposes this matrix.

Returns

this


transposed()

transposed(): Matrix

Returns a new matrix resulting from transposing this matrix.

Returns

Matrix


value()

value(row, column): number

Returns the value at [row][column].

Throws a RangeError if row or column is outside the valid range.

Parameters

row

number

Row index.

column

number

Column index.

Returns

number