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 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 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 , 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 .
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 ω?
About 220. With , the error shrinks by per sweep, against Gauss–Seidel's 0.999. Each sweep costs the same, so the right ω is a 64-fold speedup for free.
Name it
Splittings
Write with M easy to solve, and iterate
The error is multiplied by each step, so the method converges from every start exactly when the spectral radius , its largest eigenvalue in size, is below 1. Each sweep gains digits.
With (diagonal, strictly lower, strictly upper parts):
| Method | M | Update |
|---|---|---|
| Jacobi | D | every from the old values |
| Gauss–Seidel | D + L | each uses the newest values as they're computed |
| SOR | Gauss–Seidel's change, multiplied by ω |
When they converge
If A is strictly diagonally dominant ( in every row), Jacobi and Gauss–Seidel converge. If A is symmetric positive definite, Gauss–Seidel converges, and SOR does for every . Nodal matrices of resistor networks are both.
The model problem
For the five-point Laplacian on an N × N grid, , Gauss–Seidel has , and SOR at
has . Sweeps needed: about 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 is small relative to . With ρ near 1, a small change between sweeps doesn't mean a small error: the remaining error is about times the last change.
Worked example
Do two Jacobi sweeps and one Gauss–Seidel sweep on , , from zero. (The solution is 1, 1, 1.)
Show the solution
- First Jacobi sweep. From zero each equation gives its unknown directly:
- Second Jacobi sweep.
- One Gauss–Seidel sweep. It uses each new value at once:
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
- Jacobi's rate.
- Jacobi's sweeps.
- Gauss–Seidel. It needs half that, 14 000.
- SOR. With 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 , how fast do Jacobi and Gauss–Seidel converge?
Show the solution
- Jacobi's iteration matrix.
- Its eigenvalues. So each sweep shrinks the error by 0.316, about half a digit.
- 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.
- 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 ?
Check
For the model problem Jacobi has = 0.9. What's Gauss–Seidel's spectral radius?
Check
One Jacobi sweep on , from : what's the new ?
Check
Which of these matrices is guaranteed to make Jacobi converge?
Check
Solve 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°.
Step 2
What is SOR's spectral radius at that factor, ?
Explain why
Why does over-relaxation (ω > 1) speed up Gauss–Seidel so much on smooth problems?
On problems like Laplace's equation, the error that survives longest is smooth: it varies slowly across the grid. Each Gauss–Seidel update moves a value toward the average of its neighbors, but for a smooth error the neighbors are almost as wrong as the point itself, so each sweep changes things only slightly, always in the same direction. Over-relaxation multiplies each change by ω, pushing past the Gauss–Seidel value in the direction it was already heading, which is the right direction for smooth errors. At the optimal ω the slowest error shrinks by about per sweep instead of , turning a cost proportional to into one proportional to N. Too large an ω overshoots and the iteration oscillates, and ω ≥ 2 diverges.
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.