Tutorials › Linear Algebra › Deriving the Gauss-Seidel Iteration

LU Factorization and Numerical Considerations · Tutorial 928 of 1000

Deriving the Gauss-Seidel Iteration

Learn to derive the Gauss-Seidel update, carry out its component-by-component sweeps, and distinguish its use of fresh values from Jacobi’s.

Intermediate 9 min read

What You'll Learn

  • Split a matrix into its diagonal, strict lower-triangular, and strict upper-triangular parts.
  • Derive the Gauss-Seidel matrix equation from the component equations.
  • Identify the nonzero-diagonal condition that makes each sweep well-defined.
  • Compute successive Gauss-Seidel iterates using exact arithmetic.
  • Check an iterate by evaluating its residual in the original system.
  • Explain why a fixed point of the iteration solves the linear system.

From a Linear System to an Iteration

For a system \(\mathbf{A}\mathbf{x}=\mathbf{b}\), a direct method seeks the solution by a finite sequence of operations. An iterative method instead begins with a chosen vector \(\mathbf{x}^{(0)}\) and constructs successive approximations \(\mathbf{x}^{(1)},\mathbf{x}^{(2)},\ldots\). The Gauss-Seidel method is one such method. Its defining feature is the order in which it uses the components: during a sweep, each component is updated in turn, and the newly computed values are used immediately in the remaining updates.

Work over \(\mathbb{R}\), with \(\mathbf{A}\in\mathbb{R}^{n\times n}\), \(\mathbf{x},\mathbf{b}\in\mathbb{R}^n\), and \(a_{ii}\ne0\) for every \(i\). The nonzero diagonal condition matters: each component update divides by \(a_{ii}\). Write the system row by row as \(a_{ii}x_i=b_i-\sum_{j\ne i}a_{ij}x_j\). Gauss-Seidel turns these equations into a sequence of updates by using new values for components with indices below \(i\), and the old values for components with indices above \(i\).

Definition: Given an initial vector \(\mathbf{x}^{(0)}\), one Gauss-Seidel sweep computes, in order for \(i=1,\ldots,n\), $$ x_i^{(k+1)} =\frac{1}{a_{ii}}\left( b_i-\sum_{j=1}^{i-1}a_{ij}x_j^{(k+1)} -\sum_{j=i+1}^{n}a_{ij}x_j^{(k)} \right). $$ An empty sum is \(0\). Thus the update for \(x_i^{(k+1)}\) uses the new components \(x_1^{(k+1)},\ldots,x_{i-1}^{(k+1)}\), and the old components \(x_{i+1}^{(k)},\ldots,x_n^{(k)}\).

The order is part of the method: the updates are performed from component 1 to component \(n\). In particular, when \(i=1\), there are no new components to use, while when \(i=n\), every other component in that equation has already been updated. The method is well-defined for every initial vector when all diagonal entries are nonzero. This condition does not by itself say that the iterates approach the solution; convergence is a separate question.

The Matrix Form of a Sweep

Let \(\mathbf{D}\) contain the diagonal entries of \(\mathbf{A}\), let \(\mathbf{L}\) contain its entries strictly below the diagonal, and let \(\mathbf{U}\) contain its entries strictly above the diagonal. Then \(\mathbf{A}=\mathbf{D}+\mathbf{L}+\mathbf{U}\). The entries of \(\mathbf{L}\) and \(\mathbf{U}\) retain their signs as they appear in \(\mathbf{A}\). The component update can now be written as one matrix equation.

Theorem (Gauss-Seidel update): Suppose every diagonal entry of \(\mathbf{A}\in\mathbb{R}^{n\times n}\) is nonzero, and split \(\mathbf{A}=\mathbf{D}+\mathbf{L}+\mathbf{U}\) as above. One Gauss-Seidel sweep is exactly $$ (\mathbf{D}+\mathbf{L})\mathbf{x}^{(k+1)} =\mathbf{b}-\mathbf{U}\mathbf{x}^{(k)}. $$ Moreover, \(\mathbf{D}+\mathbf{L}\) is invertible, so the sweep is equivalently $$ \mathbf{x}^{(k+1)} =-(\mathbf{D}+\mathbf{L})^{-1}\mathbf{U}\mathbf{x}^{(k)} +(\mathbf{D}+\mathbf{L})^{-1}\mathbf{b}. $$

Proof. In row \(i\), the product \((\mathbf{D}+\mathbf{L})\mathbf{x}^{(k+1)}\) is \(a_{ii}x_i^{(k+1)}+\sum_{j=1}^{i-1}a_{ij}x_j^{(k+1)}\). The row \(i\) entry of \(\mathbf{U}\mathbf{x}^{(k)}\) is \(\sum_{j=i+1}^{n}a_{ij}x_j^{(k)}\). Consequently, row \(i\) of the matrix equation is precisely the component update after multiplying that update by \(a_{ii}\) and moving the new lower-index terms to the left. This holds for every \(i\), so the matrix equation and the component sweep are equivalent.

To check invertibility, consider \((\mathbf{D}+\mathbf{L})\mathbf{z}=\mathbf{0}\). Its first row gives \(a_{11}z_1=0\), so \(z_1=0\). If \(z_1,\ldots,z_{i-1}=0\), row \(i\) gives \(a_{ii}z_i=0\), so \(z_i=0\). Induction shows that the only solution is \(\mathbf{z}=\mathbf{0}\). Also, for any right-hand side, each row can be solved in order by dividing by the nonzero \(a_{ii}\), giving a unique solution. Thus \(\mathbf{D}+\mathbf{L}\) is invertible. Multiplying the matrix equation by its inverse gives the displayed iteration formula. \(\square\)

The matrix form summarizes the same update rule; it does not change it. In particular, the lower-triangular part \(\mathbf{D}+\mathbf{L}\) acts on the new iterate, while the strictly upper-triangular part acts on the old iterate. Since \(\mathbf{D}+\mathbf{L}\) is lower triangular with nonzero diagonal, each sweep can be carried out by forward substitution, rather than by forming its inverse.

Working Through the Component Updates

Worked Example: Two Components and Two Sweeps

Apply Gauss-Seidel to \(\begin{bmatrix}4&1\\2&3\end{bmatrix}\mathbf{x}=\begin{bmatrix}1\\2\end{bmatrix}\), starting from \(\mathbf{x}^{(0)}=\begin{bmatrix}0\\0\end{bmatrix}\). The row equations give \(x_1^{(k+1)}=(1-x_2^{(k)})/4\) and \(x_2^{(k+1)}=(2-2x_1^{(k+1)})/3\).

For the first sweep, \(x_2^{(0)}=0\), so \(x_1^{(1)}=(1-0)/4=1/4\). Use this new value immediately: \(x_2^{(1)}=(2-2(1/4))/3=(2-1/2)/3=(3/2)/3=1/2\). Thus \(\mathbf{x}^{(1)}=\begin{bmatrix}1/4\\1/2\end{bmatrix}\).

For the second sweep, use \(x_2^{(1)}\) to calculate the first component: \(x_1^{(2)}=(1-1/2)/4=1/8\). Then use that newly computed component: \(x_2^{(2)}=(2-2(1/8))/3=(2-1/4)/3=(7/4)/3=7/12\). Therefore \(\mathbf{x}^{(2)}=\begin{bmatrix}1/8\\7/12\end{bmatrix}\).

Check: Multiplication by the original matrix gives \(\begin{bmatrix}4&1\\2&3\end{bmatrix}\mathbf{x}^{(2)} =\begin{bmatrix}4(1/8)+7/12\\2(1/8)+3(7/12)\end{bmatrix} =\begin{bmatrix}13/12\\2\end{bmatrix}\). The residual \(\mathbf{b}-\mathbf{A}\mathbf{x}^{(2)}\) is therefore \(\begin{bmatrix}-1/12\\0\end{bmatrix}\). The second row is satisfied exactly because its update was the last step in the sweep; the first row need not be satisfied exactly yet.

This last check illustrates how to interpret an intermediate iterate. It is an approximation, not automatically an exact solution. Also, Gauss-Seidel does not solve every row simultaneously using the same vector: it satisfies each row update in sequence, with a mixture of new and old components during the sweep.

Worked Example: A Three-Component Sweep

Consider $$ \begin{bmatrix} 4&-1&0\\ -1&4&-1\\ 0&-1&3 \end{bmatrix}\mathbf{x} = \begin{bmatrix}15\\10\\10\end{bmatrix}, \qquad \mathbf{x}^{(0)}=\begin{bmatrix}0\\0\\0\end{bmatrix}. $$ The component equations for the sweep, in order, are \(x_1^{(k+1)}=(15+x_2^{(k)})/4\), \(x_2^{(k+1)}=(10+x_1^{(k+1)}+x_3^{(k)})/4\), and \(x_3^{(k+1)}=(10+x_2^{(k+1)})/3\).

Starting with the zero vector, \(x_1^{(1)}=15/4\). Next, \(x_2^{(1)}=(10+15/4+0)/4=(55/4)/4=55/16\). Finally, \(x_3^{(1)}=(10+55/16)/3=(160/16+55/16)/3=(215/16)/3=215/48\). Thus \(\mathbf{x}^{(1)}=\begin{bmatrix}15/4\\55/16\\215/48\end{bmatrix}\).

Check: In the original system, the third row gives \(-55/16+3(215/48)=-165/48+645/48=10\), as required. The first row gives \(4(15/4)-55/16=15-55/16=185/16\), and the second gives \(-15/4+4(55/16)-215/48=-180/48+660/48-215/48=265/48\). The first two rows are not yet exact, which is consistent with these being first-sweep iterates rather than a claimed solution.

For this example the matrix split makes the update especially visible:

$$ \mathbf{D}+\mathbf{L} =\begin{bmatrix}4&0&0\\-1&4&0\\0&-1&3\end{bmatrix}, \qquad \mathbf{U} =\begin{bmatrix}0&-1&0\\0&0&-1\\0&0&0\end{bmatrix}. $$

The first and second entries of \(\mathbf{U}\mathbf{x}^{(k)}\) use old components, while solving with \(\mathbf{D}+\mathbf{L}\) in order incorporates the new components as soon as they are available.

Worked Example: Fresh Values in a Full Three-Component System

Apply two sweeps to \(\begin{bmatrix}2&1&1\\1&3&1\\1&1&4\end{bmatrix}\mathbf{x}=\begin{bmatrix}4\\5\\6\end{bmatrix}\), starting from \(\mathbf{x}^{(0)}=\begin{bmatrix}0\\0\\0\end{bmatrix}\). The ordered updates are \(x_1^{(k+1)}=(4-x_2^{(k)}-x_3^{(k)})/2\), \(x_2^{(k+1)}=(5-x_1^{(k+1)}-x_3^{(k)})/3\), and \(x_3^{(k+1)}=(6-x_1^{(k+1)}-x_2^{(k+1)})/4\).

The first sweep gives \(x_1^{(1)}=4/2=2\), \(x_2^{(1)}=(5-2-0)/3=1\), and \(x_3^{(1)}=(6-2-1)/4=3/4\). Hence \(\mathbf{x}^{(1)}=\begin{bmatrix}2\\1\\3/4\end{bmatrix}\).

For the second sweep, \(x_1^{(2)}=(4-1-3/4)/2=(9/4)/2=9/8\). Then \(x_2^{(2)}=(5-9/8-3/4)/3=(40/8-9/8-6/8)/3=(25/8)/3=25/24\). Lastly, \(x_3^{(2)}=(6-9/8-25/24)/4=(144/24-27/24-25/24)/4=(92/24)/4=23/24\). Thus \(\mathbf{x}^{(2)}=\begin{bmatrix}9/8\\25/24\\23/24\end{bmatrix}\).

Check: Multiplying by the original matrix gives \(\mathbf{A}\mathbf{x}^{(2)}=\begin{bmatrix}17/4\\125/24\\6\end{bmatrix}\). For example, the first component is \(2(9/8)+25/24+23/24=54/24+25/24+23/24=17/4\); the second is \(9/8+3(25/24)+23/24=27/24+75/24+23/24=125/24\); and the third is \(9/8+25/24+4(23/24)=27/24+25/24+92/24=6\). The residual is \(\mathbf{b}-\mathbf{A}\mathbf{x}^{(2)}=\begin{bmatrix}-1/4\\-5/24\\0\end{bmatrix}\).

Fixed Points and Solutions

The matrix form also gives a precise connection between the iteration and the original system. A fixed point of an iteration is a vector that is unchanged by one application of its update rule. This connection identifies what Gauss-Seidel is trying to reach, without asserting that a particular sequence of iterates will reach it.

Theorem: Suppose every diagonal entry of \(\mathbf{A}\in\mathbb{R}^{n\times n}\) is nonzero. A vector \(\mathbf{x}\) is a fixed point of the Gauss-Seidel update if and only if \(\mathbf{A}\mathbf{x}=\mathbf{b}\). If \(\mathbf{A}\) is invertible, the fixed point is the unique solution of the system.

Proof. The update is \((\mathbf{D}+\mathbf{L})\mathbf{x}^{(k+1)}=\mathbf{b}-\mathbf{U}\mathbf{x}^{(k)}\). If \(\mathbf{x}\) is a fixed point, set \(\mathbf{x}^{(k+1)}=\mathbf{x}^{(k)}=\mathbf{x}\). Then \((\mathbf{D}+\mathbf{L})\mathbf{x}=\mathbf{b}-\mathbf{U}\mathbf{x}\). Adding \(\mathbf{U}\mathbf{x}\) to both sides gives \((\mathbf{D}+\mathbf{L}+\mathbf{U})\mathbf{x}=\mathbf{b}\), which is \(\mathbf{A}\mathbf{x}=\mathbf{b}\). Conversely, if \(\mathbf{A}\mathbf{x}=\mathbf{b}\), use \(\mathbf{A}=\mathbf{D}+\mathbf{L}+\mathbf{U}\) and rearrange to obtain \((\mathbf{D}+\mathbf{L})\mathbf{x}=\mathbf{b}-\mathbf{U}\mathbf{x}\). Since \(\mathbf{D}+\mathbf{L}\) is invertible, this is exactly the update with the same vector on both sides as the old and new iterate. Thus \(\mathbf{x}\) is a fixed point. If \(\mathbf{A}\) is invertible, the system has a unique solution, so this fixed point is unique. \(\square\)

Invertibility of \(\mathbf{A}\) is not needed for the equivalence: every fixed point solves the system, and every solution is a fixed point. Invertibility is needed for the stated uniqueness. Neither the fixed-point equivalence nor uniqueness establishes that the sequence from an arbitrary initial vector approaches a fixed point.

Common Mistake: Reusing an Old Component

In the full three-component example, a common error is to calculate the second component from the old first component, as if every component were being updated from \(\mathbf{x}^{(0)}\). That gives the incorrect Gauss-Seidel calculation \(x_2^{(1)}=(5-0-0)/3=5/3\). It fails to use the just-computed value \(x_1^{(1)}=2\). The correct calculation is \(x_2^{(1)}=(5-2-0)/3=1\). The third update must then use both new values: \(x_3^{(1)}=(6-2-1)/4=3/4\).

Using old values for every component is the defining update pattern of the Jacobi iteration, not Gauss-Seidel. A reliable way to avoid mixing the methods is to write the update equations in index order and mark each component as soon as it has been computed. For \(x_i^{(k+1)}\), indices below \(i\) use the new iterate, and indices above \(i\) use the old one.

Finally, a zero diagonal entry prevents the displayed component rule from being used in that row because it requires division by \(a_{ii}\). This does not by itself show that the system has no solution; it means this particular ordering and direct component update are not available as written. One must not silently divide by zero or infer a conclusion about the system’s solvability from the failure of the update formula.

Check Your Understanding

For each question, keep the order of component updates explicit and use exact arithmetic.

  1. For \(\begin{bmatrix}3&1\\1&2\end{bmatrix}\mathbf{x}=\begin{bmatrix}5\\5\end{bmatrix}\) and \(\mathbf{x}^{(0)}=\begin{bmatrix}0\\0\end{bmatrix}\), compute one Gauss-Seidel sweep.
  2. Write the Gauss-Seidel component updates for a general \(3\times3\) system with nonzero diagonal entries.
  3. For \(\mathbf{A}=\begin{bmatrix}2&-1\\4&3\end{bmatrix}\), identify \(\mathbf{D}\), \(\mathbf{L}\), and \(\mathbf{U}\), and write the matrix equation for one sweep.
  4. Explain why a Gauss-Seidel sweep is well-defined when every diagonal entry of \(\mathbf{A}\) is nonzero.
  5. State and justify the relationship between a fixed point of the Gauss-Seidel update and a solution of \(\mathbf{A}\mathbf{x}=\mathbf{b}\).

Test yourself: Linear Algebra final exam practice

Ready to check what you know? Work a full-length practice final, then open the complete worked solutions.

Want all 1,114 practice problems?

This tutorial covers one topic. Calc Pass covers the full Calculus AB & BC curriculum (the core of Calculus I and II): full review, every practice question, and step-by-step solutions to each one.

QR code to download the Calc Pass app

Get the Calc Pass App

Scan to download and practice on the go, with instant scoring.

Calc Pass Volume 1: 1,114 Practice Questions book cover

Vol. 1: 1,114 Questions

The complete practice question bank, organized by AB & BC topic.

View on Amazon
Calc Pass Volume 2: Solutions Manual book cover

Vol. 2: Solutions Manual

Fully worked solutions to every question in Volume 1.

View on Amazon