Numerical Linear Algebra/LU and Cholesky Factorization in Practice

Lesson 8.21,254 words

LU and Cholesky Factorization in Practice

Gaussian elimination, read as a factorization A = LU, turns a linear system into two triangular solves. A single near-zero pivot wrecks it, so partial pivoting reorders rows to pick the largest available pivot and makes the method work for every invertible matrix.

╌╌╌╌

Solving by hand means Gaussian elimination: clear the first column, clear the second, and so on until the matrix is triangular, then back-substitute. Von Neumann and Goldstine observed in 1947 that this is really two separate operations, first decompose into a product of triangular matrices, then solve by substitution, and that separating them is what lets one factorization serve any number of right-hand sides.1 The decomposition is , and once it is in hand the system reduces to two triangular solves.

Reading elimination as a factorization

To solve , substitute and split it in two:

so that . When a normalized decomposition exists, both factors are unique: if , then is at once unipotent-lower and upper triangular, forcing it to equal .1

The factors are built one row and column at a time by a recursion that peels off the first row and column at each step. Partition

Multiplying out the second block row gives and , so provided the pivot ,

The updated block , the Schur complement of , is the input to the next step. The pivots end up on the diagonal of , which yields the exact condition for existence.

One step of : the pivot and first row/column are read off, then the rank-one update overwrites the trailing Schur complement, shrinking the active block by one.

The cost is dominated by the rank-one update, flops at step , so the full factorization costs

and the two substitutions that follow add only . The factorization is the expensive part; once is stored, any number of right-hand sides is cheap. Because is read once and overwritten in place by and , the efficiency ratio is , so a Level-3 BLAS implementation runs near peak performance.

Small pivots and instability

Existence fails the instant a pivot is zero. The invertible matrix

has and no normalized at all. The deeper problem is that a pivot close to zero is nearly as damaging as an exact zero, once arithmetic is rounded. Take

On a machine carrying sixteen significant digits, rounds to : the subtraction of falls below the resolution of the representation. The computed factor is the exact factorization of a different matrix, one with the entry silently changed from to . Solving with the rounded factors returns against the true : a one-hundred-percent error in the first component from a matrix that is perfectly well-behaved.

Partial pivoting

The fix uses a freedom in the problem: the row order of a system is arbitrary. Before eliminating column , scan it and move the entry of largest absolute value into the pivot position.

Each row swap is a transposition , and their accumulated product is a permutation matrix . The arithmetic of each step is identical to the unpivoted recursion; only the row selection changes. The result is a factorization of the row-permuted matrix.

The proof is an induction showing each Schur complement stays invertible, so its first column is never entirely zero and a nonzero pivot always exists. The bound is the payoff of choosing the largest pivot: the multipliers can never blow up, which is what keeps the rounded factorization close to a true one.

Partial pivoting scans column for the largest-magnitude entry (here , below the diagonal) and swaps its row up before eliminating, keeping every multiplier in size.

Nothing about the solve changes: becomes , so one permutes the right-hand side and runs the same forward and back substitution.

Algorithm:PivotedLU(A)\textsc{PivotedLU}(A) — in-place PA=LUP^\ast A = LU with partial pivoting
  1. 1
    p[1,2,,m]p \gets [1, 2, \dots, m]
    permutation record
  2. 2
    for k=1k = 1 to m1m-1 do
  3. 3
    choose jkj \ge k maximizing Ajk\lvert A_{jk} \rvert
    pivot search
  4. 4
    swap rows kk and jj of AA and entries k,jk, j of pp
  5. 5
    for i=k+1i = k+1 to mm do
  6. 6
    AikAik/AkkA_{ik} \gets A_{ik} / A_{kk}
    multiplier ll, stored below the diagonal
  7. 7
    end for
  8. 8
    Ak+1:m,k+1:mAk+1:m,k+1:mAk+1:m,kAk,k+1:mA_{k+1:m,\, k+1:m} \gets A_{k+1:m,\, k+1:m} - A_{k+1:m,\, k}\, A_{k,\, k+1:m}
    Schur update
  9. 9
    end for
  10. 10
    return L=unit lower part,  U=upper part,  pL = \text{unit lower part},\; U = \text{upper part},\; p
The two computed solutions of the near-singular system against the true solution. Without pivoting the first component collapses to zero; partial pivoting lands on the true point.

Partial pivoting is the default dense solver everywhere; it is what a call to A\b or LAPACK's xGETRF runs underneath.

Cholesky for symmetric positive-definite systems

A large class of systems — least-squares normal equations, covariance matrices, stiffness matrices in mechanics — carry extra structure that a general solver wastes. These are the symmetric (Hermitian) positive-definite matrices.

For s.p.d. matrices the factorization can be made symmetric, and no pivoting is ever needed because every leading principal submatrix inherits the s.p.d. property and so is invertible.

The factor is built row by row. Partitioning and matching blocks gives, for row ,

Positive definiteness of the principal submatrix guarantees , so the square root is real and the diagonal stays positive. The name reads as a matrix square root: Cholesky is to s.p.d. matrices what is to positive numbers.2

Cholesky reads only the lower half of the symmetric and produces one triangular factor ; row needs a forward solve against plus a square root for the diagonal entry .
Algorithm:Cholesky(A)\textsc{Cholesky}(A) — factor s.p.d. A=LLA = L L^\ast row by row
  1. 1
    for k=1k = 1 to mm do
  2. 2
    lL1:k1,1:k11A1:k1,kl \gets L_{1:k-1,\,1:k-1}^{-1}\, A_{1:k-1,\,k}
    forward substitution
  3. 3
    Lk,1:k1lL_{k,\,1:k-1} \gets l^\ast
  4. 4
    LkkAkkllL_{kk} \gets \sqrt{A_{kk} - l^\ast l}
    fails (root of 0\le 0) if AA is not s.p.d.
  5. 5
    end for
  6. 6
    return LL

Only the lower half of is touched, and only one triangular factor is stored, so Cholesky costs

half the cost of a general , with the same efficiency ratio and the same near-peak Level-3 BLAS performance. The square root also doubles as a test: if the argument is ever nonpositive, was not positive definite, and the algorithm reports it.

Choosing a solver

SituationMethodCost (flop)Pivoting
General invertible pivoted , partial (rows)
Symmetric positive-definite Cholesky, none needed
Many right-hand sides, fixed factor once, substitute per per solvereuse the factors

The recurring pattern is to factor once and then answer each new right-hand side with two triangular solves. How much error a solve inherits from the matrix is set by its conditioning; whether the algorithm reaches that floor is the question of stability, where pivoted turns out to be, in the backward sense, as accurate as the problem allows.

Footnotes

  1. Bornemann, Numerical Linear Algebra, §7 — Triangular Decomposition: the recursion via Schur complements, uniqueness, the cost, the Zeroth Law, and partial pivoting giving with . 2 3
  2. Bornemann, §8 — Cholesky Decomposition: the s.p.d. definition, the row-wise construction , , and the cost.

╌╌ END ╌╌