How Efficient Is Jacobi Iteration in Solving Linear Systems

Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

Disant Upadhyay (2022), 1, 1–7

PROJECT1

How Efficient is Jacobi Iteration in Solving Linear


Systems?
Disant Upadhyay*
Memorial University of Newfoundland
*Corresponding author. Email: [email protected]

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.

2. Efficiency of Jacobi Iteration in Solving the Linear System Ax = b


2.1 The problem statement as an overview
The problem of solving a system of linear equations can be computationally expensive and time-
consuming, especially for large values of N. In this specific case, the matrix A has a specific structure,
2 Disant Upadhyay et al.

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.

2.2 What do we expect the final result to be?


The Jacobi iteration method is a common iterative method for solving systems of linear equations,
but its efficiency depends on the specific characteristics of the matrix and vector involved.
In the case of the matrix A and vector b described in the problem statement, the matrix A has a
specific structure, where all diagonal elements are equal to –2N 2 , and all off-diagonal elements are
zero. This structure of the matrix can cause the Jacobi iteration to converge slowly, as the method
relies on the diagonal elements of the matrix to be dominant.
Also, the formula for the elements of vector b may also introduce additional computational
challenges.
Therefore, it is unlikely that the Jacobi iteration method would be highly efficient in solving the
linear system Ax = b described in the problem statement.
Other iterative methods such as Gauss-Seidel or Conjugate Gradient could be more efficient or
direct methods such as LU decomposition or Cholesky decomposition could be better alternatives
for solving this system.
Below we will see the variations in solutions to a Matrix A with a unique property.

3. The unique property


The unique matrix we consider is defined as follows: for a given positive integer N, let A be an
N × N matrix such that all elements on the main diagonal are equal to –2N 2 . Specifically, for
i = 0, 1, ..., N – 1, the i-th diagonal element of A is equal to –2N 2 .
In addition, let b be an N-dimensional column vector, where the i-th element is defined by
2
bi = 2σ(2σxi2 – 1)e–σxi
i+1
, where xi = N+1 – 1 and σ is a positive scalar.
This matrix and vector are used to solve a system of linear equations Ax = b.
Below is an example of the sample matrix.

Figure 1. Example matrix.


Disant Upadhyay 3

4. Observations of the Solution Vector for Various Values of N

Figure 2. The solution x plotted

Figure 3. The vector b plotted

4.1 Observations based on figures 2 and 3:


The values of x and b are plotted along the indices of the array, so it could be observed that the values
of x are close to the values of b. Also, the solution x is a smooth curve, indicating that the Jacobi
method is stable and converging to the correct solution.
4 Disant Upadhyay et al.

Table 1. Plot outputs of the solution vector for various values of N.

4.2 Observation based on the plots in table 1:


From the output plots, it can be observed that as the value of N increases, the solution x becomes
more accurate and closely matches the true solution of the linear system. This can be seen by the
fact that the values of x for larger values of N are closer to the true solution. This is due to the fact
that as N increases, the matrix A and vector b are defined on a finer grid, which allows for a more
accurate solution to be calculated. It can also be observed that the solution x becomes smoother as N
increases, which is expected since the Jacobi method is a stable iterative method.
Another observation is that the solution x is defined on a finer grid as N increases, which is
expected since the matrix A and vector b are defined on a finer grid.
It’s also worth noting that Jacobi method is not the most efficient method for solving this type of
system and the running time of the algorithm is directly proportional to the number of iterations
and the number of elements in the matrix. Therefore, for larger values of N, the running time of the
algorithm will be much higher than for smaller values of N.

5. Conclusion and Discussion


In conclusion, the Jacobi Method is a popular iterative method for solving linear systems, and it
has been shown to be effective in solving linear systems when implemented correctly. The Python
code provided in this article demonstrates the use of the Jacobi Method for solving a linear system of
equations, where the matrix A is tridiagonal, and the vector b is given.
The code demonstrates the use of the Jacobi Method for solving the system for different values
of N and it has been observed that as the value of N increases, the solution becomes more accurate,
and the solution x is defined on a finer grid.
However, it’s worth noting that the Jacobi method is not the most efficient method for solving
this type of system and the running time of the algorithm is directly proportional to the number of
iterations and the number of elements in the matrix. Therefore, for larger values of N, the running
time of the algorithm will be much higher than for smaller values of N. This makes Jacobi method
not suitable for larger systems or real-time applications.
In terms of space complexity, the Jacobi method only requires a single vector to store the solution
at each iteration, which makes it relatively memory efficient compared to other methods.
In summary, the Jacobi Method can be an efficient method for solving linear systems, but it is
Disant Upadhyay 5

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.

Appendix 1. Python code used to generate the plots

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 ( )

You might also like