Skip to content

linsolve

Solve a linear system with optional structure hints.

X = linsolve(A, B)
X = linsolve(A, B, opts)

Solves A*X = B for X. Equivalent to MATLAB’s backslash A\B for the simple form, but accepts an opts struct with hints about A’s structure (LT lower-triangular, UT upper-triangular, SYM symmetric, POSDEF positive-definite, RECT rectangular least-squares, TRANSA apply transpose).

With hints, LAPACK uses the appropriate specialized solver — substantially faster than the generic LU pivoted solver when the structure is known.

A = magic(3); b = [1; 2; 3];
x = linsolve(A, b) % solves A*x = b
norm(A*x - b) % near-zero
  • lu — LU decomposition (with partial pivoting).
  • qr — QR decomposition.
  • chol — Cholesky factorization of a Hermitian positive-definite matrix.
  • inv — Matrix inverse.