1. Home
  2. Linear algebra

Linear algebra · factorization

LU Factorization of a Matrix: Method and Worked Example

Eigenfield editorial team ·

LU factorization writes a square matrix A as a product A = LU, where L is lower triangular with ones on its diagonal and U is upper triangular. It is Gaussian elimination recorded in matrix form. Once the factors exist, solving Ax = b takes two quick triangular substitutions, and the determinant falls out of the diagonal of U.

How the factors are built

Elimination clears the entries below the diagonal one column at a time. To clear column 1, subtract a multiple of row 1 from each lower row; the multiplier used on row i is li1 = ai1/a11. These multipliers, stored in the position they cleared, are exactly the below-diagonal entries of L. What is left after all columns are cleared is U.

The entry a11 (and later each diagonal entry met during elimination) is the pivot. A zero pivot breaks the method, and a tiny pivot wrecks accuracy, so practical codes reorder the rows. That gives the form PA = LU with a permutation matrix P, called partial pivoting.

A worked 3 × 3 example

Let A = [2 1 1; 4 3 3; 8 7 9]. Column 1 has pivot 2. The multipliers are l21 = 4/2 = 2 and l31 = 8/2 = 4.

Row 2 minus 2 times row 1 gives [0 1 1]. Row 3 minus 4 times row 1 gives [0 3 5]. Column 2 now has pivot 1, and the multiplier for row 3 is l32 = 3/1 = 3. Row 3 minus 3 times the new row 2 gives [0 0 2]. The factors are

L = [1 0 0; 2 1 0; 4 3 1], U = [2 1 1; 0 1 1; 0 0 2].

Verify by multiplying. The third row of LU is 4·[2 1 1] + 3·[0 1 1] + 1·[0 0 2] = [8, 4 + 3, 4 + 3 + 2] = [8 7 9], which is the third row of A. The second row is 2·[2 1 1] + [0 1 1] = [4 3 3]. Both match.

Solving a system with the factors

Take b = (4, 10, 24); this is A times (1, 1, 1). Solve Ly = b by forward substitution: y₁ = 4, y₂ = 10 − 2·4 = 2, y₃ = 24 − 4·4 − 3·2 = 2. Then solve Ux = y by back substitution: x₃ = 2/2 = 1, x₂ = 2 − 1·x₃ = 1, x₁ = (4 − x₂ − x₃)/2 = 1. The solution is (1, 1, 1), as it should be.

The payoff is reuse. Factoring costs about 2n³/3 floating-point operations, while each triangular solve costs about n². With many right-hand sides, the factorization is paid for once. This is also what happens underneath matrix division for a general square matrix.

The determinant and pivoting

The determinant of A is the product of the diagonal of U times the sign of the permutation. Here det A = 2 · 1 · 2 = 4, and expanding along the first row confirms it: 2(27 − 21) − 1(36 − 24) + 1(28 − 24) = 12 − 12 + 4 = 4.

A small case shows why pivoting exists. A = [1 2; 3 4] has pivot 1, but partial pivoting swaps the rows first so the pivot is the larger entry 3. Then PA = [3 4; 1 2], the multiplier is 1/3, and U = [3 4; 0 2/3]. The determinant is 3 · 2/3 = 2, times −1 for one row swap, giving −2, which equals 1·4 − 2·3.

A singular matrix eventually produces a zero pivot that no row swap can avoid, and a nearly singular one produces a pivot that is tiny relative to its neighbors. Both are warnings worth reading; see the glossary entry for condition number.

LU is for general square systems. When A is symmetric and positive definite, Cholesky halves the work. For rectangular or rank-deficient problems, QR and the SVD take over, as in left division and least squares. Eigenvalue problems use yet another route, the Schur factorization. The linear algebra hub collects them.

Back to top