Gauss-Seidel Method
The Gauss-Seidel method is an iterative method for solving Ax = b. Like the Jacobi method, it solves each equation for its diagonal variable, but it uses each new value as soon as it is computed. It converges for strictly diagonally dominant matrices, usually about twice as fast as Jacobi.
Before this lesson: Jacobi Method, Fixed-Point Iteration and Partial Pivoting
The idea: use the newest values right away
In the Jacobi method, all of iteration k + 1 is computed from iteration k. But once you have the new x, it is usually a better estimate than the old one. Gauss-Seidel uses it immediately when it computes y, then uses the new x and y when it computes z, and so on.
This small change has two effects. Information spreads through the system faster, so fewer iterations are needed. And only one copy of the vector has to be stored, since each new value overwrites the old one. The cost is that the updates in one sweep must be done in order, not all at once.
The graph compares the two methods on Example 2. The vertical axis is on a log scale, so a straight line means the error shrinks by the same factor each iteration.
Gauss-Seidel formula
For equation i, use the new values for the variables before xᵢ and the old values for the variables after it:
x_i^{(k+1)} = \dfrac{1}{a_{ii}}\left(b_i - \sum_{j \lt i} a_{ij}\, x_j^{(k+1)} - \sum_{j \gt i} a_{ij}\, x_j^{(k)}\right)In matrix form, split A = L + D + U into its strictly lower part, diagonal and strictly upper part. Then
(D + L)\,\mathbf{x}^{(k+1)} = \mathbf{b} - U\,\mathbf{x}^{(k)},\qquad T_{GS} = -(D + L)^{-1}UWhen does Gauss-Seidel converge?
- If A is strictly diagonally dominant, Gauss-Seidel converges for every starting guess.
- If A is symmetric positive definite, Gauss-Seidel also converges for every starting guess (Jacobi need not).
- The exact test: it converges for every start if and only if the spectral radius ρ(T_{GS}) < 1. For many common matrices, such as tridiagonal ones, ρ(T_{GS}) = ρ(T_J)², so one Gauss-Seidel sweep does about the work of two Jacobi sweeps.
How to use the Gauss-Seidel method
- Arrange the equations so the diagonal entries are large (ideally strictly diagonally dominant).
- Solve equation i for xᵢ.
- Start from a guess, often x⁽⁰⁾ = 0.
- Update x₁, then x₂, …, then xₙ, always using the newest values available.
- Stop when the largest change in one sweep is below the tolerance.
Gauss-Seidel method examples
Example 1: A 2 × 2 system
Use Gauss-Seidel on 4x + y = 9 and x + 5y = 7, starting at (0, 0). Do three iterations and compare with Jacobi. The exact solution is (2, 1).
x^{(k+1)} = \dfrac{9 - y^{(k)}}{4},\quad y^{(k+1)} = \dfrac{7 - x^{(k+1)}}{5}The y-update uses the new x.
x^{(1)} = \dfrac{9 - 0}{4} = 2.25Iteration 1: old y = 0.
y^{(1)} = \dfrac{7 - 2.25}{5} = 0.95Use the new x = 2.25.
x^{(2)} = \dfrac{9 - 0.95}{4} = 2.0125Iteration 2: y = 0.95.
y^{(2)} = \dfrac{7 - 2.0125}{5} = 0.9975Use the new x = 2.0125.
x^{(3)} = \dfrac{9 - 0.9975}{4} = 2.000625Iteration 3: y = 0.9975.
y^{(3)} = \dfrac{7 - 2.000625}{5} = 0.999875Use the new x = 2.000625.
Answer: after three iterations, (x, y) = (2.000625, 0.999875), within 0.000625 of (2, 1). Jacobi gave (2.0125, 1.02) after three iterations, an error of 0.02.
Example 2: A 3 × 3 system with an iteration table
Use Gauss-Seidel on the system below, starting at (0, 0, 0). The exact solution is (1, −1, 2).
\begin{aligned} 5x - y + z &= 8 \\ 2x + 8y - z &= -8 \\ -x + y + 4z &= 6 \end{aligned}x = \dfrac{8 + y - z}{5},\quad y = \dfrac{-8 - 2x + z}{8},\quad z = \dfrac{6 + x - y}{4}Solve each equation for its diagonal variable.
x^{(1)} = \dfrac{8 + 0 - 0}{5} = 1.6Iteration 1 starts from (0, 0, 0).
y^{(1)} = \dfrac{-8 - 2(1.6) + 0}{8} = \dfrac{-11.2}{8} = -1.4Use the new x = 1.6.
z^{(1)} = \dfrac{6 + 1.6 - (-1.4)}{4} = \dfrac{9}{4} = 2.25Use the new x and y.
x^{(2)} = \dfrac{8 + (-1.4) - 2.25}{5} = \dfrac{4.35}{5} = 0.87Iteration 2 uses y = −1.4 and z = 2.25.
y^{(2)} = \dfrac{-8 - 2(0.87) + 2.25}{8} = \dfrac{-7.49}{8} = -0.93625Use the new x = 0.87.
z^{(2)} = \dfrac{6 + 0.87 - (-0.93625)}{4} = \dfrac{7.80625}{4} = 1.9515625Use the new x and y.
Continuing gives the table below (rounded to 6 decimal places).
| k | x | y | z | Largest change |
|---|---|---|---|---|
| 0 | 0 | 0 | 0 | — |
| 1 | 1.6 | −1.4 | 2.25 | 2.25 |
| 2 | 0.87 | −0.93625 | 1.951563 | 0.73 |
| 3 | 1.022438 | −1.011664 | 2.008525 | 0.152438 |
| 4 | 0.995962 | −0.997925 | 1.998472 | 0.026475 |
| 5 | 1.000721 | −1.000371 | 2.000273 | 0.004759 |
| 6 | 0.999871 | −0.999934 | 1.999951 | 0.000850 |
Answer: after 6 iterations the largest change is 0.00085 and every component is within 0.00013 of (1, −1, 2). Jacobi needed 8 iterations just to get the largest change below 0.002.
Example 3: Why Gauss-Seidel converges faster
For 4x + y = 9 and x + 5y = 7, write one Gauss-Seidel iteration as a formula for y alone, and find how fast the error shrinks.
x^{(k+1)} = \dfrac{9 - y^{(k)}}{4}First update.
y^{(k+1)} = \dfrac{1}{5}\left(7 - \dfrac{9 - y^{(k)}}{4}\right)Substitute it into the second update.
= \dfrac{28 - 9 + y^{(k)}}{20} = \dfrac{19 + y^{(k)}}{20}Multiply inside by 4/4 and combine (see adding and subtracting fractions).
y^{(k+1)} - 1 = \dfrac{19 + y^{(k)}}{20} - \dfrac{20}{20} = \dfrac{1}{20}\left(y^{(k)} - 1\right)Subtract the exact value y = 1.
\rho(T_{GS}) = \dfrac{1}{20} = 0.05,\quad \rho(T_J) = \sqrt{\dfrac{1}{20}} \approx 0.2236Compare with Jacobi’s rate for the same system.
Answer: each Gauss-Seidel iteration multiplies the error by 0.05, and 0.05 = 0.2236². One Gauss-Seidel sweep does the work of two Jacobi sweeps here.
Example 4: Divergence and the fix
Apply Gauss-Seidel to x + 2y = 3 and 3x + y = 4 (solution (1, 1)) as written, then after swapping the equations.
x = 3 - 2y,\quad y = 4 - 3x
Formulas as written; the diagonal entries are 1 and 1.
x^{(1)} = 3,\quad y^{(1)} = 4 - 3(3) = -5Iteration 1.
x^{(2)} = 3 - 2(-5) = 13,\quad y^{(2)} = 4 - 3(13) = -35Iteration 2: the values blow up.
x = \dfrac{4 - y}{3},\quad y = \dfrac{3 - x}{2}Swap the equations: 3x + y = 4 first, then x + 2y = 3.
x^{(1)} = \dfrac{4}{3} \approx 1.3333,\quad y^{(1)} = \dfrac{3 - \tfrac{4}{3}}{2} = \dfrac{5}{6} \approx 0.8333Iteration 1.
x^{(2)} = \dfrac{4 - \tfrac{5}{6}}{3} = \dfrac{19}{18} \approx 1.0556,\quad y^{(2)} = \dfrac{3 - \tfrac{19}{18}}{2} = \dfrac{35}{36} \approx 0.9722Iteration 2.
x^{(3)} = \dfrac{4 - \tfrac{35}{36}}{3} = \dfrac{109}{108} \approx 1.0093,\quad y^{(3)} = \dfrac{3 - \tfrac{109}{108}}{2} = \dfrac{215}{216} \approx 0.9954Iteration 3.
Answer: as written, the error grows by a factor of 6 each sweep (ρ = 6 = (√6)²). After the swap the system is strictly diagonally dominant, and the error shrinks by a factor of 1/6 each sweep toward (1, 1).
Example 5: Temperatures in a metal plate (word problem)
Return to the plate from the Jacobi lesson: three interior points with 4T₁ − T₂ = 140, −T₁ + 4T₂ − T₃ = 100 and −T₂ + 4T₃ = 180 (edges at 100°C, 0°C, 40°C and 80°C). Do three Gauss-Seidel iterations from 0.
T_1 = \dfrac{140 + T_2}{4},\quad T_2 = \dfrac{100 + T_1 + T_3}{4},\quad T_3 = \dfrac{180 + T_2}{4}Solve each equation for its own temperature.
T_1 = 35,\quad T_2 = \dfrac{100 + 35 + 0}{4} = 33.75,\quad T_3 = \dfrac{180 + 33.75}{4} = 53.4375Iteration 1, using each new value at once.
T_1 = \dfrac{140 + 33.75}{4} = 43.4375Iteration 2.
T_2 = \dfrac{100 + 43.4375 + 53.4375}{4} = \dfrac{196.875}{4} = 49.21875New T₁, old T₃.
T_3 = \dfrac{180 + 49.21875}{4} = 57.3046875New T₂.
T_1 = \dfrac{140 + 49.21875}{4} = 47.3046875Iteration 3.
T_2 = \dfrac{100 + 47.3046875 + 57.3046875}{4} = \dfrac{204.609375}{4} = 51.15234375New T₁, old T₃.
T_3 = \dfrac{180 + 51.15234375}{4} = 57.7880859375New T₂.
Answer: after three iterations, T ≈ (47.30, 51.15, 57.79)°C, compared with the exact (47.86, 51.43, 57.86)°C. Jacobi gave only (46.25, 48.13, 56.25)°C after three iterations.
Common mistakes
| Mistake | Example of the error | Fix |
|---|---|---|
| Using old values for variables already updated | Computing y⁽²⁾ in Example 2 with x = 1.6 instead of 0.87 | In Gauss-Seidel, use every value already found in the current sweep. |
| Using new values for variables not yet updated | Using a “new” z when computing x at the start of a sweep | Variables after xᵢ still have their iteration-k values. |
| Changing the update order between sweeps | Updating x, y, z in one sweep and z, y, x in the next without meaning to | Keep one order; the order affects the iterates (not the final solution). |
| Skipping the convergence check | Running x + 2y = 3, 3x + y = 4 as written | Check diagonal dominance or symmetric positive definiteness first; reorder if needed. |
| Stopping on one small change | Stopping when x barely changes but z still changes by 0.1 | Use the largest change over all variables. |
Related methods
Successive over-relaxation (SOR)
SOR pushes each Gauss-Seidel update further: xᵢ⁽ᵏ⁺¹⁾ = (1 − ω)xᵢ⁽ᵏ⁾ + ω · (Gauss-Seidel value). With 1 < ω < 2 chosen well, it can converge many times faster on large sparse systems. With ω = 1 it is Gauss-Seidel.
Gauss-Seidel versus Jacobi
| Feature | Jacobi | Gauss-Seidel |
|---|---|---|
| Values used | All from iteration k | Newest available |
| Storage | Two vectors | One vector |
| Parallel updates | Yes | No (in order) |
| Typical speed | Slower | About twice as fast |
| Symmetric positive definite A | May fail | Always converges |
Practice problems
- Do two Gauss-Seidel iterations from (0, 0) for 6x − 2y = 10 and x + 4y = 6.
- Do three Gauss-Seidel iterations from (0, 0) for 2x − y = 1 and −x + 2y = 1.
- In a 3 × 3 Gauss-Seidel sweep in the order x, y, z, which values are used to compute z⁽ᵏ⁺¹⁾?
- For 6x − 2y = 10 and x + 4y = 6, write one Gauss-Seidel iteration as a formula for y alone. What is the error factor per iteration?
- Reorder x + 3y = 5 and 4x − y = 7 so Gauss-Seidel converges, then do two iterations from (0, 0).
- Is Gauss-Seidel guaranteed to converge for A = \begin{bmatrix} 2 & 1 \\ 1 & 2 \end{bmatrix}? Give two reasons.
- If ρ(T_{GS}) = 0.05, how many iterations reduce the error by a factor of at least 10⁶? How many does Jacobi need if ρ(T_J) = 0.2236?
- A rod has two interior points with 2T₁ − T₂ = 100 and −T₁ + 2T₂ = 40. Do three Gauss-Seidel iterations from 0. The exact solution is (80, 60).
- Do one Gauss-Seidel iteration from (0, 0, 0) for 4x + y + z = 7, x + 5y − z = 10, x − y + 3z = 2.
- Why is Gauss-Seidel harder to run in parallel than Jacobi?
Show answers
1.
x = \dfrac{10 + 2y}{6},\quad y = \dfrac{6 - x}{4}Solve for the diagonal variables.
x^{(1)} = \dfrac{10}{6} = \dfrac{5}{3},\quad y^{(1)} = \dfrac{6 - \tfrac{5}{3}}{4} = \dfrac{13}{12}Iteration 1; y uses the new x.
x^{(2)} = \dfrac{10 + \tfrac{13}{6}}{6} = \dfrac{73}{36} \approx 2.0278Iteration 2: 2y = 13/6.
y^{(2)} = \dfrac{6 - \tfrac{73}{36}}{4} = \dfrac{143}{144} \approx 0.9931Use the new x.
Answer: (2.0278, 0.9931); the exact solution is (2, 1)
2.
x = \dfrac{1 + y}{2},\quad y = \dfrac{1 + x}{2}Gauss-Seidel formulas.
(0.5,\ 0.75) \to (0.875,\ 0.9375) \to (0.96875,\ 0.984375)
For example, y⁽¹⁾ = (1 + 0.5)/2 = 0.75.
Answer: (0.96875, 0.984375), approaching (1, 1)
3.
Answer: the new x⁽ᵏ⁺¹⁾ and y⁽ᵏ⁺¹⁾ from the same sweep
4.
x^{(k+1)} = \dfrac{10 + 2y^{(k)}}{6} = \dfrac{5 + y^{(k)}}{3}Simplify the x-update.
y^{(k+1)} = \dfrac{1}{4}\left(6 - \dfrac{5 + y^{(k)}}{3}\right) = \dfrac{13 - y^{(k)}}{12}Substitute and combine.
y^{(k+1)} - 1 = -\dfrac{1}{12}\left(y^{(k)} - 1\right)Subtract the exact value y = 1.
Answer: y⁽ᵏ⁺¹⁾ = (13 − y⁽ᵏ⁾)/12; the error is multiplied by −1/12 each iteration (factor 1/12 ≈ 0.083)
5.
4x - y = 7,\quad x + 3y = 5
Swap so |4| > 1 and |3| > 1.
x^{(1)} = \dfrac{7}{4} = 1.75,\quad y^{(1)} = \dfrac{5 - 1.75}{3} = \dfrac{13}{12} \approx 1.0833Iteration 1.
x^{(2)} = \dfrac{7 + \tfrac{13}{12}}{4} = \dfrac{97}{48} \approx 2.0208,\quad y^{(2)} = \dfrac{5 - \tfrac{97}{48}}{3} = \dfrac{143}{144} \approx 0.9931Iteration 2.
Answer: (2.0208, 0.9931), approaching (2, 1)
6.
2 \gt 1
Each diagonal entry beats the other entry in its row.
\det A = 4 - 1 = 3 \gt 0,\quad a_{11} = 2 \gt 0A is symmetric with positive leading minors, so it is positive definite.
Answer: yes; A is strictly diagonally dominant and also symmetric positive definite
7.
0.05^k \le 10^{-6} \Rightarrow k \ge \dfrac{6}{\log_{10} 20} \approx 4.61Take logs (see logarithms).
0.2236^k \le 10^{-6} \Rightarrow k \ge \dfrac{6}{-\log_{10} 0.2236} \approx 9.22Same for Jacobi.
Answer: 5 Gauss-Seidel iterations versus 10 Jacobi iterations
8.
T_1 = \dfrac{100 + T_2}{2},\quad T_2 = \dfrac{40 + T_1}{2}Gauss-Seidel formulas.
(50,\ 45) \to (72.5,\ 56.25) \to (78.125,\ 59.0625)
For example, T₂ = (40 + 50)/2 = 45.
Answer: (78.125, 59.0625); Jacobi gave (72.5, 50) after three iterations
9.
x = \dfrac{7 - 0 - 0}{4} = 1.75Old y = z = 0.
y = \dfrac{10 - 1.75 + 0}{5} = 1.65New x, old z.
z = \dfrac{2 - 1.75 + 1.65}{3} = \dfrac{1.9}{3} \approx 0.6333New x and y.
Answer: (1.75, 1.65, 0.6333); the exact solution is (1, 2, 1)
10.
Answer: each update needs the values just computed in the same sweep, so x₂ must wait for x₁, x₃ for x₂, and so on; Jacobi’s updates are independent
Gauss-Seidel method FAQ
What is the Gauss-Seidel method?
It is an iterative method for Ax = b that solves each equation for its diagonal variable and updates the variables one at a time, always using the newest values available.
Is Gauss-Seidel faster than Jacobi?
Usually yes. For many common matrices its error factor per iteration is the square of Jacobi’s, so it needs about half as many iterations. Jacobi can still be faster on parallel hardware.
When does the Gauss-Seidel method converge?
It converges for every starting guess when A is strictly diagonally dominant or symmetric positive definite. The exact condition is that the spectral radius of its iteration matrix is less than 1.
What is the difference between Gauss-Seidel and SOR?
SOR (successive over-relaxation) takes the Gauss-Seidel update and moves further in the same direction by a factor ω. With ω = 1, SOR is exactly Gauss-Seidel.
Summary
- Gauss-Seidel updates x₁, x₂, …, xₙ in order, using each new value immediately.
- Each new xᵢ uses new values for the variables before it and old values for the variables after it.
- It converges for strictly diagonally dominant or symmetric positive definite matrices.
- It is usually about twice as fast as Jacobi but harder to parallelize.
- SOR adds a relaxation factor ω to speed it up further.
Previous lesson: Jacobi Method
Next lesson: Condition Number of a Matrix
Back to the Numerical Methods Index