How Efficient Is Jacobi Iteration in Solving Linear Systems
How Efficient Is Jacobi Iteration in Solving Linear Systems
How Efficient Is Jacobi Iteration in Solving Linear Systems
PROJECT1
Abstract
The Jacobi Iteration method is a widely used iterative method for solving linear systems of equations.
However, it is not always clear how efficient it is in solving these systems, especially for larger systems or
real-time applications. In this article, N is the number of points used to discretize the solution of the linear
system. The article aims to evaluate the efficiency of Jacobi Iteration in solving linear systems by analyzing
the running time and space complexity of the method. Additionally, the article examines the accuracy of
the method for different values of N. The results of this study will provide insight into the suitability of
Jacobi Iteration for solving different types of linear systems and help guide the choice of algorithm for
solving linear systems in different contexts.
1. Introduction to the Jacobi Iteration Method for Solving Systems of Linear Equations
Jacobi iteration is an iterative method for solving systems of linear equations of the form Ax = b,
where A is a square matrix, x and b are column vectors. The method is named after Carl Jacobi, a
German mathematician who first introduced the method in 1845 Jacobi 1845. The method is also
known as the Jacobi method or the method of cyclic reduction.
The Jacobi iteration method starts with an initial guess for the solution vector x, and in each
iteration, the method updates the solution vector by taking the weighted average of the previous
solution vector and the vector b, with weights determined by the inverse of the diagonal elements of
A. The method continues iterating until the solution vector converges to a certain desired accuracy
or until a certain maximum number of iterations is reached.
Jacobi iteration is relatively simple to implement and is useful for solving diagonally dominant
systems of equations, which are systems of equations where the absolute value of the diagonal element
of a matrix is greater than the sum of the absolute values of the other elements in the same row.
The Jacobi method is considered as an outdated method to solve linear systems because it is
relatively slow, it requires more iterations than other methods such as Gaussian elimination or LU
decomposition to achieve the same accuracy, and it is not parallelizable. However, it has been used
in many fields such as physics, engineering, and numerical analysis Trefethen and Bau 1997.
where all diagonal elements are equal to –2N 2 , and this structure can cause numerical instability
when using certain methods to solve the system, such as Gaussian elimination. Additionally, the
formula for the elements of vector b may also introduce additional computational challenges.
not always the best choice, depending on the size of the system and the desired level of accuracy. It is
important to consider the specific characteristics of the problem at hand and the trade-offs between
different methods before choosing an algorithm for solving a linear system.
Acknowledgement
This article is the first assignment project for the course Technical writing taught by Jabrul Alam at
the Memorial University of Newfoundland.
References
Jacobi, Carl Gustav Jacob. 1845. De resolutione aequationum differentialium per seriem infinitam. Crelle’s Journal 30 (1):
213–279.
Trefethen, Lloyd N, and David Bau. 1997. Numerical linear algebra. SIAM.
6 Disant Upadhyay et al.
i m p o r t numpy a s np
import m a t p l o t l i b . pyplot a s p l t
class JacobiIteration :
d e f _ _ i n i t _ _ ( s e l f , n _ i t e r , N, sigma ) :
s e l f . n_iter = n_iter
s e l f .N = N
s e l f . sigma = sigma
s e l f . A = np . z e r o s (N)
s e l f . b = np . z e r o s (N)
s e l f . x = None
def __initialize_A_and_b ( s e l f ) :
f o r i i n range ( s e l f .N) :
x i = ( i + 1 ) / ( s e l f .N+ 1 ) − 0 . 5
s e l f . A[ i ] = −2∗ s e l f .N∗ s e l f .N
s e l f . b [ i ] = 2 ∗ s e l f . sigma ∗ ( 2 ∗ s e l f . sigma ∗ x i ∗ x i − 1 ) ∗ np . exp (
− s e l f . sigma ∗ x i ∗ x i )
def solve ( s e l f ) :
s e l f . __initialize_A_and_b ()
n = s e l f .A. shape [0]
M = np . d i a g ( s e l f . A ) ∗ np . eye ( n , n )
s e l f . x = np . z e r o s _ l i k e ( s e l f . b )
f o r k i n range ( s e l f . n _ i t e r ) :
s e l f . x = s e l f . x + np . l i n a l g . i n v (M)@( s e l f . b− s e l f . A@self . x )
def plot ( s e l f ) :
p l t . p l o t ( s e l f . x , l a b e l =" x " )
p l t . ylabel ( ’ x values ’ )
plt . xlabel ( ’ indices ’ )
p l t . legend ( )
p l t . show ( )
p l t . p l o t ( s e l f . b , l a b e l =" b " , c o l o r = ’ red ’ )
p l t . ylabel ( ’ b values ’ )
plt . xlabel ( ’ indices ’ )
p l t . legend ( )
p l t . show ( )
def plotx ( s e l f ) :
p l t . p l o t ( s e l f . x , l a b e l =" x " )
p l t . ylabel ( ’ x values ’ )
plt . xlabel ( ’ indices ’ )
p l t . legend ( )
# C r e a t e an i n s t a n c e o f t h e c l a s s
Disant Upadhyay 7
j a c o b i = J a c o b i I t e r a t i o n ( n _ i t e r = 5 , N= 51 2 , sigma = 5 0 0 )
# S o l v e t h e l i n e a r s y s t e m and p l o t t h e s o l u t i o n
jacobi . solve ()
jacobi . plot ()
# S o l v e t h e l i n e a r s y s t e m and p l o t t h e s o l u t i o n f o r t h e f o l l o w i n g N v a l u e s .
N _ v a l u e s = [ 3 2 , 6 4 , 1 2 8 , 2 5 6 , 5 12 ]
f o r N in N_values :
j a c o b i = J a c o b i I t e r a t i o n ( n _ i t e r = 1 0 , N=N, sigma = 5 0 0 )
jacobi . solve ()
jacobi . plotx ()
p l t . t i t l e ( f " S o l u t i o n f o r N = {N} " )
p l t . show ( )