@haydenhigg/squarematrix
v1.0.0
Published
A lightweight library for working with square matrices.
Downloads
2
Readme
@haydenhigg/squarematrix
Lightweight library for working with square matrices.
Usage
const SquareMatrix = require('@haydenhigg/squarematrix');
const mat = new SquareMatrix([
[-4, 2, 1],
[1, 2, 3],
[5, 1, 2]
]);
console.log(mat.inv());
/* =>
[
[ 0.07692307692307693, -0.23076923076923078, 0.3076923076923077 ],
[ 1, -1, 1 ],
[ -0.6923076923076923, 1.0769230769230769, -0.7692307692307693 ]
]
*/
console.log(SquareMatrix.exact(mat.inv()));
/* =>
[
[ '1/13', '-3/13', '4/13' ],
[ '1', '-1', '1' ],
[ '-9/13', '14/13', '-10/13' ]
]
*/
Complete Interface
Instance Methods
constructor(a)
: creates a new matrix instance with the square, 2-dimensional arraya
identity()
: returns an identity matrix with the same dimensions as the input matrixtranpose()
: returns the transpose of the input matrixdet()
: returns the determinant of the input matrixadj()
: returns the adjugate matrix of the input matrixinv()
: returns the inverse matrix of the input matrixexact()
: returns the input matrix with each value in its exact (fractional) form using num2fraction
Static Methods
identity(d)
: returns an identity matrix with the dimensiond
- Every other instance method has a static equivalent that takes an argument
a