Linear algebra

Products and transpose

import { Matrix } from "@teakit/matrix";

a.mmul(b); // matrix product a·b (a.columns must equal b.rows) -> new Matrix
a.mpow(3); // matrix power Aⁿ (square, non-negative integer exponent)
a.transpose(); // new Matrix (see also the zero-copy transpose view)
a.dot(vector); // scalar (dot) product of two equal-length vectors
a.kroneckerProduct(b); // alias: tensorProduct
a.kroneckerSum(b);
a.mmulStrassen(b); // Strassen multiplication; also strassen2x2 / strassen3x3
a.trace(); // sum of the diagonal
a.norm(); // 'frobenius' (default) or 'max'

Echelon forms

a.echelonForm(); // row echelon form (new matrix)
a.reducedEchelonForm(); // reduced row echelon form (new matrix)

Top-level solvers (named imports)

import {
  solve,
  inverse,
  determinant,
  pseudoInverse,
  linearDependencies,
} from "@teakit/matrix";

determinant(A); // number (square only)

inverse(A); // exact inverse; pass true to use SVD for singular/ill-conditioned
inverse(A, true);

// Solve A·x = b. LU for square A, QR for rectangular; pass true for SVD.
const x = solve(A, b);
const x2 = solve(A, b, true);

pseudoInverse(A); // Moore–Penrose pseudo-inverse (via SVD)
linearDependencies(A); // matrix describing linear dependencies between rows

solve, inverse, and the decompositions accept any MaybeMatrix (AbstractMatrix or a 2D array). b in solve is a matrix / column vector.

For the underlying factorizations (and reusing one across several solves), see decompositions.