MatrixJs is a small Javascript Library use to compute matrix
MatrixJs can do basic computing of matrix. such as - Finding Determinant, Transponse, Minor, Adjoint and more - Inversing
- First We Import
Matrix
from MatrixJs
import Matrix from "./MatrixJS";
- To Create a Matrix we initate a Matrix class with 2 Dimenstional Array
let MyMatrix = new Matrix([
[1, 2, 3],
[4, 5, 6],
[7, 8, 9],
]);
- To access the matrix use
console.log(MyMatrix.matrix);
returns an array of [row, column]
let size = MyMatrix.size();
let [row, column] = MyMatrix.size();
console.log(size); // [3, 3]
let determinant = MyMatrix.det();
or without creating a variable for the matrix
let determinant = new Matrix([
[1, 2, 3],
[4, 5, 6],
[7, 8, 9],
]).det();
let inverse = MyMatrix.inverse();
or you can just change the matrix by passing true
as a parameter
MyMatrix.inverse(true);
let transposed = MyArray.transponse();
or to change the Matrix itself pass true
parameter
MyMatrix.transponse(true);
console.log(MyMatrix.matrix);
/*
[
[1, 4, 7],
[2, 5, 8],
[3, 6, 9]
]
*/
Cofactor and Minor take two arguments row
and column
let cofactor = MyMatrix.cofactor(0, 1); // 6
let minor = MyMatrix.minor(0, 0); // -6