matrmath
A library for performing matrix operations.
Installation
npm install matrmath
Usage
Utilize the functions in this library for performing matrix operations.
For example, compute the diagonal difference of a square (n x n) matrix:
const mtr = require("matrmath");
let diff = mtr.diagonalDiff([
[2, 5, 3],
[4, 6, 1],
[7, 8, 9]
]);
console.log(diff);
Or compute a matrix in reduced row echelon form:
const mtr = require("matrmath");
let reduced = mtr.rowReduce([
[5, 8, 2],
[3, 5, 3],
[6, 4, 9]
]);
console.log(reduced);
Config
rowReduce(M)
Transform a matrix in-place and return the reduced row-echelon form of a matrix. Row replacement is achieved through Gaussian Elimination.
M
- number[][]
- A 2-dimensional array.square
- boolean
- Optional boolean parameter to specify if the matrix is square (ie 3x3, 4x4 etc).
diagonalDiff(M)
Return the diagonal difference of a square. The diagonal difference is the absolute value of the left diagonal minus the right diagonal in a square matrix.
M
- number[][] | number[]
- A 2-dimensional array, or optionally 1D array.is2D
- boolean
- Optional boolean parameter to specify if the matrix is 1D instead of 2D.debug
- boolean
- Optional boolean parameter to output the lib
object with items used in computations.
isSquare(M)
Check whether a 2D or 1D matrix is square. That is the number of rows equals the number of columns in a n x m
layout where n = rows and m = columns and n must equal m.
M
- number[][] | number[]
- A 2D or 1D array, or optionally 1D array.is2D
- boolean
- Optional boolean parameter to specify if the matrix is 1D instead of 2D.
det(M)
Calculate the determinant of a matrix.
M
- number[][]
- A 2-dimensional array.
isIndependent(M)
Calculate whether a square matrix is linearly independent. If the determinant of a matrix is not equal to 0, its linearly independent.
M
- number[][]
- A 2-dimensional array.
isDependent(M)
Calculate whether a square matrix is linearly dependent. Meaning its determinant equals 0.
M
- number[][]
- A 2-dimensional array.
Tests
npm run test
Todo
Resources