README
matrix
Single or multi dimensional matrices and matrix functions.
Installation
Run npm install --save @smockle/matrix
to add matrix
to your project.
Usage
const Matrix = require('@smockle/matrix')
// 1x1 Matrix
const m11 = Matrix(3)
// 1x3 Matrix
const m13 = Matrix([1, 2, 3])
// 3x1 Matrix
const m31 = Matrix([[1], [2], [3]])
API Reference
- 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 ⏏
Matrix ⏏
new Matrix(x)
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 |
number
matrix.countRows() ⇒ Counts rows in this matrix
Kind: instance method of Matrix
Returns: number
- Number of rows
number
matrix.countColumns() ⇒ Counts columns in this matrix
Kind: instance method of Matrix
Returns: number
- Number of columns
boolean
matrix.addable(y) ⇒ 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 |
Matrix
matrix.add(y) ⇒ 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 |
boolean
matrix.multipliable(y) ⇒ 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 |
Matrix
matrix.multiply(y) ⇒ 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 |
Matrix
matrix.transpose() ⇒ Calculates the transpose of this matrix
Kind: instance method of Matrix
Returns: Matrix
- New matrix with the transpose
Matrix
matrix.invert() ⇒ Inverts this matrix
Kind: instance method of Matrix
Returns: Matrix
- Matrix inverse
Matrix
matrix.map() ⇒ Maps over this matrix
Kind: instance method of Matrix
Returns: Matrix
- Matrix inverse
number
| Array.<number>
matrix.valueOf() ⇒ Returns the number or number array value
Kind: instance method of Matrix
Returns: number
| Array.<number>
- Number of number array value
string
matrix.inspect() ⇒ Formats and prints the matrix value
Kind: instance method of Matrix
Returns: string
- Formatted matrix value
string
inspect~padding : Output array filled with zeroes
Kind: inner constant of inspect
boolean
Matrix.addable(x, y) ⇒ 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 |
Matrix
Matrix.add(x, y) ⇒ 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 |
boolean
Matrix.multipliable(x, y) ⇒ 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 |
Matrix
Matrix.multiply(x, y) ⇒ 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 |
Matrix
multiply~z : New matrix with the dot product
Kind: inner constant of multiply
Matrix
Matrix.invert(Matrix) ⇒ Inverts a matrix
Kind: static method of Matrix
Returns: Matrix
- Matrix inverse
Param | Type | Description |
---|---|---|
Matrix | x |
to invert |
Matrix
Matrix~matrix : Single or multi dimensional matrix
Kind: inner constant of Matrix
number
Matrix~innerproduct(x, y, i) ⇒ 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 |
Testing
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.