Skip to content

Latest commit

 

History

History
294 lines (192 loc) · 10.5 KB

README.md

File metadata and controls

294 lines (192 loc) · 10.5 KB

npm codecov

matrix

Single or multi dimensional matrices and matrix functions.

Installation

Run npm install --save @smockle/matrix to add matrix to your project.

Usage

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

API Reference

Matrix ⏏

Kind: Exported class

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

matrix.countRows() ⇒ number

Counts rows in this matrix

Kind: instance method of Matrix
Returns: number - Number of rows

matrix.countColumns() ⇒ number

Counts columns in this matrix

Kind: instance method of Matrix
Returns: number - Number of columns

matrix.addable(y) ⇒ boolean

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.add(y) ⇒ Matrix

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

matrix.multipliable(y) ⇒ boolean

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.multiply(y) ⇒ Matrix

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.transpose() ⇒ Matrix

Calculates the transpose of this matrix

Kind: instance method of Matrix
Returns: Matrix - New matrix with the transpose

matrix.invert() ⇒ Matrix

Inverts this matrix

Kind: instance method of Matrix
Returns: Matrix - Matrix inverse

matrix.map() ⇒ Matrix

Maps over this matrix

Kind: instance method of Matrix
Returns: Matrix - Matrix inverse

matrix.valueOf() ⇒ number | Array.<number>

Returns the number or number array value

Kind: instance method of Matrix
Returns: number | Array.<number> - Number of number array value

matrix.inspect() ⇒ string

Formats and prints the matrix value

Kind: instance method of Matrix
Returns: string - Formatted matrix value

inspect~padding : string

Output array filled with zeroes

Kind: inner constant of inspect

Matrix.addable(x, y) ⇒ boolean

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.add(x, y) ⇒ Matrix

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

Matrix.multipliable(x, y) ⇒ boolean

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.multiply(x, y) ⇒ Matrix

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

multiply~z : Matrix

New matrix with the dot product

Kind: inner constant of multiply

Matrix.invert(Matrix) ⇒ 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

Matrix~innerproduct(x, y, i) ⇒ number

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.