Suvarna Garge (Editor)

Gauss–Seidel method

Updated on
Edit
Like
Comment
Share on FacebookTweet on TwitterShare on LinkedInShare on Reddit

In numerical linear algebra, the Gauss–Seidel method, also known as the Liebmann method or the method of successive displacement, is an iterative method used to solve a linear system of equations. It is named after the German mathematicians Carl Friedrich Gauss and Philipp Ludwig von Seidel, and is similar to the Jacobi method. Though it can be applied to any matrix with non-zero elements on the diagonals, convergence is only guaranteed if the matrix is either diagonally dominant, or symmetric and positive definite. It was only mentioned in a private letter from Gauss to his student Gerling in 1823. A publication was not delivered before 1874 by Seidel.

Contents

Description

The Gauss–Seidel method is an iterative technique for solving a square system of n linear equations with unknown x:

A x = b .

It is defined by the iteration

L x ( k + 1 ) = b U x ( k ) ,

where x ( k ) is the kth approximation or iteration of x , x ( k + 1 ) is the next or k + 1 iteration of x , and the matrix A is decomposed into a lower triangular component L , and a strictly upper triangular component U: A = L + U .

In more detail, write out A, x and b in their components:

A = [ a 11 a 12 a 1 n a 21 a 22 a 2 n a n 1 a n 2 a n n ] , x = [ x 1 x 2 x n ] , b = [ b 1 b 2 b n ] .

Then the decomposition of A into its lower triangular component and its strictly upper triangular component is given by:

A = L + U where L = [ a 11 0 0 a 21 a 22 0 a n 1 a n 2 a n n ] , U = [ 0 a 12 a 1 n 0 0 a 2 n 0 0 0 ] .

The system of linear equations may be rewritten as:

L x = b U x

The Gauss–Seidel method now solves the left hand side of this expression for x, using previous value for x on the right hand side. Analytically, this may be written as:

x ( k + 1 ) = L 1 ( b U x ( k ) ) .

However, by taking advantage of the triangular form of L , the elements of x(k+1) can be computed sequentially using forward substitution:

x i ( k + 1 ) = 1 a i i ( b i j = 1 i 1 a i j x j ( k + 1 ) j = i + 1 n a i j x j ( k ) ) , i = 1 , 2 , , n .

The procedure is generally continued until the changes made by an iteration are below some tolerance, such as a sufficiently small residual.

Discussion

The element-wise formula for the Gauss–Seidel method is extremely similar to that of the Jacobi method.

The computation of xi(k+1) uses only the elements of x(k+1) that have already been computed, and only the elements of x(k) that have not yet to be advanced to iteration k+1. This means that, unlike the Jacobi method, only one storage vector is required as elements can be overwritten as they are computed, which can be advantageous for very large problems.

However, unlike the Jacobi method, the computations for each element cannot be done in parallel. Furthermore, the values at each iteration are dependent on the order of the original equations.

Gauss-Seidel is the same as SOR (successive over-relaxation) with ω = 1 .

Convergence

The convergence properties of the Gauss–Seidel method are dependent on the matrix A. Namely, the procedure is known to converge if either:

  • A is symmetric positive-definite, or
  • A is strictly or irreducibly diagonally dominant.
  • The Gauss–Seidel method sometimes converges even if these conditions are not satisfied.

    Algorithm

    Since elements can be overwritten as they are computed in this algorithm, only one storage vector is needed, and vector indexing is omitted. The algorithm goes as follows:

    Inputs: A, b Output: ϕ Choose an initial guess ϕ to the solution repeat until convergence for i from 1 until n do σ 0 for j from 1 until n do if ji then σ σ + a i j ϕ j end if end (j-loop) ϕ i 1 a i i ( b i σ ) end (i-loop) check if convergence is reached end (repeat)

    An example for the matrix version

    A linear system shown as A x = b is given by:

    A = [ 16 3 7 11 ] and b = [ 11 13 ] .

    We want to use the equation

    x ( k + 1 ) = L 1 ( b U x ( k ) )

    in the form

    x ( k + 1 ) = T x ( k ) + C

    where:

    T = L 1 U and C = L 1 b .

    We must decompose A into the sum of a lower triangular component L and a strict upper triangular component U :

    L = [ 16 0 7 11 ] and U = [ 0 3 0 0 ] .

    The inverse of L is:

    L 1 = [ 16 0 7 11 ] 1 = [ 0.0625 0.0000 0.0398 0.0909 ] .

    Now we can find:

    T = [ 0.0625 0.0000 0.0398 0.0909 ] × [ 0 3 0 0 ] = [ 0.000 0.1875 0.000 0.1193 ] , C = [ 0.0625 0.0000 0.0398 0.0909 ] × [ 11 13 ] = [ 0.6875 0.7443 ] .

    Now we have T and C and we can use them to obtain the vectors x iteratively.

    First of all, we have to choose x ( 0 ) : we can only guess. The better the guess, the quicker the algorithm will perform.

    We suppose:

    x ( 0 ) = [ 1.0 1.0 ] .

    We can then calculate:

    x ( 1 ) = [ 0.000 0.1875 0.000 0.1193 ] × [ 1.0 1.0 ] + [ 0.6875 0.7443 ] = [ 0.5000 0.8636 ] . x ( 2 ) = [ 0.000 0.1875 0.000 0.1193 ] × [ 0.5000 0.8636 ] + [ 0.6875 0.7443 ] = [ 0.8494 0.6413 ] . x ( 3 ) = [ 0.000 0.1875 0.000 0.1193 ] × [ 0.8494 0.6413 ] + [ 0.6875 0.7443 ] = [ 0.8077 0.6678 ] . x ( 4 ) = [ 0.000 0.1875 0.000 0.1193 ] × [ 0.8077 0.6678 ] + [ 0.6875 0.7443 ] = [ 0.8127 0.6646 ] . x ( 5 ) = [ 0.000 0.1875 0.000 0.1193 ] × [ 0.8127 0.6646 ] + [ 0.6875 0.7443 ] = [ 0.8121 0.6650 ] . x ( 6 ) = [ 0.000 0.1875 0.000 0.1193 ] × [ 0.8121 0.6650 ] + [ 0.6875 0.7443 ] = [ 0.8122 0.6650 ] . x ( 7 ) = [ 0.000 0.1875 0.000 0.1193 ] × [ 0.8122 0.6650 ] + [ 0.6875 0.7443 ] = [ 0.8122 0.6650 ] .

    As expected, the algorithm converges to the exact solution:

    x = A 1 b = [ 0.8122 0.6650 ] .

    In fact, the matrix A is strictly diagonally dominant (but not positive definite).

    Another example for the matrix version

    Another linear system shown as A x = b is given by:

    A = [ 2 3 5 7 ] and b = [ 11 13 ] .

    We want to use the equation

    x ( k + 1 ) = L 1 ( b U x ( k ) )

    in the form

    x ( k + 1 ) = T x ( k ) + C

    where:

    T = L 1 U and C = L 1 b .

    We must decompose A into the sum of a lower triangular component L and a strict upper triangular component U :

    L = [ 2 0 5 7 ] and U = [ 0 3 0 0 ] .

    The inverse of L is:

    L 1 = [ 2 0 5 7 ] 1 = [ 0.500 0.000 0.357 0.143 ] .

    Now we can find:

    T = [ 0.500 0.000 0.357 0.143 ] × [ 0 3 0 0 ] = [ 0.000 1.500 0.000 1.071 ] , C = [ 0.500 0.000 0.357 0.143 ] × [ 11 13 ] = [ 5.500 2.071 ] .

    Now we have T and C and we can use them to obtain the vectors x iteratively.

    First of all, we have to choose x ( 0 ) : we can only guess. The better the guess, the quicker will perform the algorithm.

    We suppose:

    x ( 0 ) = [ 1.1 2.3 ] .

    We can then calculate:

    x ( 1 ) = [ 0 1.500 0 1.071 ] × [ 1.1 2.3 ] + [ 5.500 2.071 ] = [ 2.050 0.393 ] . x ( 2 ) = [ 0 1.500 0 1.071 ] × [ 2.050 0.393 ] + [ 5.500 2.071 ] = [ 4.911 1.651 ] . x ( 3 ) = .

    If we test for convergence we'll find that the algorithm diverges. In fact, the matrix A is neither diagonally dominant nor positive definite. Then, convergence to the exact solution

    x = A 1 b = [ 38 29 ]

    is not guaranteed and, in this case, will not occur.

    An example for the equation version

    Suppose given k equations where xn are vectors of these equations and starting point x0. From the first equation solve for x1 in terms of x n + 1 , x n + 2 , , x n . For the next equations substitute the previous values of xs.

    To make it clear let's consider an example.

    10 x 1 x 2 + 2 x 3 = 6 , x 1 + 11 x 2 x 3 + 3 x 4 = 25 , 2 x 1 x 2 + 10 x 3 x 4 = 11 , 3 x 2 x 3 + 8 x 4 = 15.

    Solving for x 1 , x 2 , x 3 and x 4 gives:

    x 1 = x 2 / 10 x 3 / 5 + 3 / 5 , x 2 = x 1 / 11 + x 3 / 11 3 x 4 / 11 + 25 / 11 , x 3 = x 1 / 5 + x 2 / 10 + x 4 / 10 11 / 10 , x 4 = 3 x 2 / 8 + x 3 / 8 + 15 / 8.

    Suppose we choose (0, 0, 0, 0) as the initial approximation, then the first approximate solution is given by

    x 1 = 3 / 5 = 0.6 , x 2 = ( 3 / 5 ) / 11 + 25 / 11 = 3 / 55 + 25 / 11 = 2.3272 , x 3 = ( 3 / 5 ) / 5 + ( 2.3272 ) / 10 11 / 10 = 3 / 25 + 0.23272 1.1 = 0.9873 , x 4 = 3 ( 2.3272 ) / 8 + ( 0.9873 ) / 8 + 15 / 8 = 0.8789.

    Using the approximations obtained, the iterative procedure is repeated until the desired accuracy has been reached. The following are the approximated solutions after four iterations.

    x 1 x 2 x 3 x 4 0.6 2.32727 0.987273 0.878864 1.03018 2.03694 1.01446 0.984341 1.00659 2.00356 1.00253 0.998351 1.00086 2.0003 1.00031 0.99985

    The exact solution of the system is (1, 2, −1, 1).

    An example using Python 3 and NumPy

    The following numerical procedure simply iterates to produce the solution vector.

    Produces the output:

    Program to solve arbitrary no. of equations using Matlab

    The following code uses the formula x i ( k + 1 ) = 1 a i i ( b i j < i a i j x j ( k + 1 ) j > i a i j x j ( k ) ) , i , j = 1 , 2 , , n

    References

    Gauss–Seidel method Wikipedia