Loading [MathJax]/jax/output/HTML-CSS/jax.js
Skip to main content
Library homepage
 

Text Color

Text Size

 

Margin Size

 

Font Type

Enable Dyslexic Font
Mathematics LibreTexts

8: Gauss-Seidel Method

( \newcommand{\kernel}{\mathrm{null}\,}\)

Learning Objectives

After reading this chapter, you should be able to:

  1. solve a set of equations using the Gauss-Seidel method,
  2. recognize the advantages and pitfalls of the Gauss-Seidel method, and
  3. determine under what conditions the Gauss-Seidel method always converges.

Why do we need another method to solve a set of simultaneous linear equations?

In certain cases, such as when a system of equations is large, iterative methods of solving equations are more advantageous. Elimination methods, such as Gaussian elimination, are prone to large round-off errors for a large set of equations. Iterative methods, such as the Gauss-Seidel method, give the user control of the round-off error. Also, if the physics of the problem are well known, initial guesses needed in iterative methods can be made more judiciously leading to faster convergence.

What is the algorithm for the Gauss-Seidel method? Given a general set of n equations and n unknowns, we have

a11x1+a12x2+a13x3+...+a1nxn=c1

a21x1+a22x2+a23x3+...+a2nxn=c2

                   

an1x1+an2x2+an3x3+...+annxn=cn

If the diagonal elements are non-zero, each equation is rewritten for the corresponding unknown, that is, the first equation is rewritten with x1 on the left hand side, the second equation is rewritten with x2 on the left hand side and so on as follows

x1=c1a12x2a13x3a1nxna11

x2=c2a21x1a23x3a2nxna22

xn1=cn1an1,1x1an1,2x2an1,n2xn2an1,nxnan1,n1

xn=cnan1x1an2x2an,n1xn1ann

These equations can be rewritten in a summation form as

x1=c1nj=1j1a1jxja11

x2=c2nj=1j2a2jxja22

xn1=cn1nj=1jn1an1,jxjan1,n1

xn=cnnj=1jnanjxjann

Hence for any row i,

xi=cinj=1jiaijxjaii,i=1,2,,n.

Now to find xi’s, one assumes an initial guess for the xi’s and then uses the rewritten equations to calculate the new estimates. Remember, one always uses the most recent estimates to calculate the next estimates, xi. At the end of each iteration, one calculates the absolute relative approximate error for each xi as

|a|i=|xnewixoldixnewi|×100

where xnewiis the recently obtained value of xi, and xoldi is the previous value of xi.

When the absolute relative approximate error for each xi is less than the pre-specified tolerance, the iterations are stopped.

Example 1

The upward velocity of a rocket is given at three different times in the following table

Table 1: Velocity vs. time data.

Time, t(s) Velocity, v(m/s)
5 106.8
8 177.2
12 279.2

The velocity data is approximated by a polynomial as

v(t)=a1t2+a2t+a3,5t12

Find the values of a1, a2,and a3 using the Gauss-Seidel method. Assume an initial guess of the solution as

[a1a2a3]=[125]

and conduct two iterations.

Solution

The polynomial is going through three data points (t1,v1),(t2,v2),and(t3,v3) where from the above table

t1=5,v1=106.8

t2=8,v2=177.2

t3=12,v3=279.2

Requiring that v(t)=a1t2+a2t+a3passes through the three data points gives

v(t1)=v1=a1t21+a2t1+a3

v(t2)=v2=a1t22+a2t2+a3

v(t3)=v3=a1t23+a2t3+a3

Substituting the data (t1,v1),(t2,v2),and(t3,v3) gives

a1(52)+a2(5)+a3=106.8

a1(82)+a2(8)+a3=177.2

a1(122)+a2(12)+a3=279.2

or

25a1+5a2+a3=106.8

64a1+8a2+a3=177.2

144a1+12a2+a3=279.2

The coefficients a1,a2,anda3 for the above expression are given by

[25516481144121][a1a2a3]=[106.8177.2279.2]

Rewriting the equations gives

a1=106.85a2a325

a2=177.264a1a38

a3=279.2144a112a21

Iteration #1

Given the initial guess of the solution vector as

[a1a2a3]=[125]

we get

a1=106.85(2)(5)25=3.6720

a2=177.264(3.6720)(5)8=7.8150

a3=279.2144(3.6720)12(7.8510)1=155.36

The absolute relative approximate error for each xi then is

|a|1=|3.672013.6720|×100=72.76%

|a|2=|7.851027.8510|×100=125.47%

|a|3=|155.365155.36|×100=103.22%

At the end of the first iteration, the estimate of the solution vector is

[a1a2a3]=[3.67207.8510155.36]

and the maximum absolute relative approximate error is 125.47.

Iteration #2

The estimate of the solution vector at the end of Iteration #1 is

[a1a2a3]=[3.67207.8510155.36]

Now we get

a1=106.85(7.8510)(155.36)25=12.056

a2=177.264(12.056)(155.36)8=54.882

a3=279.2144(12.056)12(54.882)1=798.34

The absolute relative approximate error for each xi then is

|a|1=|12.0563.672012.056|×100=69.543%

|a|2=|54.882(7.8510)54.882|×100=85.695%

|a|3=|798.34(155.36)798.34|×100=80.540%

At the end of the second iteration the estimate of the solution vector is

[a1a2a3]=[12.05654.882798.54]

and the maximum absolute relative approximate error is 85.695%.

Conducting more iterations gives the following values for the solution vector and the corresponding absolute relative approximate errors.

Iteration a1 |a|1% a2 |a|2% a3 |a|3%
1 3.672 72.767 –7.8510 125.47 –155.36 103.22
2 12.056 69.543 –54.882 85.695 –798.34 80.54
3 47.182 74.447 –255.51 78.521 –3448.9 76.852
4 193.33 75.595 –1093.4 76.632 –14440 76.116
5 800.53 75.85 –4577.2 76.112 –60072 75.963
6 3322.6 75.906 –19049 75.972 –249580 75.931

As seen in the above table, the solution estimates are not converging to the true solution of

a1=0.29048

a2=19.690

a3=1.0857

The above system of equations does not seem to converge. Why?

Well, a pitfall of most iterative methods is that they may or may not converge. However, the solution to a certain class of system of simultaneous equations does always converge using the Gauss-Seidel method. This class of system of equations is where the coefficient matrix [A] in [A][X]=[C] is diagonally dominant, that is

|aii|nj=1ji|aij| for all i

|aii|>nj=1ji|aij|for at least one i

If a system of equations has a coefficient matrix that is not diagonally dominant, it may or may not converge. Fortunately, many physical systems that result in simultaneous linear equations have a diagonally dominant coefficient matrix, which then assures convergence for iterative methods such as the Gauss-Seidel method of solving simultaneous linear equations.

Example 2

Find the solution to the following system of equations using the Gauss-Seidel method.

12x1+3x25x3=1

x1+5x2+3x3=28

3x1+7x2+13x3=76

Use

[x1x2x3]=[101]

as the initial guess and conduct two iterations.

Solution1

The coefficient matrix

[A]=[12351533713]

is diagonally dominant as

|a11|=|12|=12|a12|+|a13|=|3|+|5|=8

|a22|=|5|=5|a21|+|a23|=|1|+|3|=4

|a33|=|13|=13|a31|+|a32|=|3|+|7|=10

and the inequality is strictly greater than for at least one row. Hence, the solution should converge using the Gauss-Seidel method.

Rewriting the equations, we get

x1=13x2+5x312

x2=28x13x35

x3=763x17x213

Assuming an initial guess of

[x1x2x3]=[101]

Iteration #1

x1=13(0)+5(1)12=0.50000

x2=28(0.50000)3(1)5=4.9000

x3=763(0.50000)7(4.9000)13=3.0923

The absolute relative approximate error at the end of the first iteration is

|a|1=|0.5000010.50000|×100=100.00%

|a|2=|4.900004.9000|×100=100.00%

|a|3=|3.092313.0923|×100=67.662%

The maximum absolute relative approximate error is 100.00%

Iteration #2

x1=13(4.9000)+5(3.0923)12=0.14679

x2=28(0.14679)3(3.0923)5=3.7153

x3=763(0.14679)7(3.7153)13=3.8118

At the end of second iteration, the absolute relative approximate error is

|a|1=|0.146790.500000.14679|×100=240.61%

|a|2=|3.71534.90003.7153|×100=31.889%

|a|3=|3.81183.09233.8118|×100=18.874%

The maximum absolute relative approximate error is 240.61%. This is greater than the value of 100.00% we obtained in the first iteration. Is the solution diverging? No, as you conduct more iterations, the solution converges as follows.

Iteration a1 |a|1% a2 |a|2% a3 |a|3%
1 0.5 100 4.9 100 3.0923 67.662
2 0.14679 240.61 3.7153 31.889 3.8118 18.874
3 0.74275 80.236 3.1644 17.408 3.9708 4.0064
4 0.94675 21.546 3.0281 4.4996 3.9971 0.65772
5 0.99177 4.5391 3.0034 0.82499 4.0001 0.074383
6 0.99919 0.74307 3.0001 0.10856 4.0001 0.00101

This is close to the exact solution vector of

[x1x2x3]=[134]

Example 3

Given the system of equations

3x1+7x2+13x3=76

x1+5x2+3x3=28

12x1+3x25x3=1

find the solution using the Gauss-Seidel method. Use

[x1x2x3]=[101]

as the initial guess.

Solution1

Rewriting the equations, we get

x1=767x213x33

x2=28x13x35

x3=112x13x25

Assuming an initial guess of

[x1x2x3]=[101]

the next six iterative values are given in the table below.

Iteration a1 |a|1% a2 |a|2% a3 |a|3%
1 21 95.238 0.8 100 50.68 98.027
2 –196.15 110.71 14.421 94.453 –462.30 110.96
3 1995 109.83 –116.02 112.43 4718.1 109.8
4 –20149 109.9 1204.6 109.63 –47636 109.9
5 2.0364 ×105 109.89 –12140 109.92 4.8144 ×105 109.89
6 –2.0579 ×106 109.89 1.2272 ×105 109.89 –4.8653 ×106 109.89

You can see that this solution is not converging and the coefficient matrix is not diagonally dominant. The coefficient matrix

[A]=[37131531235]

is not diagonally dominant as

|a11|=|3|=3|a12|+|a13|=|7|+|13|=20

Hence, the Gauss-Seidel method may or may not converge.

However, it is the same set of equations as the previous example and that converged. The only difference is that we exchanged first and the third equation with each other and that made the coefficient matrix not diagonally dominant.

Therefore, it is possible that a system of equations can be made diagonally dominant if one exchanges the equations with each other. However, it is not possible for all cases. For example, the following set of equations

x1+x2+x3=3

2x1+3x2+4x3=9

x1+7x2+x3=9

cannot be rewritten to make the coefficient matrix diagonally dominant.

Gauss-Seidel Method Quiz

Quiz 1

A square matrix [A]n×n is diagonally dominant if

(A) |aii|nj=1ij|aij|, i=1,2,...,n

(B) |aii|nj=1ij|aij|, i=1,2,...,n and |aii|>nj=1ij|aij|, for any i=1,2,...,n

(C) |aii|nj=1|aij|, i=1,2,...,n and |aii|>nj=1|aij|, for any i=1,2,...,n

(D) |aii|nj=1|aij|, i=1,2,...,n

Quiz 2

Using [x1,x2,x3]=[1,3,5] as the initial guess, the values of [x1,x2,x3] after three iterations in the Gauss-Seidel method for

[12731512711][x1x2x3]=[256]

are

(A) [2.83331.43331.9727]

(B) [1.49590.904640.84914]

(C) [0.906661.01151.0243]

(D) [1.21480.720600.82451]

Quiz 3

To ensure that the following system of equations,

2x1+7x211x3=6x1+2x2+x3=57x1+5x2+2x3=17

converges using the Gauss-Seidel method, one can rewrite the above equations as follows:

(A) [2711121752] [x1x2x3]=[6517]

(B) [7521212711] [x1x2x3]=[1756]

(C) [7521212711] [x1x2x3]=[6517]

(D) The equations cannot be rewritten in a form to ensure convergence.

Quiz 4

For [12731512711] [x1x2x3]=[2272]and using [x1x2x3]=[121] as the initial guess, the values of [x1x2x3] are found at the end of each iteration as

Iteration # x1 x2 x3
1 0.41667 1.1167 0.96818
2 0.93990 1.0184 1.0008
3 0.98908 1.0020 0.99931
4 0.99899 1.0003 1.0000

At what first iteration number would you trust at least 1 significant digit in your solution?

(A) 1

(B) 2

(C) 3

(D) 4

Quiz 5

The algorithm for the Gauss-Seidel method to solve [A][X]=[C] is given as follows when using nmax iterations. The initial value of [X] is stored in [X].

(A) Sub

Seidel(n,a,x,rhs,nmax)

For k=1 To nmax

For i=1 To n

For j=1 To n

If (i<>j) Then

Sum = Sum + a(i,j)x(j)

endif

Next j

x(i)=(rhs(i)Sum)/a(i,i)

Next i

Next j

End Sub

(B) Sub

Seidel(n,a,x,rhs,nmax)

For k=1 To nmax

For i=1 To n

Sum = 0

For j=1 To n

If (i<>j) Then

Sum = Sum + a(i,j)x(j)

endif

Next j

x(i)=(rhs(i)Sum)/a(i,i)

Next i

Next k

End Sub

(C) Sub

Seidel(n,a,x,rhs,nmax)

For k=1To nmax

For i=1To n

Sum = 0

For j=1To n

Sum = Sum + a(i,j)x(j)

Next j

x(i)=(rhs(i)Sum)/a(i,i)

Next i

Next k

End Sub

(D) Sub

Seidel(n,a,x,rhs,nmax)

For k=1To{nmax}$

For i=1 To n

Sum = 0

For j=1 To n

If (i<>j) Then

Sum = Sum + a(i,j)x(j)

endif

Next j

x(i)=(rhs(i)Sum)/a(i,i)

Next i

Next k

End Sub

Quiz 6

Thermistors measure temperature, have a nonlinear output and are valued for a limited range. So when a thermistor is manufactured, the manufacturer supplies a resistance vs. temperature curve. An accurate representation of the curve is generally given by

1T=a0+a1ln(R)+a2{ln(R)}2+a3{ln(R)}3

where T is temperature in Kelvin, R is resistance in ohms, and a0,a1,a2,a3 are constants of the calibration curve. Given the following for a thermistor

R T
ohm C

1101.0

911.3

636.0

451.1

25.113

30.131

40.120

50.128

the value of temperature in C for a measured resistance of 900 ohms most nearly is

(A) 30.002

(B) 30.473

(C) 31.272

(D) 31.445

Gauss-Seidel Method Exercise

Exercise 1

In a system of equation [A][X]=[C], if [A] is diagonally dominant, then GaussSeidal-Seidel method

  1. always converges
  2. may or may not converge
  3. always diverges
Answer

A

Exercise 2

In a system of equations [A][X]=[C], if [A] is not diagonally dominant, then Gauss-Seidel method

  1. Always converges
  2. May or may not converge
  3. Always diverges.
Answer

B

Exercise 3

In a system of equations [A][X]=[C], if [A] is not diagonally dominant, the system of equations can always be rewritten to make it diagonally dominant.

  1. True
  2. False
Answer

B

Exercise 4

Solve the following system of equations using Gauss-Seidel method

12x1+7x2+3x3=2x1+5x2+x3=52x1+7x211x3=6

Conduct 3 iterations, calculate the maximum absolute relative approximate error at the end of each iteration and choose [x1x2x3]=[135] as your initial guess.

Answer

[x1x2x3]=[0.906661.01151.0243] [|a|1|a|2|a|3]=[65.001%10.564%17.099%] [|a|1|a|2|a|3]=[65.001%10.564%17.099%]

Exercise 5

Solve the following system of equations using Gauss-Seidel method

12x1+7x2+3x3=2
x1+5x2+x3=5
2x1+7x211x3=6
Conduct 3 iterations, calculate the maximum absolute relative approximate error at the end of each iteration, and choose [x1x2x3]=[135] as your initial guess.

Answer

[x1x2x3]=[0.906661.01151.0243]

Exercise 6

Solve the following system of equations using Gauss-Seidel Method
x1+5x2+x3=5
12x1+7x2+3x3=2
2x1+7x211x3=6
Conduct 3 iterations, calculate the maximum absolute relative approximate error at the end of each iteration, and choose [x1x2x3]=[135] as your initial guess.

Answer

[x1x2x3]=[1163.71947.61027.2]

[|a|1|a|2|a|3]=[89.156%89.139%89.183%]


This page titled 8: Gauss-Seidel Method is shared under a CC BY-NC-SA 4.0 license and was authored, remixed, and/or curated by Autar Kaw via source content that was edited to the style and standards of the LibreTexts platform.

Support Center

How can we help?