A1324 of 55
0 XP
  1. Hook
  2. Play
  3. Predict
  4. Name it
  5. Check
  6. Explain

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, PA=LU, 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 A=LLT 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 Ax=b: dense LU (23n3), Cholesky (13n3), banded LU with bandwidth b (2nb2), and a tridiagonal solve (8n).
  • 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?

Name it

Factor once, solve many times

PA=LU costs 23n3. Each solve afterward is a forward substitution with L and a back substitution with U, about 2n2 in total. The determinant comes for free: det⁡A=±∏uii, with the sign set by the number of row swaps. You rarely need A−1 itself: forming it costs three times as much as factoring, and x=A−1b is less accurate than solving with the factors.

Cholesky

A symmetric positive definite matrix (one with xTAx>0 for every nonzero x) factors as A=LLT, with

ljj=ajj−∑k<jljk2,lij=aij−∑k<jlikljkljj(i>j).

It costs 13n3 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 2nb2. 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 r=b−Ax^ (in higher precision if you can), solve Ad=r with the same factors, and update x^←x^+d. Each step multiplies the error by about κ(A)u, where u is the factorization's unit roundoff. That lets a fast float32 factorization deliver float64 accuracy when κ(A)u32≪1.

Worked example

Factor A=(4223) by Cholesky.

Show the solution
  1. The first column. l11=4=2l21=22=1
  2. The corner. l22=3−12=2
  3. The factor. L=(2012) Multiplying LLT gives back A.
  4. Determinant. (l11l22)2=(22)2=8 which matches 4×3−2×2.
  5. On the edge. If the corner entry had been 1 instead of 3, l22 would be 0: the matrix would be singular, sitting on the edge of positive definiteness.

Answer L=(2012), and the determinant is 8.

Worked example

Solve (2−10−12−10−12)x=(101) with the Thomas algorithm.

Show the solution
  1. Sweep down: row 2. Row 2 becomes row 2 + ½ row 1: diagonal=2−12=1.5right side=0+12=0.5
  2. Sweep down: row 3. Row 3 becomes row 3 + 11.5 row 2: diagonal=2−11.5=43right side=1+0.51.5=43
  3. Back substitute. x3=4/34/3=1x2=0.5+x31.5=1x1=1+x22=1
  4. 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 x=(1,1,1).

Worked example

A matrix with κ=104 is factored in float32 (u≈6×10−8) and refined in float64. How does the error fall?

Show the solution
  1. The first solve. It is accurate to about κu32=6×10−4
  2. Each refinement step. It multiplies the error by about 6×10−4 again: 4×10−7, then 2×10−10, then 10−13.
  3. The floor. The error falls until it reaches float64's own limit, about κu64=10−12.
  4. The payoff. Three cheap refinement steps, each costing O(n2), recover what a float64 factorization would give, while the expensive O(n3) factorization ran in float32, often two to four times faster on GPUs.

Answer from about 6×10−4 the error shrinks by about 6×10−4 per step, reaching float64's limit of about 10−12 after three steps.

Check

Factor (42210)=LLT.

(a)

What is l21?

(b)

What is l22?

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

PA=LU needed 3 row swaps, and U has diagonal 2, 3, 0.5. What is det⁡A?

Check

Cholesky on (10.90.91): what is l22?

Check

A matrix with κ = 1000 is factored in float32 (u=6×10−8) 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 x=A−1b for 50 right-hand sides b. What should you compute?

Check

Cholesky on the symmetric matrix (abbc).

Step 1

What is l11?

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°.

Explain why

Why does iterative refinement with a low-precision factorization converge to high-precision accuracy?

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.