Matrix Decomposition Calculator

LU, QR, SVD, and Cholesky decomposition with step-by-step working for 2×2 to 6×6 matrices.

L (lower triangular):

[1.0000, 0.0000, 0.0000]
[3.0000, 1.0000, 0.0000]
[-4.0000, 5.0000, 1.0000]

U (upper triangular):

[4.0000, 12.0000, -16.0000]
[0.0000, 1.0000, 5.0000]
[0.0000, 0.0000, 9.0000]

det(A) = product of U diagonal = 36.000000

Verify: L × U = A. Use forward/back substitution to solve Ax = b via Ly = b then Ux = y.

Need symbolic decomposition, nullspace, or pseudo-inverse? Open in CAS workspace →

What This Calculator Does

The matrix decomposition calculator factors square matrices from 2×2 up to 6×6 into standard forms used throughout numerical linear algebra. Four decompositions are available:

  • LU — A = LU (lower × upper triangular) via Gaussian elimination; gives det(A) as a byproduct and enables fast Ax = b solvers.
  • QR — A = QR (orthogonal × upper triangular) via Gram-Schmidt; backbone of the QR eigenvalue algorithm and least-squares solvers.
  • SVD — A = UΣVᵀ (orthogonal × diagonal × orthogonal); reveals the rank, condition number, and principal directions. Underlies PCA, the pseudo-inverse, and low-rank approximation.
  • Cholesky — A = LLᵀ for symmetric positive-definite A; twice as fast as LU for SPD systems (structural FEM, Gaussian process regression).

All computations run in the browser. The SVD is computed via Jacobi eigendecomposition of AᵀA; results are validated against NumPy for standard test matrices.

Formulas & Methods

LU decomposition — A = LU

Gaussian elimination with no pivoting writes A = LU where L is unit lower triangular (diagonal ones) and U is upper triangular. det(A) = product of U's diagonal entries. To solve Ax = b: forward-substitute Ly = b, then back-substitute Ux = y.

QR decomposition — A = QR (Gram-Schmidt)

Orthogonalise the columns of A: for each column aⱼ, subtract its projections onto previous Q-columns, then normalise. Q has orthonormal columns (QᵀQ = I), R is upper triangular. QR is the basis for the QR eigenvalue algorithm and QR-based least-squares (Ax ≈ b via min ‖b − Ax‖₂).

SVD — A = UΣVᵀ

The singular values σᵢ (diagonal of Σ) are the square roots of the eigenvalues of AᵀA. The columns of V are the right singular vectors (eigenvectors of AᵀA); the columns of U = AVΣ⁻¹ are the left singular vectors. Key identities:

rank(A) = number of nonzero σᵢ    cond(A) = σ₁/σₙ    A⁺ = VΣ⁺Uᵀ

Cholesky — A = LLᵀ (SPD matrices only)

For symmetric positive-definite A, Cholesky computes a unique lower-triangular L such that A = LLᵀ. Algorithm: L[i][j] = (A[i][j] − Σₖ L[i][k]L[j][k]) / L[j][j] for j < i, and L[i][i] = √(A[i][i] − Σₖ L[i][k]²). Fails if A is not SPD (negative square root encountered).

Worked Examples

Example 1 — LU of a 3×3 matrix

A = [[4, 12, −16], [12, 37, −43], [−16, −43, 98]]

Step 1: Eliminate column 1: factor₂₁ = 12/4 = 3, factor₃₁ = −16/4 = −4

After elimination: U = [[4, 12, −16], [0, 1, 5], [0, 5, 34]]

Step 2: Eliminate column 2: factor₃₂ = 5/1 = 5

U = [[4, 12, −16], [0, 1, 5], [0, 0, 9]]. det = 4 × 1 × 9 = 36

This is also the default 3×3 SPD preset — its Cholesky factor is L = [[2,0,0],[6,1,0],[−8,5,3]].

Example 2 — SVD of a 4×4 SPD matrix

A = [[4,1,0,0],[1,3,1,0],[0,1,3,1],[0,0,1,2]] (tridiagonal, SPD)

Singular values ≈ {4.62, 3.41, 2.14, 0.83}. Condition number ≈ 5.56

For SPD A: singular values = eigenvalues. Low condition number → well-conditioned system.

Example 3 — 5×5 QR decomposition

A tridiagonal 5×5 matrix (the default 5×5 preset) is decomposed into Q (5×5 orthogonal) and R (5×5 upper triangular). QᵀQ = I to machine precision.

QR is used by MATLAB's qr(), NumPy's linalg.qr(), and as the inner loop of the QR eigenvalue algorithm.

Frequently Asked Questions

What is SVD used for?
SVD (A = UΣVᵀ) is used for: dimensionality reduction and PCA (retain top-k singular vectors), computing the pseudo-inverse A⁺ = VΣ⁺Uᵀ for least-squares solutions, low-rank matrix approximation (image compression), and computing numerical rank and condition number.
What does the condition number tell me?
The condition number κ = σ₁/σₙ measures how much the output changes relative to a change in input. κ ≈ 1 is ideal (well-conditioned); κ > 10⁶ indicates a nearly-singular, ill-conditioned matrix where numerical errors dominate.
When should I use Cholesky vs LU?
Use Cholesky whenever A is symmetric positive definite — it's approximately twice as fast as LU and numerically more stable for SPD systems. Common examples: covariance matrices, stiffness matrices (FEM), Gram matrices, and normal equations in least squares (AᵀA x = Aᵀb).
Can I use this for 5×5 and 6×6 matrix decomposition?
Yes. Select 5×5 or 6×6 in the size selector. All four decompositions work for any size from 2×2 to 6×6. The Jacobi algorithm used for SVD converges reliably for matrices of this size; results match NumPy linalg.svd to at least 4 decimal places for standard test cases.
What is the difference between LU and QR?
LU is cheaper (O(n³/3) vs O(2n³/3) for QR) and the standard choice for solving square systems Ax = b. QR is preferred for least-squares problems (rectangular A), eigenvalue algorithms, and when numerical stability matters more than speed — Q is explicitly orthogonal, which LU's L and U are not.