Jacobi method
In numerical linear algebra, the Jacobi method (a.k.a. the Jacobi iteration method) is an iterative algorithm for determining the solutions of a strictly 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.
Description
Let [math]\displaystyle{ A\mathbf x = \mathbf b }[/math] be a square system of n linear equations, where:[math]\displaystyle{ A = \begin{bmatrix} a_{11} & a_{12} & \cdots & a_{1n} \\ a_{21} & a_{22} & \cdots & a_{2n} \\ \vdots & \vdots & \ddots & \vdots \\a_{n1} & a_{n2} & \cdots & a_{nn} \end{bmatrix}, \qquad \mathbf{x} = \begin{bmatrix} x_{1} \\ x_2 \\ \vdots \\ x_n \end{bmatrix} , \qquad \mathbf{b} = \begin{bmatrix} b_{1} \\ b_2 \\ \vdots \\ b_n \end{bmatrix}. }[/math]
When [math]\displaystyle{ A }[/math] and [math]\displaystyle{ \mathbf b }[/math] are known, and [math]\displaystyle{ \mathbf x }[/math] is unknown, we can use the Jacobi method to approximate [math]\displaystyle{ \mathbf x }[/math]. The vector [math]\displaystyle{ \mathbf x^{(0)} }[/math] denotes our initial guess for [math]\displaystyle{ \mathbf x }[/math] (often [math]\displaystyle{ \mathbf x^{(0)}_i=0 }[/math] for [math]\displaystyle{ i=1,2,...,n }[/math]). We denote [math]\displaystyle{ \mathbf{x}^{(k)} }[/math] as the k-th approximation or iteration of [math]\displaystyle{ \mathbf{x} }[/math], and [math]\displaystyle{ \mathbf{x}^{(k+1)} }[/math] is the next (or k+1) iteration of [math]\displaystyle{ \mathbf{x} }[/math].
Matrix-based formula
Then A can be decomposed into a diagonal component D, a lower triangular part L and an upper triangular part U:[math]\displaystyle{ A=D+L+U \qquad \text{where} \qquad D = \begin{bmatrix} a_{11} & 0 & \cdots & 0 \\ 0 & a_{22} & \cdots & 0 \\ \vdots & \vdots & \ddots & \vdots \\0 & 0 & \cdots & a_{nn} \end{bmatrix} \text{ and } L+U = \begin{bmatrix} 0 & a_{12} & \cdots & a_{1n} \\ a_{21} & 0 & \cdots & a_{2n} \\ \vdots & \vdots & \ddots & \vdots \\ a_{n1} & a_{n2} & \cdots & 0 \end{bmatrix}. }[/math]The solution is then obtained iteratively via
- [math]\displaystyle{ \mathbf{x}^{(k+1)} = D^{-1} (\mathbf{b} - (L+U) \mathbf{x}^{(k)}). }[/math]
Element-based formula
The element-based formula for each row [math]\displaystyle{ i }[/math] is thus:[math]\displaystyle{ x^{(k+1)}_i = \frac{1}{a_{ii}} \left(b_i -\sum_{j\ne i}a_{ij}x^{(k)}_j\right),\quad i=1,2,\ldots,n. }[/math]The computation of [math]\displaystyle{ x_i^{(k+1)} }[/math] requires each element in [math]\displaystyle{ \mathbf{x}^{(k)} }[/math] except itself. Unlike the Gauss–Seidel method, we can't overwrite [math]\displaystyle{ x_i^{(k)} }[/math] with [math]\displaystyle{ x_i^{(k+1)} }[/math], 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 criterion Output: solution when convergence is reached Comments: pseudocode based on the element-based formula above k = 0 while convergence not reached do for i := 1 step until n do σ = 0 for j := 1 step until n do if j ≠ i then σ = σ + aij xj(k) end end xi(k+1) = (bi − σ) / aii end increment k end
Convergence
The standard convergence condition (for any iterative method) is when the spectral radius of the iteration matrix is less than 1:
- [math]\displaystyle{ \rho(D^{-1}(L+U)) \lt 1. }[/math]
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:
- [math]\displaystyle{ \left | a_{ii} \right | \gt \sum_{j \ne i} {\left | a_{ij} \right |}. }[/math]
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, [math]\displaystyle{ A = \begin{pmatrix} 29 & 2 & 1\\ 2 & 6 & 1\\ 1 & 1 & \frac{1}{5} \end{pmatrix} \quad \Rightarrow \quad D^{-1} (L+U) = \begin{pmatrix} 0 & \frac{2}{29} & \frac{1}{29}\\ \frac{1}{3} & 0 & \frac{1}{6}\\ 5 & 5 & 0 \end{pmatrix} \quad \Rightarrow \quad \rho(D^{-1}(L+U)) \approx 1.0661 \,. }[/math]
Examples
Example 1
A linear system of the form [math]\displaystyle{ Ax=b }[/math] with initial estimate [math]\displaystyle{ x^{(0)} }[/math] is given by
- [math]\displaystyle{ A= \begin{bmatrix} 2 & 1 \\ 5 & 7 \\ \end{bmatrix}, \ b= \begin{bmatrix} 11 \\ 13 \\ \end{bmatrix} \quad \text{and} \quad x^{(0)} = \begin{bmatrix} 1 \\ 1 \\ \end{bmatrix} . }[/math]
We use the equation [math]\displaystyle{ x^{(k+1)}=D^{-1}(b - (L+U)x^{(k)}) }[/math], described above, to estimate [math]\displaystyle{ x }[/math]. First, we rewrite the equation in a more convenient form [math]\displaystyle{ D^{-1}(b - (L+U)x^{(k)}) = Tx^{(k)} + C }[/math], where [math]\displaystyle{ T=-D^{-1}(L+U) }[/math] and [math]\displaystyle{ C = D^{-1}b }[/math]. From the known values [math]\displaystyle{ D^{-1}= \begin{bmatrix} 1/2 & 0 \\ 0 & 1/7 \\ \end{bmatrix}, \ L= \begin{bmatrix} 0 & 0 \\ 5 & 0 \\ \end{bmatrix} \quad \text{and} \quad U = \begin{bmatrix} 0 & 1 \\ 0 & 0 \\ \end{bmatrix} . }[/math] we determine [math]\displaystyle{ T=-D^{-1}(L+U) }[/math] as [math]\displaystyle{ T= \begin{bmatrix} 1/2 & 0 \\ 0 & 1/7 \\ \end{bmatrix} \left\{ \begin{bmatrix} 0 & 0 \\ -5 & 0 \\ \end{bmatrix} + \begin{bmatrix} 0 & -1 \\ 0 & 0 \\ \end{bmatrix}\right\} = \begin{bmatrix} 0 & -1/2 \\ -5/7 & 0 \\ \end{bmatrix} . }[/math] Further, [math]\displaystyle{ C }[/math] is found as [math]\displaystyle{ C = \begin{bmatrix} 1/2 & 0 \\ 0 & 1/7 \\ \end{bmatrix} \begin{bmatrix} 11 \\ 13 \\ \end{bmatrix} = \begin{bmatrix} 11/2 \\ 13/7 \\ \end{bmatrix}. }[/math] With [math]\displaystyle{ T }[/math] and [math]\displaystyle{ C }[/math] calculated, we estimate [math]\displaystyle{ x }[/math] as [math]\displaystyle{ x^{(1)}= Tx^{(0)}+C }[/math]: [math]\displaystyle{ x^{(1)}= \begin{bmatrix} 0 & -1/2 \\ -5/7 & 0 \\ \end{bmatrix} \begin{bmatrix} 1 \\ 1 \\ \end{bmatrix} + \begin{bmatrix} 11/2 \\ 13/7 \\ \end{bmatrix} = \begin{bmatrix} 5.0 \\ 8/7 \\ \end{bmatrix} \approx \begin{bmatrix} 5 \\ 1.143 \\ \end{bmatrix} . }[/math] The next iteration yields [math]\displaystyle{ x^{(2)}= \begin{bmatrix} 0 & -1/2 \\ -5/7 & 0 \\ \end{bmatrix} \begin{bmatrix} 5.0 \\ 8/7 \\ \end{bmatrix} + \begin{bmatrix} 11/2 \\ 13/7 \\ \end{bmatrix} = \begin{bmatrix} 69/14 \\ -12/7 \\ \end{bmatrix} \approx \begin{bmatrix} 4.929 \\ -1.714 \\ \end{bmatrix} . }[/math] This process is repeated until convergence (i.e., until [math]\displaystyle{ \|Ax^{(n)} - b\| }[/math] is small). The solution after 25 iterations is
- [math]\displaystyle{ x=\begin{bmatrix} 7.111\\ -3.222 \end{bmatrix} . }[/math]
Example 2
Suppose we are given the following linear system:
- [math]\displaystyle{ \begin{align} 10x_1 - x_2 + 2x_3 & = 6, \\ -x_1 + 11x_2 - x_3 + 3x_4 & = 25, \\ 2x_1- x_2+ 10x_3 - x_4 & = -11, \\ 3x_2 - x_3 + 8x_4 & = 15. \end{align} }[/math]
If we choose (0, 0, 0, 0) as the initial approximation, then the first approximate solution is given by [math]\displaystyle{ \begin{align} x_1 & = (6 + 0 - (2 * 0)) / 10 = 0.6, \\ x_2 & = (25 + 0 + 0 - (3 * 0)) / 11 = 25/11 = 2.2727, \\ x_3 & = (-11 - (2 * 0) + 0 + 0) / 10 = -1.1,\\ x_4 & = (15 - (3 * 0) + 0) / 8 = 1.875. \end{align} }[/math] 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.
[math]\displaystyle{ x_1 }[/math] | [math]\displaystyle{ x_2 }[/math] | [math]\displaystyle{ x_3 }[/math] | [math]\displaystyle{ x_4 }[/math] |
---|---|---|---|
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).
Python example
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 = [f"{A[i, j]}*x{j + 1}" for j in range(A.shape[1])] print(f'{" + ".join(row)} = {b[i]}') print() x = np.zeros_like(b) for it_count in range(ITERATION_LIMIT): if it_count != 0: print(f"Iteration {it_count}: {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 x_new[i] == x_new[i-1]: break 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)
Weighted Jacobi method
The weighted Jacobi iteration uses a parameter [math]\displaystyle{ \omega }[/math] to compute the iteration as
- [math]\displaystyle{ \mathbf{x}^{(k+1)} = \omega D^{-1} (\mathbf{b} - (L+U) \mathbf{x}^{(k)}) + \left(1-\omega\right)\mathbf{x}^{(k)} }[/math]
with [math]\displaystyle{ \omega = 2/3 }[/math] being the usual choice.[1] From the relation [math]\displaystyle{ L + U = A - D }[/math], this may also be expressed as
- [math]\displaystyle{ \mathbf{x}^{(k+1)} = \omega D^{-1} \mathbf{b} + \left( I - \omega D^{-1} A \right) \mathbf{x}^{(k)} }[/math].
Convergence in the symmetric positive definite case
In case that the system matrix [math]\displaystyle{ A }[/math] is of symmetric positive-definite type one can show convergence.
Let [math]\displaystyle{ C=C_\omega = I-\omega D^{-1}A }[/math] be the iteration matrix. Then, convergence is guaranteed for
- [math]\displaystyle{ \rho(C_\omega) \lt 1 \quad \Longleftrightarrow \quad 0 \lt \omega \lt \frac{2}{\lambda_\text{max} (D^{-1}A)} \,, }[/math]
where [math]\displaystyle{ \lambda_\text{max} }[/math] is the maximal eigenvalue.
The spectral radius can be minimized for a particular choice of [math]\displaystyle{ \omega = \omega_\text{opt} }[/math] as follows [math]\displaystyle{ \min_\omega \rho (C_\omega) = \rho (C_{\omega_\text{opt}}) = 1-\frac{2}{\kappa(D^{-1}A)+1} \quad \text{for} \quad \omega_\text{opt} := \frac{2}{\lambda_\text{min}(D^{-1}A)+\lambda_\text{max}(D^{-1}A)} \,, }[/math] where [math]\displaystyle{ \kappa }[/math] is the matrix condition number.
See also
- Gauss–Seidel method
- Successive over-relaxation
- Iterative method § Linear systems
- Gaussian Belief Propagation
- Matrix splitting
References
- ↑ Saad, Yousef (2003). Iterative Methods for Sparse Linear Systems (2nd ed.). SIAM. p. 414. ISBN 0898715342. https://archive.org/details/iterativemethods0000saad/page/414.
External links
- Black, Noel. "Jacobi method". http://mathworld.wolfram.com/JacobiMethod.html.
- Jacobi Method from www.math-linux.com
Original source: https://en.wikipedia.org/wiki/Jacobi method.
Read more |