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

Jacobi's Iteration Method

Jacobi's Iteration Method is an iterative approach used to solve strictly diagonally dominant systems of linear equations, named after Carl Gustav Jacob Jacobi. The method involves decomposing a matrix into its diagonal, lower triangular, and upper triangular components, and iteratively updating the solution until a desired accuracy is achieved. The document also includes a Python script that demonstrates the implementation of this method for solving linear equations.

Uploaded by

itzninja34
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)
15 views

Jacobi's Iteration Method

Jacobi's Iteration Method is an iterative approach used to solve strictly diagonally dominant systems of linear equations, named after Carl Gustav Jacob Jacobi. The method involves decomposing a matrix into its diagonal, lower triangular, and upper triangular components, and iteratively updating the solution until a desired accuracy is achieved. The document also includes a Python script that demonstrates the implementation of this method for solving linear equations.

Uploaded by

itzninja34
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/ 8

Jacobi’s Iteration Method

MPHYCC-05 unit IV (Sem.-II)

Jacobi’s Iteration method


Jacobi’s method in numerical linear algebra is an iterative method to compute the
solution of a strictly diagonally dominant system of linear equations. The method
is named after Carl Gustav Jacob Jacobi. The method is a shorter version of
the Jacobi transformation method of matrix diagonalization. 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 diagonal component (D), a strictly
lower triangular part (L) and a strictly upper triangular component (U) as:

A=D + L + U

Where

1
Ref: developed with the help of online study material for Methods of Matrix Inversion
Moreover, 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 using the element-based formula:

( ∑ )

Thus new value of X is calculated after putting the previous iterative value of X in
the above equation till the required accuracy is achieved. However, we overwrite,
with . The important thing is that the method should be converging for
having a solution. And the sufficient but not necessary condition for the method to
converge is that the matrix is strictly diagonally dominant. That means for each
row the absolute value of diagonal term is greater than the sum of the absolute
values of the other terms:

| | ∑| |

However, the method sometimes converges even if these conditions are not
satisfied. Moreover, the standard convergence condition for any iterative method is
defined in terms of the spectral radius, ρ() of the iteration matrix. And the spectral
radius of the matrix is equal to the largest absolute value of its eigenvalues. The
convergence condition for the method is when the spectral radius, ρ() of the
iteration matrix is less than 1; thus
2
Ref: developed with the help of online study material for Methods of Matrix Inversion
( )

The method is simple and numerically robust and each iterations quite fast.
However, the method is computing the independent variables of the linear
equations in parallel and independent way. Therefore the method might require
much iteration as well as good memory power of computational system. In-order to
understand the process completely, we start with a motivational example as given
below.

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 Jacobi’s
iteration method.

……………………………………………………………………………….
import numpy as np
from scipy.linalg import solve

def Jacobi(A, B, x, n):


# computing the diagonal matrix
D = np.diag(A)
4
Ref: developed with the help of online study material for Methods of Matrix Inversion
# computing the sum of upper and
#lower triangular matrix (R=U+L=A-D)
R = A - np.diagflat(D)
# computing new solution from old solution
for i in range(n):
x = (B - np.dot(R,x))/ D
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 = Jacobi(A, B, x, n)
# Direct command that is solve to find the solution of a set of linear equations
print ('Solution using the solve command:', 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:[3,5]
Enter guess of x:[0,0]
Enter the number of Iterations:25
[1.5 0.71428571]
[1.14285714 0.07142857]
[1.46428571 0.2244898 ]
[1.3877551 0.08673469]
[1.45663265 0.11953353]
[1.44023324 0.09001458]
[1.45499271 0.0970429 ]
[1.45147855 0.09071741]
[1.4546413 0.09222348]
[1.45388826 0.09086802]

5
Ref: developed with the help of online study material for Methods of Matrix Inversion
[1.45456599 0.09119075]
[1.45440463 0.09090029]
[1.45454986 0.09096945]
[1.45451528 0.0909072 ]
[1.4545464 0.09092202]
[1.45453899 0.09090869]
[1.45454566 0.09091186]
[1.45454407 0.090909 ]
[1.4545455 0.09090968]
[1.45454516 0.09090907]
[1.45454546 0.09090922]
[1.45454539 0.09090909]
[1.45454546 0.09090912]
[1.45454544 0.09090909]
[1.45454545 0.0909091 ]
Solution using the solve command: [1.45454545 0.09090909]

Hence the solution is (1.4545, 0.0909)

…………………………………………………………

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


Enter the matrix B:[-1,2,3]
Enter guess of x:[1,1,1]
Enter the number of Iterations:25
[-0.4 0.44444444 -0.28571429]
[ 0.14920635 0.12063492 -0.60634921]
[ 0.21206349 0.33932981 -0.4031746 ]
[ 0.17763668 0.33770723 -0.41645755]
[ 0.18495742 0.32770751 -0.42606198]
[ 0.18672019 0.33121492 -0.42254181]
[ 0.18601105 0.33141138 -0.42253922]
[ 0.18608808 0.33117471 -0.4227699 ]
[ 0.18613182 0.33122602 -0.42271408]
[ 0.18611885 0.33123439 -0.42270891]
[ 0.1861191 0.3312295 -0.42271381]
[ 0.18612009 0.33123012 -0.42271304]
[ 0.18611987 0.33123037 -0.42271285]
[ 0.18611986 0.33123027 -0.42271295]
[ 0.18611988 0.33123028 -0.42271294]
[ 0.18611987 0.33123029 -0.42271293]
[ 0.18611987 0.33123028 -0.42271293]
6
Ref: developed with the help of online study material for Methods of Matrix Inversion
[ 0.18611987 0.33123028 -0.42271293]
[ 0.18611987 0.33123028 -0.42271293]
[ 0.18611987 0.33123028 -0.42271293]
[ 0.18611987 0.33123028 -0.42271293]
[ 0.18611987 0.33123028 -0.42271293]
[ 0.18611987 0.33123028 -0.42271293]
[ 0.18611987 0.33123028 -0.42271293]
[ 0.18611987 0.33123028 -0.42271293]
Solution using the solve command: [ 0.18611987 0.33123028 -0.42271293]

Hence the solution is (0.186, 0.331, -0.423)


……………………………………………………………….

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


Enter the matrix B:[17,-18,25]
Enter guess of x:[0,0,0]
Enter the number of Iterations:25
[ 0.85 -0.9 1.25]
[ 1.02 -0.965 1.03 ]
[ 1.00125 -1.0015 1.00325]
[ 1.0004 -1.000025 0.99965 ]
[ 0.99996625 -1.0000775 0.99995625]
[ 0.9999995 -0.99999712 0.99999175]
[ 0.99999903 -1.00000034 1.00000048]
[ 1.00000007 -0.99999983 1.00000005]
[ 1. -1.00000001 1.00000002]
[ 1. -1. 1.]
[ 1. -1. 1.]
[ 1. -1. 1.]
[ 1. -1. 1.]
[ 1. -1. 1.]
[ 1. -1. 1.]
[ 1. -1. 1.]
[ 1. -1. 1.]
[ 1. -1. 1.]
[ 1. -1. 1.]
[ 1. -1. 1.]
[ 1. -1. 1.]
[ 1. -1. 1.]
[ 1. -1. 1.]
[ 1. -1. 1.]
[ 1. -1. 1.]
7
Ref: developed with the help of online study material for Methods of Matrix Inversion
Solution using the solve command: [ 1. -1. 1.]

Hence the solution is (1, -1, 1)


...............................................................................................................................................

Enter the matrix A:np.array([[10,2,-1],[1,8,3],[-2,-1,10]])


Enter the matrix B:[7,-4,9]
Enter guess of x:[0,0,0]
Enter the number of Iterations:25
[ 0.7 -0.5 0.9]
[ 0.89 -0.925 0.99 ]
[ 0.984 -0.9825 0.9855]
[ 0.99505 -0.9925625 0.99855 ]
[ 0.9983675 -0.9988375 0.99975375]
[ 0.99974288 -0.99970359 0.99978975]
[ 0.99991969 -0.99988902 0.99997822]
[ 0.99997562 -0.99998179 0.99999504]
[ 0.99999586 -0.99999509 0.99999695]
[ 0.99999871 -0.99999834 0.99999966]
[ 0.99999963 -0.99999971 0.99999991]
[ 0.99999993 -0.99999992 0.99999996]
[ 0.99999998 -0.99999997 0.99999999]
[ 0.99999999 -1. 1. ]
[ 1. -1. 1.]
[ 1. -1. 1.]
[ 1. -1. 1.]
[ 1. -1. 1.]
[ 1. -1. 1.]
[ 1. -1. 1.]
[ 1. -1. 1.]
[ 1. -1. 1.]
[ 1. -1. 1.]
[ 1. -1. 1.]
[ 1. -1. 1.]
Solution using the solve command: [ 1. -1. 1.]

Hence the solution is (1, -1, 1)


……………………………………………………………………….

8
Ref: developed with the help of online study material for Methods of Matrix Inversion

You might also like