# Jacobi Iterative Method for Solving Linear System of Equations

by admin in Linear System of Equations , Math, Statistics, and Optimization , MATLAB Family on June 18, 2019**Jacobi method** is an iterative algorithm for determining the solutions of a diagonally dominant system of linear equations. Each diagonal element is solved for, and an approximate value is plugged in. The process is then iterated until it converges. This algorithm is a stripped-down version of the Jacobi transformation method of matrix diagonalization. The method is named after Carl Gustav Jacob Jacobi.

### Example On Using This Code

#### Input

tol = 1e-9; % tolerance m = 1e6; % maximum number of iterations A =[4 2 3; 3 -5 2; -2 3 8]; % Equations coefficients B = [8 ; -14 ; 27]; % Right-Hand side

#### Output

Solution vector after 111 iterations is : -1.00000000 3.00000000 2.00000000

### Contents

- Description
- Algorithm
- Convergence
- Example
- Another example
- An example using Python and Numpy

- Weighted Jacobi method
- Convergence in the symmetric positive definite case

- References
- External links

### Description

Let

be a square system of *n* linear equations, where:

Then *A* can be decomposed into a diagonal component *D*, and the remainder *R*:

The solution is then obtained iteratively via

where x^(k) is the *k*th approximation or iteration of x and x^(k+1) is the next or *k* + 1 iteration of x. The element-based formula is thus:

The computation of *x*_{i}^{(k+1)} requires each element in **x**^{(k)} except itself. Unlike the Gauss–Seidel method, we can’t overwrite *x*_{i}^{(k)} with *x*_{i}^{(k+1)}, as that value will be needed by the rest of the computation. The minimum amount of storage is two vectors of size *n*.

### Algorithm

Input:initial guess x^(0) to the solution, (diagonal dominant) matrix A, right-hand side vector b, convergence criterionOutput:solution when convergence is reachedComments:pseudocode based on the element-based formula above

k = 0whileconvergence not reacheddofori := 1step untilndosigma = 0forj := 1step untilndoifj ≠ ithenendendendend

### Convergence

The standard convergence condition (for any iterative method) is when the spectral radius of the iteration matrix is less than 1:

A sufficient (but not necessary) condition for the method to converge is that the matrix *A* is strictly or irreducibly diagonally dominant. Strict row diagonal dominance means that for each row, the absolute value of the diagonal term is greater than the sum of absolute values of other terms:

The Jacobi method sometimes converges even if these conditions are not satisfied.

Note that the Jacobi method does not converge for every symmetric positive-definite matrix. For example,

### Example

A linear system of the form Ax = b with initial estimate x^(0) is given by

We use the equation = x^(k+1) = D^(-1)(b – Rx^(k)), described above, to estimate ء. First, we rewrite the equation in a more convenient form

, where T = -D^(-1).R, and C = D^(-1).b. Note that R = L + U, where L and U are the strictly lower and upper parts of A. From the known values

we determine

as

Further, C is found as

With T and C calculated, we estimate x as

The next iteration yields

This process is repeated until convergence (i.e., until |Ax^(n) – b| is small). The solution after 25 iterations is

#### Another Example

Suppose we are given the following linear system:

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

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

0.6 | 2.27272 | -1.1 | 1.875 |

1.04727 | 1.7159 | -0.80522 | 0.88522 |

0.93263 | 2.05330 | -1.0493 | 1.13088 |

1.01519 | 1.95369 | -0.9681 | 0.97384 |

0.98899 | 2.0114 | -1.0102 | 1.02135 |

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

#### An example using Python and Numpy

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

```
import numpy as np
ITERATION_LIMIT = 1000
# initialize the matrix
A = np.array([[10., -1., 2., 0.],
[-1., 11., -1., 3.],
[2., -1., 10., -1.],
[0.0, 3., -1., 8.]])
# initialize the RHS vector
b = np.array([6., 25., -11., 15.])
# prints the system
print("System:")
for i in range(A.shape[0]):
row = ["{}*x{}".format(A[i, j], j + 1) for j in range(A.shape[1])]
print(" + ".join(row), "=", b[i])
print()
x = np.zeros_like(b)
for it_count in range(ITERATION_LIMIT):
print("Current solution:", x)
x_new = np.zeros_like(x)
for i in range(A.shape[0]):
s1 = np.dot(A[i, :i], x[:i])
s2 = np.dot(A[i, i + 1:], x[i + 1:])
x_new[i] = (b[i] - s1 - s2) / A[i, i]
if np.allclose(x, x_new, atol=1e-10, rtol=0.):
break
x = x_new
print("Solution:")
print(x)
error = np.dot(A, x) - b
print("Error:")
print(error)
```

Produces the output:

System: 10.0*x1 + -1.0*x2 + 2.0*x3 + 0.0*x4 = 6.0 -1.0*x1 + 11.0*x2 + -1.0*x3 + 3.0*x4 = 25.0 2.0*x1 + -1.0*x2 + 10.0*x3 + -1.0*x4 = -11.0 0.0*x1 + 3.0*x2 + -1.0*x3 + 8.0*x4 = 15.0 Current solution: [ 0. 0. 0. 0.] Current solution: [ 0.6 2.27272727 -1.1 1.875 ] Current solution: [ 1.04727273 1.71590909 -0.80522727 0.88522727] Current solution: [ 0.93263636 2.05330579 -1.04934091 1.13088068] Current solution: [ 1.01519876 1.95369576 -0.96810863 0.97384272] Current solution: [ 0.9889913 2.01141473 -1.0102859 1.02135051] Current solution: [ 1.00319865 1.99224126 -0.99452174 0.99443374] Current solution: [ 0.99812847 2.00230688 -1.00197223 1.00359431] Current solution: [ 1.00062513 1.9986703 -0.99903558 0.99888839] Current solution: [ 0.99967415 2.00044767 -1.00036916 1.00061919] Current solution: [ 1.0001186 1.99976795 -0.99982814 0.99978598] Current solution: [ 0.99994242 2.00008477 -1.00006833 1.0001085 ] Current solution: [ 1.00002214 1.99995896 -0.99996916 0.99995967] Current solution: [ 0.99998973 2.00001582 -1.00001257 1.00001924] Current solution: [ 1.00000409 1.99999268 -0.99999444 0.9999925 ] Current solution: [ 0.99999816 2.00000292 -1.0000023 1.00000344] Current solution: [ 1.00000075 1.99999868 -0.99999899 0.99999862] Current solution: [ 0.99999967 2.00000054 -1.00000042 1.00000062] Current solution: [ 1.00000014 1.99999976 -0.99999982 0.99999975] Current solution: [ 0.99999994 2.0000001 -1.00000008 1.00000011] Current solution: [ 1.00000003 1.99999996 -0.99999997 0.99999995] Current solution: [ 0.99999999 2.00000002 -1.00000001 1.00000002] Current solution: [ 1. 1.99999999 -0.99999999 0.99999999] Current solution: [ 1. 2. -1. 1.] Solution: [ 1. 2. -1. 1.] Error: [ -2.81440107e-08 5.15706873e-08 -3.63466359e-08 4.17092547e-08]

### Weighted Jacobi Method

The weighted Jacobi iteration uses a parameter **omega** to compute the iteration as

with omega = 2/3 being the usual choice.^{[1]}

### Convergence in the Symmetric Positive Definite Case

In case that the system matrix A is of symmetric positive-definite type one can show convergence. Let

be the iteration matrix. Then, convergence is guaranteed for

where **lambda_max** is the maximal eigenvalue.

The spectral radius can be minimized for a particular choice of omega = omega_opt as follows

where **kappa **is the matrix condition number.

### References

- Saad, Yousef (2003).
*Iterative Methods for Sparse Linear Systems*(2 ed.). SIAM. p. 414. ISBN 0898715342.

### External Links

- Hazewinkel, Michiel, ed. (2001) [1994], “Jacobi method”,
*Encyclopedia of Mathematics*, Springer Science+Business Media B.V. / Kluwer Academic Publishers, ISBN 978-1-55608-010-4 - This article incorporates text from the article Jacobi_method on CFD-Wiki that is under the GFDL license.

- Black, Noel; Moore, Shirley; and Weisstein, Eric W. “Jacobi method”.
*MathWorld*. - Jacobi Method from www.math-linux.com
- Numerical matrix inversion

Share Now!