1.0.0 • Published 4 years ago

@haydenhigg/squarematrix v1.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
4 years ago

@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 array a
  • identity(): returns an identity matrix with the same dimensions as the input matrix
  • tranpose(): returns the transpose of the input matrix
  • det(): returns the determinant of the input matrix
  • adj(): returns the adjugate matrix of the input matrix
  • inv(): returns the inverse matrix of the input matrix
  • exact(): returns the input matrix with each value in its exact (fractional) form using num2fraction

Static Methods

  • identity(d): returns an identity matrix with the dimension d
  • Every other instance method has a static equivalent that takes an argument a