matrix-linear-algebra
v0.6.2
Published
Dense matrix operations without dependencies: multiply, transpose, determinant, inverse, LU decomposition and linear solve via partial pivoting.
Downloads
142
Maintainers
Readme
matrix-linear-algebra
Dense matrix math for Node with no dependencies. Matrices are plain arrays of rows
(number[][]); vectors are flat number[]. Determinant, inverse and solve all share a
single LU decomposition with partial pivoting.
Install
npm install matrix-linear-algebraUsage
import { multiply, determinant, inverse, solve } from "matrix-linear-algebra";
multiply([[1, 2], [3, 4]], [[5, 6], [7, 8]]);
// [[19, 22], [43, 50]]
determinant([[6, 1, 1], [4, -2, 5], [2, 8, 7]]); // -306
// Solve 2x + y = 5, x + 3y = 10
solve([[2, 1], [1, 3]], [5, 10]); // [1, 3]
inverse([[4, 7], [2, 6]]); // [[0.6, -0.7], [-0.2, 0.4]]API
shape(a)→[rows, cols]identity(n)transpose(a)add(a, b),sub(a, b),scale(a, k)multiply(a, b)— matrix productmatVec(a, v)— matrix times a flat vectordeterminant(a)— returns exactly0for singular matricessolve(a, b)— solveA x = binverse(a)— throws for singular matricestrace(a)equals(a, b, tol = 1e-9)— tolerant elementwise comparison
Numerics
Row operations use partial pivoting for stability. Determinant and inverse do not attempt symbolic exactness — expect floating-point rounding on ill-conditioned inputs.
License
Apache-2.0
