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

A13 · Lesson 27 · Iterative linear solvers: Jacobi, Gauss–Seidel and SOR

Solving big sparse systems by repeated cheap sweeps

A field solver on a 1000 × 1000 grid has a million unknowns. Gaussian elimination on the dense matrix would need 23×1018 operations and 8 TB of memory. But each equation involves only five unknowns, and an iterative method exploits that: it starts from a guess and repeatedly updates each unknown from its neighbors, at a cost proportional to the number of nonzeros per sweep. You did this in A9 and A12's relaxation labs. This lesson explains when such sweeps converge, why plain relaxation is so slow, and how one parameter, the over-relaxation factor ω, can make it a hundred times faster.

  • The curve shows how many sweeps SOR needs to cut the error by 106 on the model problem (Laplace's equation on an N × N grid), against ω.
  • ω = 1 is Gauss–Seidel. Raise ω and the count drops steeply to a sharp minimum at ωopt=21+sin⁡(π/N), then rises again; past 2 it diverges.
  • Raise N: the minimum moves toward 2 and grows only in proportion to N, while Gauss–Seidel's count grows as N2.

Predict

On a 100 × 100 grid, Gauss–Seidel needs about 14 000 sweeps to gain 6 digits. About how many does SOR need at the best ω?

Name it

Splittings

Write A=M−N with M easy to solve, and iterate

Mx(k+1)=Nx(k)+b

The error is multiplied by G=M−1N each step, so the method converges from every start exactly when the spectral radius ρ(G), its largest eigenvalue in size, is below 1. Each sweep gains log10⁡(1/ρ) digits.

With A=D+L+U (diagonal, strictly lower, strictly upper parts):

MethodMUpdate
JacobiDevery xi from the old values
Gauss–SeidelD + Leach xi uses the newest values as they're computed
SOR1ωD+LGauss–Seidel's change, multiplied by ω

When they converge

If A is strictly diagonally dominant (|aii|>∑j≠i|aij| in every row), Jacobi and Gauss–Seidel converge. If A is symmetric positive definite, Gauss–Seidel converges, and SOR does for every 0<ω<2. Nodal matrices of resistor networks are both.

The model problem

For the five-point Laplacian on an N × N grid, ρJ=cos⁡πN≈1−π22N2, Gauss–Seidel has ρJ2, and SOR at

ωopt=21+sin⁡(π/N)

has ρ=ωopt−1≈1−2πN. Sweeps needed: about N2 for Jacobi and Gauss–Seidel, about N for optimal SOR. Multigrid (A12's relaxation done on a hierarchy of grids) gets it down to a fixed number, independent of N.

Stopping

Stop when the residual ‖b−Ax‖ is small relative to ‖b‖. With ρ near 1, a small change between sweeps doesn't mean a small error: the remaining error is about ρ1−ρ times the last change.

Worked example

Do two Jacobi sweeps and one Gauss–Seidel sweep on 4x1−x2=3, −x1+4x2−x3=2, −x2+4x3=3 from zero. (The solution is 1, 1, 1.)

Show the solution
  1. First Jacobi sweep. From zero each equation gives its unknown directly: x=(0.75,0.5,0.75)
  2. Second Jacobi sweep. x1=3+0.54=0.875x2=2+0.75+0.754=0.875x3=3+0.54=0.875
  3. One Gauss–Seidel sweep. It uses each new value at once: x1=0.75x2=2+0.754=0.6875x3=3+0.68754=0.9219

Answer Jacobi gives (0.75, 0.5, 0.75) and then (0.875, 0.875, 0.875); one Gauss–Seidel sweep gives (0.75, 0.6875, 0.9219).

Worked example

How many sweeps does each method need on a 100 × 100 grid to gain 6 digits?

Show the solution
  1. Jacobi's rate. ρJ=cos⁡(π/100)=0.999507
  2. Jacobi's sweeps. 6ln⁡10−ln⁡0.999507=28000
  3. Gauss–Seidel. It needs half that, 14 000.
  4. SOR. With ωopt=1.9391 it has ρ = 0.9391 and needs 220.

Answer about 28 000 sweeps for Jacobi, 14 000 for Gauss–Seidel and 220 for SOR.

Worked example

For (4125)x=b, how fast do Jacobi and Gauss–Seidel converge?

Show the solution
  1. Jacobi's iteration matrix. −D−1(L+U)=(0−1/4−2/50)
  2. Its eigenvalues. ±14⋅25=±0.316 So each sweep shrinks the error by 0.316, about half a digit.
  3. Gauss–Seidel. For a 2 × 2 matrix like this one, its spectral radius is the square of Jacobi's, 0.1: a full digit per sweep.
  4. The general pattern. The same relation holds for the model problems of this lesson, which is why Gauss–Seidel needs half as many sweeps.

Answer Jacobi shrinks the error by 0.316 per sweep and Gauss–Seidel by 0.1.

Check

What's the optimal SOR factor for the model problem on a 50 × 50 grid?

Check

About how many Jacobi sweeps does the model problem on a 50 × 50 grid need to gain 6 digits?

Check

And how many SOR sweeps at ωopt?

Check

For the model problem Jacobi has ρJ = 0.9. What's Gauss–Seidel's spectral radius?

Check

One Jacobi sweep on 5x1+x2=6, x1+5x2=8 from x=(1,1): what's the new x1?

Check

Which of these matrices is guaranteed to make Jacobi converge?

Check

Solve (2113)x=c iteratively.

(a)

What is Jacobi's spectral radius?

(b)

What is Gauss–Seidel's?

Check

For the model problem, Jacobi's spectral radius is r.

Step 1

What is the optimal SOR factor?

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 over-relaxation (ω > 1) speed up Gauss–Seidel so much on smooth problems?

Practice

Keep practicing

9 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.