Single or multi dimensional matrices and matrix functions.
Run npm install --save @smockle/matrix
to add matrix
to your project.
import Matrix from '@smockle/matrix'
// 1x1 Matrix
const m11 = Matrix([3])
// 1x3 Matrix
const m13 = Matrix([1, 2, 3])
// 3x1 Matrix
const m31 = Matrix([[1], [2], [3]])
- matrix
- Matrix ⏏
- new Matrix(x)
- instance
- .countRows() ⇒
number
- .countColumns() ⇒
number
- .addable(y) ⇒
boolean
- .add(y) ⇒
Matrix
- .multipliable(y) ⇒
boolean
- .multiply(y) ⇒
Matrix
- .transpose() ⇒
Matrix
- .invert() ⇒
Matrix
- .map() ⇒
Matrix
- .valueOf() ⇒
number
|Array.<number>
- .inspect() ⇒
string
- ~padding :
string
- ~padding :
- .countRows() ⇒
- static
- .addable(x, y) ⇒
boolean
- .add(x, y) ⇒
Matrix
- .multipliable(x, y) ⇒
boolean
- .multiply(x, y) ⇒
Matrix
- ~z :
Matrix
- ~z :
- .invert(Matrix) ⇒
Matrix
- .addable(x, y) ⇒
- inner
- ~matrix :
Matrix
- ~innerproduct(x, y, i) ⇒
number
- ~matrix :
- Matrix ⏏
Creates a Matrix
Returns: Matrix
- Single or multi dimensional matrix
Throws:
TypeError
Argument x must be a number or number array
Param | Type | Description |
---|---|---|
x | number | Array.<number> |
Values to store in matrix |
Counts rows in this matrix
Kind: instance method of Matrix
Returns: number
- Number of rows
Counts columns in this matrix
Kind: instance method of Matrix
Returns: number
- Number of columns
Determines whether this matrix can be summed
Kind: instance method of Matrix
Returns: boolean
- Whether this matrix can be summed (using matrix addition)
Param | Type | Description |
---|---|---|
y | Matrix |
Matrix to check |
Adds this matrix using matrix addition
Kind: instance method of Matrix
Returns: Matrix
- New matrix with the summation
Param | Type | Description |
---|---|---|
y | Matrix |
Matrix to add |
Determines whether this matrix can be multiplied
Kind: instance method of Matrix
Returns: boolean
- Whether two matrices can be summed (using matrix multiplication)
Param | Type | Description |
---|---|---|
y | Matrix |
Matrix to check |
Calculates the dot product of this matrix
Kind: instance method of Matrix
Returns: Matrix
- New matrix with the dot product
Param | Type | Description |
---|---|---|
y | Matrix |
Matrix to multiply |
Calculates the transpose of this matrix
Kind: instance method of Matrix
Returns: Matrix
- New matrix with the transpose
Inverts this matrix
Kind: instance method of Matrix
Returns: Matrix
- Matrix inverse
Maps over this matrix
Kind: instance method of Matrix
Returns: Matrix
- Matrix inverse
Returns the number or number array value
Kind: instance method of Matrix
Returns: number
| Array.<number>
- Number of number array value
Formats and prints the matrix value
Kind: instance method of Matrix
Returns: string
- Formatted matrix value
Output array filled with zeroes
Kind: inner constant of inspect
Determines whether two matrices can be summed
Kind: static method of Matrix
Returns: boolean
- Whether two matrices can be summed (using matrix addition)
Param | Type | Description |
---|---|---|
x | Matrix |
Matrix to check |
y | Matrix |
Matrix to check |
Adds two matrices using matrix addition
Kind: static method of Matrix
Returns: Matrix
- New matrix with the summation
Throws:
TypeError
Matrices are not addable
Param | Type | Description |
---|---|---|
x | Matrix |
Matrix to add |
y | Matrix |
Matrix to add |
Determines whether two matrices can be multiplied
Kind: static method of Matrix
Returns: boolean
- Whether two matrices can be summed (using matrix multiplication)
Param | Type | Description |
---|---|---|
x | Matrix |
Matrix to check |
y | Matrix |
Matrix to check |
Calculates the dot product of two matrices
Kind: static method of Matrix
Returns: Matrix
- New matrix with the dot product
Param | Type | Description |
---|---|---|
x | Matrix |
Matrix to multiply |
y | Matrix |
Matrix to multiply |
New matrix with the dot product
Kind: inner constant of multiply
Inverts a matrix
Kind: static method of Matrix
Returns: Matrix
- Matrix inverse
Param | Type | Description |
---|---|---|
Matrix | x |
to invert |
Single or multi dimensional matrix
Kind: inner constant of Matrix
Calculates the inner product of two matrices
Kind: inner method of Matrix
Returns: number
- Inner product of matrices
Param | Type | Description |
---|---|---|
x | Matrix |
Matrix to multiply |
y | Matrix |
Matrix to multiply |
i | number |
Column in matrix y to multiply |
matrix
includes several unit tests. After cloning the matrix
repo locally, run npm install
in the project folder to install dependencies. Run npm test
to execute the tests.