lnagb.js Documentation

SquareMatrix

Contains the SquareMatrix class, which is similar to the Matrix class but only encodes square matrices.

Author: Zach / cszach@proton.me


SquareMatrix~SquareMatrix ⇐ Matrix

Encodes square matrices.

Kind: inner class of SquareMatrix
Extends: Matrix


new SquareMatrix(size, entries)

Constructs a SquareMatrix instance.

entries is optional. If not given, the constructor will create a zero square matrix.

Param Type Description
size number The number of rows (or columns) for the new matrix.
entries Array.<number> The entries in row-major order for the new matrix.

squareMatrix.size : object

Contains the dimensions of this matrix as an object in the form { rows, columns }.

Kind: instance property of SquareMatrix
Overrides: size


squareMatrix.numberOfEntries : number

The number of entries in this matrix.

Kind: instance property of SquareMatrix
Overrides: numberOfEntries


squareMatrix.elements : Array.<number>

Stores the elements of this matrix in row-major order.

Kind: instance property of SquareMatrix
Overrides: elements


squareMatrix.rows ⇒ Array.<Array>

Returns the rows of this matrix in an array.

Kind: instance property of SquareMatrix
Overrides: rows
Returns: Array.<Array> - The rows in this matrix


squareMatrix.columns ⇒ Array.<Array>

Returns the columns of this matrix in an array.

Kind: instance property of SquareMatrix
Overrides: columns
Returns: Array.<Array> - The columns in this matrix


squareMatrix.mainDiagonal ⇒ Array.<number>

Returns the main diagonal of this matrix.

Kind: instance property of SquareMatrix
Overrides: mainDiagonal
Returns: Array.<number> - The entries in the main diagonal of this matrix


squareMatrix.identity() ⇒ SquareMatrix

Makes this square matrix an identity matrix.

Kind: instance method of SquareMatrix
Returns: SquareMatrix - This matrix


squareMatrix.clone() ⇒ Matrix

Creates and returns a clone of this matrix instance.

Kind: instance method of SquareMatrix
Overrides: clone
Returns: Matrix - A clone of this instance


squareMatrix.equals(matrix) ⇒ boolean

Checks if this matrix and another matrix are equal.

Kind: instance method of SquareMatrix
Overrides: equals
Returns: boolean - true if the two matrices are equal, false otherwise

Param Type Description
matrix Matrix The matrix to compare this matrix to.

squareMatrix.entry(i, j) ⇒ number

Returns the entry in the specified row and column in this matrix.

Kind: instance method of SquareMatrix
Overrides: entry
Returns: number - The entry

Param Type Description
i number The row that contains the entry (1-indexed).
j number The column that contains the entry (1-indexed).

squareMatrix.row(r) ⇒ Array.<number>

Returns a row in this matrix as a JavaScript array.

Kind: instance method of SquareMatrix
Overrides: row
Returns: Array.<number> - The row’s entries

Param Type Description
r number Row number (1-indexed).

squareMatrix.column(c) ⇒ Array.<number>

Returns a column in this matrix as a JavaScript array.

Kind: instance method of SquareMatrix
Overrides: column
Returns: Array.<number> - The column’s entries

Param Type Description
c number Column number (1-indexed).

squareMatrix.leadingCoefficient(r) ⇒ number

Returns the leading coefficient of a row, or undefined if the row does not have a leading coefficient.

Kind: instance method of SquareMatrix
Overrides: leadingCoefficient
Returns: number - The leading coefficient of the row

Param Type Description
r number Row number (1-indexed).

squareMatrix.forEach(callback, thisArg)

Executes a function for each entry in this matrix. Entries are iterated in row-major order.

Kind: instance method of SquareMatrix
Overrides: forEach

Param Type Description
callback forEach The function to execute per iteration.
thisArg object The argument to use as this in the function.

squareMatrix.forEachRow(callback, thisArg)

Executes a function for each row in this matrix.

Kind: instance method of SquareMatrix
Overrides: forEachRow

Param Type Description
callback forEachRow The function to execute per iteration.
thisArg object The argument to use as this in the function.

squareMatrix.forEachColumn(callback, thisArg)

Executes a function for each column in this matrix.

Kind: instance method of SquareMatrix
Overrides: forEachColumn

Param Type Description
callback forEachColumn The function to execute per iteration.
thisArg object The argument to use as this in the function.

squareMatrix.interchargeRows(r, s) ⇒ Matrix

Intercharges two rows in this matrix.

Kind: instance method of SquareMatrix
Overrides: interchargeRows
Returns: Matrix - This matrix

Param Type Description
r number First row number (1-indexed).
s number Second row number (1-indexed).

squareMatrix.multiplyRowByScalar(r, k) ⇒ Matrix

Multiplies a row in this matrix by a nonzero scalar.

Kind: instance method of SquareMatrix
Overrides: multiplyRowByScalar
Returns: Matrix - This matrix

Param Type Description
r number Row number (1-indexed).
k number The nonzero scalar to multiply the row by.

squareMatrix.addRowTimesScalarToRow(r, s, k) ⇒ Matrix

Adds multiples of a row to another row in this matrix.

Kind: instance method of SquareMatrix
Overrides: addRowTimesScalarToRow
Returns: Matrix - This matrix

Param Type Default Description
r number   The row that gets added (1-indexed position).
s number   The row to multiply the scalar by and then add to row r (1-indexed position).
k number 1 The scalar to multiply row s by.

squareMatrix.transpose() ⇒ Matrix

Transposes this matrix in place.

Kind: instance method of SquareMatrix
Overrides: transpose
Returns: Matrix - This matrix
Todo


squareMatrix.multiplyScalar(k) ⇒ Matrix

Multiplies this matrix by a scalar.

Kind: instance method of SquareMatrix
Overrides: multiplyScalar
Returns: Matrix - This matrix

Param Type Description
k number The scalar to multiply this matrix by.

squareMatrix.negate() ⇒ Matrix

Multiplies this matrix by -1.

Kind: instance method of SquareMatrix
Overrides: negate
Returns: Matrix - This matrix


squareMatrix.add(matrix) ⇒ Matrix

Adds a matrix to this matrix.

Kind: instance method of SquareMatrix
Overrides: add
Returns: Matrix - This matrix

Param Type Description
matrix Matrix The matrix to add to this matrix.

squareMatrix.sub(matrix) ⇒ Matrix

Subtracts a matrix from this matrix.

Kind: instance method of SquareMatrix
Overrides: sub
Returns: Matrix - This matrix

Param Type Description
matrix Matrix The matrix to subtract this matrix to.

squareMatrix.multiply(matrix) ⇒ Matrix

Multiplies this matrix by another matrix. If the input matrix is not compatible for multiplication, return this matrix unchanged.

Kind: instance method of SquareMatrix
Overrides: multiply
Returns: Matrix - This matrix

Param Type Description
matrix Matrix The matrix to post-multiply this matrix to.