0% found this document useful (0 votes)
558 views

Gauss-Seidel Iteration Method

The Gauss-Seidel iteration method is an iterative technique for solving systems of linear equations. It is similar to the Jacobi method but uses the most recent updated value of the other variables in each step. The matrix is decomposed into lower and strictly upper triangular components. The solution is obtained iteratively by sequentially computing each element using the forward substitution formula. The method converges if the matrix is diagonally dominant or symmetric and positive definite. A Python script is provided to demonstrate solving systems of equations using Gauss-Seidel iteration.

Uploaded by

Lawson Sango
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
558 views

Gauss-Seidel Iteration Method

The Gauss-Seidel iteration method is an iterative technique for solving systems of linear equations. It is similar to the Jacobi method but uses the most recent updated value of the other variables in each step. The matrix is decomposed into lower and strictly upper triangular components. The solution is obtained iteratively by sequentially computing each element using the forward substitution formula. The method converges if the matrix is diagonally dominant or symmetric and positive definite. A Python script is provided to demonstrate solving systems of equations using Gauss-Seidel iteration.

Uploaded by

Lawson Sango
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Gauss-Seidel Iteration Method

MPHYCC-05 unit IV (Sem.-II)

Gauss-Seidel Iteration Method


Gauss–Seidel method is an iterative method to solve a set of linear equations and very
much similar to Jacobi’s method. This method is also known as Liebmann method or
the method of successive displacement. The name successive displacement is because
the second unknown is determined from the first unknown in the current iteration,
the third unknown is determined from the first and second unknowns. This method
was developed by German mathematicians Carl Friedrich Gauss and Philipp Ludwig
von Seidel. The method can be applied to any matrix with non-zero diagonal
elements. However, the convergence is only possible if the matrix is either diagonally
dominant, or symmetric & positive definite. The process adopted by this method for
solving a set of linear equations is as follows.

Let us assume a set of linear equations in the matrix form is as follows:

AX = B

Where

Further, the matrix A can be decomposed into a lower triangular part (L*) and an
strict upper triangular component (U) as:

A= L* + U

Where

1
Ref: developed with the help of online study material for Methods of Matrix Inversion
And equation AX=B can be written as

( )

Therefore, the solution can be obtained iteratively via using the following relation:

( ) ( )
( )

( ) ( )
Where and are the kth and (k+1)th iteration of X.

( )
The elements of can be computed sequentially using the element-based
forward substitution formula:

( ) ( ) ( )
( ∑ ∑ )

( ) ( )
Thus the calculation of is using the value of that have already
( )
computed and only those value of that have not been calculated in the (k+1)
iteration. Hence, only one storage vector is required because the elements can be
overwritten as they computed which is opposite to Jacobi method. We know that in
Jacobi method the computations for each element can be done in parallel but the
parallel computation is not possible in the Gauss-Seidel method.

The process adopted by this method can be understood completely by starting with
the following motivational example.

2
Ref: developed with the help of online study material for Methods of Matrix Inversion
3
Ref: developed with the help of online study material for Methods of Matrix Inversion
Python script is given below to solve the set of linear equations using Gauss Seidel
iteration method.

…………………………………………………………………….................................
import numpy as np
from scipy.linalg import solve
def GaussSeidel(A, B, x, n):
L=np.tril(A)
U=A-L
4
Ref: developed with the help of online study material for Methods of Matrix Inversion
for i in range(n):
x = np.dot(np.linalg.inv(L), B - np.dot(U, x))
print(x)
return x

'''___Main___'''

A = eval(input('Enter the matrix A:'))


# as np.array([[a11,a12],[a21,a22]])
B = eval(input('Enter the matrix B:'))# as [b1,b2]
x = eval(input('Enter guess of x:')) # as [x1,x2]
n = eval(input('Enter the number of Iterations:'))
x = GaussSeidel(A, B, x, n)
print ('Solution using the solve syntax:\n', solve(A, B))
…………………………………………………………………….................................

After compiling the above python script and for the different matrices we have the
following out puts:

……………………………………………………………………………………..
Enter the matrix A:np.array([[2,1],[3,7]])
Enter the matrix B:[4,3]
Enter guess of x:[0,0]
Enter the number of Iterations:25
[ 2. -0.42857143]
[ 2.21428571 -0.52040816]
[ 2.26020408 -0.54008746]
[ 2.27004373 -0.54430446]
[ 2.27215223 -0.5452081 ]
[ 2.27260405 -0.54540174]
[ 2.27270087 -0.54544323]
[ 2.27272161 -0.54545212]
[ 2.27272606 -0.54545403]
[ 2.27272701 -0.54545443]
[ 2.27272722 -0.54545452]
[ 2.27272726 -0.54545454]
[ 2.27272727 -0.54545454]
[ 2.27272727 -0.54545455]

5
Ref: developed with the help of online study material for Methods of Matrix Inversion
[ 2.27272727 -0.54545455]
[ 2.27272727 -0.54545455]
[ 2.27272727 -0.54545455]
[ 2.27272727 -0.54545455]
[ 2.27272727 -0.54545455]
[ 2.27272727 -0.54545455]
[ 2.27272727 -0.54545455]
[ 2.27272727 -0.54545455]
[ 2.27272727 -0.54545455]
[ 2.27272727 -0.54545455]
[ 2.27272727 -0.54545455]
Solution using the solve syntax:
[ 2.27272727 -0.54545455]
Hence solution is [ 2.27272727 -0.54545455]
…………………………………………………………………….................................

Enter the matrix A:np.array([[2,1],[5,7]])


Enter the matrix B:[11,15]
Enter guess of x:[0,0]
Enter the number of Iterations:25
[ 5.5 -1.78571429]
[ 6.39285714 -2.42346939]
[ 6.71173469 -2.65123907]
[ 6.82561953 -2.73258538]
[ 6.86629269 -2.76163764]
[ 6.88081882 -2.77201344]
[ 6.88600672 -2.77571909]
[ 6.88785954 -2.77704253]
[ 6.88852127 -2.77751519]
[ 6.88875759 -2.777684 ]
[ 6.888842 -2.77774428]
[ 6.88887214 -2.77776582]
[ 6.88888291 -2.77777351]
[ 6.88888675 -2.77777625]
[ 6.88888813 -2.77777723]
[ 6.88888862 -2.77777758]
[ 6.88888879 -2.77777771]
[ 6.88888885 -2.77777775]
[ 6.88888888 -2.77777777]
[ 6.88888888 -2.77777777]
[ 6.88888889 -2.77777778]
[ 6.88888889 -2.77777778]
6
Ref: developed with the help of online study material for Methods of Matrix Inversion
[ 6.88888889 -2.77777778]
[ 6.88888889 -2.77777778]
[ 6.88888889 -2.77777778]
Solution using the solve syntax:
[ 6.88888889 -2.77777778]
Hence solution is [ 6.88888889 -2.77777778]
……………………………………………………………………………………….

Enter the matrix A:np.array([[5,-1,3],[-3,9,1],[2,-1,-7]])


Enter the matrix B:[-3,5,7]
Enter guess of x:[1,1,1]
Enter the number of Iterations:25
[-1. 0.11111111 -1.3015873 ]
[ 0.2031746 0.76790123 -1.05165029]
[ 0.18457042 0.73392906 -1.0521126 ]
[ 0.17805337 0.73180808 -1.05367162]
[ 0.17856459 0.73215171 -1.05357465]
[ 0.17857513 0.73214445 -1.0535706 ]
[ 0.17857125 0.7321427 -1.05357146]
[ 0.17857142 0.73214286 -1.05357143]
[ 0.17857143 0.73214286 -1.05357143]
[ 0.17857143 0.73214286 -1.05357143]
[ 0.17857143 0.73214286 -1.05357143]
[ 0.17857143 0.73214286 -1.05357143]
[ 0.17857143 0.73214286 -1.05357143]
[ 0.17857143 0.73214286 -1.05357143]
[ 0.17857143 0.73214286 -1.05357143]
[ 0.17857143 0.73214286 -1.05357143]
[ 0.17857143 0.73214286 -1.05357143]
[ 0.17857143 0.73214286 -1.05357143]
[ 0.17857143 0.73214286 -1.05357143]
[ 0.17857143 0.73214286 -1.05357143]
[ 0.17857143 0.73214286 -1.05357143]
[ 0.17857143 0.73214286 -1.05357143]
[ 0.17857143 0.73214286 -1.05357143]
[ 0.17857143 0.73214286 -1.05357143]
[ 0.17857143 0.73214286 -1.05357143]
Solution using the solve syntax:
[ 0.17857143 0.73214286 -1.05357143]
Hence solution is [ 0.17857143 0.73214286 -1.05357143]
……………………………………………………………………
7
Ref: developed with the help of online study material for Methods of Matrix Inversion

You might also like