Matrix Decompositions, Explained
After reading this you will know what LU, QR, SVD and eigendecomposition each produce, when to reach for each one, and how to check the factors by multiplying them back together.
A matrix decomposition rewrites one matrix as a product of two or three simpler matrices. The simpler pieces are triangular, orthogonal, or diagonal, and each shape makes a specific computation cheap. Solving a linear system, computing a determinant, finding the rank, or measuring how much a matrix stretches space all become easier once you have the right factorization.
Take the demo matrix A = \begin{bmatrix} 4 & 3 \\ 6 & 3 \end{bmatrix}. Its LU factorization with partial pivoting writes it as PA = LU where L is lower triangular with ones on the diagonal, U is upper triangular, and P is a permutation that records row swaps. You will reproduce those exact numbers below.
The four decompositions at a glance
Each mode targets a different job. Pick the one that matches your question.
- LU (P·L·U)
- Factors a square matrix into a permutation, a lower triangular matrix, and an upper triangular matrix. This is the engine behind solving Ax = b and computing determinants.
- QR
- Factors any matrix as A = QR with
Qhaving orthonormal columns andRupper triangular. This is the stable route to least squares fits. - SVD (U·Σ·Vᵀ)
- Factors any matrix as A = U\Sigma V^{\top} with
UandVorthogonal and \Sigma diagonal with non-negative singular values. This exposes rank, condition and the best low-rank approximation. - Eigendecomposition
- For a square matrix that has enough independent eigenvectors, writes A = V \Lambda V^{-1} with \Lambda diagonal. This diagonalizes the matrix and reveals its long-term behavior under repeated multiplication.
When to use each one
LU is the default for square systems. If you need to solve Ax = b for several right-hand sides with the same A, factor once and reuse the triangular solves. The determinant of A is the product of the diagonal of U, times the sign of the permutation.
QR shines when the system is tall (more equations than unknowns) or when accuracy matters. The columns of Q are orthonormal, so the factorization does not amplify rounding error the way forming A^{\top}A can.
SVD is the most informative and the most expensive. Use it when you care about rank, near-rank, the condition number, or compressing a matrix. Every real matrix has an SVD, even non-square and singular ones.
Not every square matrix has an eigendecomposition. A matrix is diagonalizable only when it has a full set of independent eigenvectors. The matrix \begin{bmatrix} 1 & 1 \\ 0 & 1 \end{bmatrix} has the single eigenvalue 1 but only one eigenvector direction, so it cannot be written as V \Lambda V^{-1}. When you need a factorization that always exists, use SVD.
The math behind LU
LU is Gaussian elimination written as a product. You subtract multiples of one row from those below it to clear the entries under each pivot. Those multipliers become the entries of L, and the reduced matrix is U.
Here P is a permutation matrix that records which rows were swapped, L is lower triangular with unit diagonal, and U is upper triangular. Partial pivoting means that at each step you swap in the row whose pivot entry has the largest absolute value. That keeps the multipliers at most 1 in magnitude and controls rounding error.
Once you have the factors, solving Ax = b takes two triangular solves: first Ly = Pb going forward, then Ux = y going backward. Each is fast because triangular systems need no elimination.
Worked example: LU of the demo matrix
Factoring the 2 by 2 demo
Load 4, 3 on the first row and 6, 3 on the second, keep the mode on LU, and press Calculate.
- Compare the first-column entries:
|4| = 4and|6| = 6. Partial pivoting swaps the rows so6becomes the pivot. The permutation records this swap. - After the swap the working matrix is \begin{bmatrix} 6 & 3 \\ 4 & 3 \end{bmatrix}.
- Eliminate below the pivot. The multiplier is 4/6 = 0.6667, which becomes the
(2,1)entry ofL. - Update the second row: 3 - 0.6667 \cdot 3 = 1. That is the
(2,2)entry ofU.
The result is
Check it by multiplying LU. Row two is (0.6667 \cdot 6,\ 0.6667 \cdot 3 + 1) = (4, 3), and row one is (6, 3). That equals PA, the original matrix with its rows swapped. The determinant of A is the product of the U diagonal, 6 \cdot 1 = 6, times the sign of one swap, which is -1, giving \det A = -6. Direct calculation agrees: 4 \cdot 3 - 3 \cdot 6 = 12 - 18 = -6.
Reading SVD and eigenvalue output
The SVD lists singular values \sigma_1 \ge \sigma_2 \ge \dots \ge 0 on the diagonal of \Sigma. They are the square roots of the eigenvalues of A^{\top}A, and they measure how far the matrix stretches unit vectors along each principal direction.
For the demo matrix the singular values are about 8.113 and 0.7396. Their product equals the absolute determinant: 8.113 \cdot 0.7396 = 6.0, matching |\det A| = 6. The ratio of the largest to the smallest is the condition number, here 8.113 / 0.7396 = 10.97. A large condition number warns that solving Ax = b is sensitive to error.
| Quantity | Value | From |
|---|---|---|
| Determinant | -6 | product of U diagonal times sign |
| Rank | 2 | two nonzero singular values |
| Largest singular value | 8.113 | SVD |
| Smallest singular value | 0.7396 | SVD |
| Condition number | 10.97 | ratio of singular values |
| Eigenvalues | 7.772, -0.7720 | eigendecomposition |
Note that the eigenvalues (7.772 and -0.7720) are not the singular values. Their product is 7.772 \cdot (-0.7720) = -6, the determinant with sign, while singular values are always non-negative and give the absolute determinant. The two agree only for symmetric positive definite matrices.
QR and least squares
QR factors A = QR where Q has orthonormal columns, meaning Q^{\top}Q = I, and R is upper triangular. For an overdetermined system the least squares solution is Rx = Q^{\top}b, a single triangular solve.
The reason to prefer QR over the normal equations A^{\top}A x = A^{\top}b is numerical: forming A^{\top}A squares the condition number. If A has condition number 10.97, then A^{\top}A has condition number near 120, which loses roughly two extra digits of accuracy. QR avoids that squaring.
Common mistakes
Confusing eigenvalues with singular values is the most frequent error. They coincide only for symmetric positive definite matrices. For everything else, compute the one that answers your question.
A second mistake is expecting an eigendecomposition to exist. Check the diagonalizability flag the calculator reports. A defective matrix (fewer independent eigenvectors than its size) cannot be diagonalized, and the returned V would be singular.
Always verify a decomposition by multiplying the factors back and comparing to the original. For LU check PA = LU, for QR check QR = A, for SVD check U\Sigma V^{\top} = A. Small differences below 10^{-10} are rounding, not error.
A third pitfall is reading signs into singular values or into the columns of Q, U and V. Sign choices are not unique: flipping a column of Q and the matching row of R gives the same product. Judge a factorization by whether the product reconstructs A, not by matching another tool sign for sign.
Related calculators
For determinant, inverse, rank and RREF without the factor matrices, use the Matrix Calculator. To solve a specific linear system Ax = b or find polynomial roots, use the Equation Solver. Eigenvalues come from the characteristic polynomial, which for a 2 by 2 matrix is a quadratic you can check with the Quadratic solver. If you are working with the orthogonal columns of Q, the Vector Calculator handles dot products and projections. Complex eigenvalues from a rotation matrix can be explored with the Complex Number Calculator.
Frequently asked questions
Why does LU swap rows even when the matrix has no zero pivots?
Partial pivoting chooses the largest available pivot at each step to limit rounding error, not only to avoid dividing by zero. For the demo matrix it swaps rows because 6 beats 4 in the first column, even though 4 is nonzero.
Are singular values ever negative?
No. Singular values are defined as square roots of the eigenvalues of A^{\top}A, which are non-negative, so every singular value is \ge 0. Eigenvalues, by contrast, can be negative or complex.
What does a zero singular value mean?
It means the matrix is rank deficient. The number of nonzero singular values equals the rank. If a 3 by 3 matrix has singular values 5, 2, 0, its rank is 2 and it maps space onto a plane.
How do I get the determinant from these factors?
From LU, multiply the diagonal of U and apply the permutation sign. From SVD you get only the absolute value, the product of the singular values. From the eigendecomposition, the determinant is the product of the eigenvalues.
Can I decompose a non-square matrix?
QR and SVD work for any shape. LU and eigendecomposition require a square matrix, since both rely on the same number of rows and columns.