A13 · Lesson 24 · LU and Cholesky
Factor once and solve many times, halve the work for symmetric matrices, and refine the answer
Gaussian elimination (lesson 23) is best thought of as a factorization, , done once and reused. A circuit simulator stepping through 10 000 time steps with the same matrix, or a sensitivity analysis with a hundred right-hand sides, pays for the factorization once and then solves each new case cheaply. Matrices from resistor networks and from most physical problems are symmetric and positive definite, and for them the Cholesky factorization does half the work with no pivoting. Banded matrices cost far less again. And when a factorization is done in low precision, a few steps of iterative refinement recover full accuracy.
- The curves show the operation count against matrix size n for four ways of solving : dense LU (), Cholesky (), banded LU with bandwidth b (), and a tridiagonal solve ().
- Move b. A band of a few hundred costs far less than dense LU once n is large; a band of 1 is the tridiagonal case.
- The readouts give each method's time for n = 10 000 at 10 GFLOP/s.
Predict
A 1000-node resistive circuit's nodal matrix is symmetric with positive pivots. Compared with LU, what does Cholesky save?
Half the arithmetic, instead of , and half the storage, since only L is kept. A symmetric positive definite matrix is also safe to factor without pivoting: the pivots stay positive and the entries of L stay bounded by those of A. If Cholesky meets a zero or negative pivot, the matrix wasn't positive definite, which makes the factorization a test as well.
Name it
Factor once, solve many times
costs . Each solve afterward is a forward substitution with L and a back substitution with U, about in total. The determinant comes for free: , with the sign set by the number of row swaps. You rarely need itself: forming it costs three times as much as factoring, and is less accurate than solving with the factors.
Cholesky
A symmetric positive definite matrix (one with for every nonzero x) factors as , with
It costs and needs no pivoting. Conductance matrices of resistive networks with a ground node, stiffness matrices from finite elements and covariance matrices are all of this kind.
Banded and tridiagonal systems
If every nonzero is within b of the diagonal, elimination creates no fill outside the band, and LU costs about . For tridiagonal matrices (b = 1) the Thomas algorithm sweeps down and back in about 8n operations: a spline through a million points costs a few milliseconds.
Iterative refinement
With the factors in hand, compute the residual (in higher precision if you can), solve with the same factors, and update . Each step multiplies the error by about , where u is the factorization's unit roundoff. That lets a fast float32 factorization deliver float64 accuracy when .
Worked example
Factor by Cholesky.
Show the solution
- The first column.
- The corner.
- The factor. Multiplying gives back A.
- Determinant. which matches .
- On the edge. If the corner entry had been 1 instead of 3, would be : the matrix would be singular, sitting on the edge of positive definiteness.
Answer , and the determinant is 8.
Worked example
Solve with the Thomas algorithm.
Show the solution
- Sweep down: row 2. Row 2 becomes row 2 + ½ row 1:
- Sweep down: row 3. Row 3 becomes row 3 + row 2:
- Back substitute.
- What it means. This matrix is the discrete second derivative, and the answer is the voltages along a resistor ladder with both ends driven at 1.
Answer .
Worked example
A matrix with is factored in float32 () and refined in float64. How does the error fall?
Show the solution
- The first solve. It is accurate to about
- Each refinement step. It multiplies the error by about again: , then , then .
- The floor. The error falls until it reaches float64's own limit, about .
- The payoff. Three cheap refinement steps, each costing , recover what a float64 factorization would give, while the expensive factorization ran in float32, often two to four times faster on GPUs.
Answer from about the error shrinks by about per step, reaching float64's limit of about after three steps.
Check
Factor .
(a)
What is ?
(b)
What is ?
Check
About how long does a Cholesky factorization of a dense 1000 × 1000 matrix take at 10 GFLOP/s?
Write units the way you normally would: 1.5 s and 1500 ms are the same answer.
Check
needed 3 row swaps, and U has diagonal 2, 3, 0.5. What is ?
Check
Cholesky on : what is ?
Check
A matrix with κ = 1000 is factored in float32 () and refined.
(a)
About how accurate is the first solve?
(b)
About how accurate is it after 1 refinement steps, before float64's limit?
Check
About how many operations does the Thomas algorithm take on a tridiagonal system with 10000 unknowns?
Check
You need for 50 right-hand sides b. What should you compute?
Check
Cholesky on the symmetric matrix .
Step 1
What is ?
Type it the way you would write it, like 3sin(2πft) or 3*sin(2*pi*f*t). Angles can be in radians or carry a degree sign, like 45°.
Step 2
What is ?
Step 3
What is ?
Explain why
Why does iterative refinement with a low-precision factorization converge to high-precision accuracy?
The low-precision factors define an approximate solver that is wrong by a relative amount of about on whatever it's given. Iterative refinement only ever asks it to solve for the correction, using a residual computed accurately from the original A and the current answer. Each solve fixes the correction to within that relative error, so the remaining error shrinks by a factor of about each time. As long as that factor is below 1, the error falls geometrically until it reaches the limit set by how accurately the residual is computed, the high precision. The expensive factorization never needs to be accurate; it needs only to point in roughly the right direction.
Practice
Keep practicing
8 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.