Jacobi method

From testwiki
Jump to navigation Jump to search

Template:Short description Template:Distinguish

Template:One source 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 A๐ฑ=๐› be a square system of n linear equations, where:A=[a11a12โ‹ฏa1na21a22โ‹ฏa2nโ‹ฎโ‹ฎโ‹ฑโ‹ฎan1an2โ‹ฏann],๐ฑ=[x1x2โ‹ฎxn],๐›=[b1b2โ‹ฎbn].

When A and ๐› are known, and ๐ฑ is unknown, we can use the Jacobi method to approximate ๐ฑ. The vector ๐ฑ(0) denotes our initial guess for ๐ฑ (often ๐ฑi(0)=0 for i=1,2,...,n). We denote ๐ฑ(k) as the k-th approximation or iteration of ๐ฑ, and ๐ฑ(k+1) is the next (or k+1) iteration of ๐ฑ.

Matrix-based formula

Then A can be decomposed into a diagonal component D, a lower triangular part L and an upper triangular part U:A=D+L+UwhereD=[a110โ‹ฏ00a22โ‹ฏ0โ‹ฎโ‹ฎโ‹ฑโ‹ฎ00โ‹ฏann] and L+U=[0a12โ‹ฏa1na210โ‹ฏa2nโ‹ฎโ‹ฎโ‹ฑโ‹ฎan1an2โ‹ฏ0].The solution is then obtained iteratively via

๐ฑ(k+1)=Dโˆ’1(๐›โˆ’(L+U)๐ฑ(k)).

Element-based formula

The element-based formula for each row i is thus:xi(k+1)=1aii(biโˆ’โˆ‘jโ‰ iaijxj(k)),i=1,2,โ€ฆ,n.The computation of xi(k+1) requires each element in ๐ฑ(k) except itself. Unlike the Gaussโ€“Seidel method, we cannot overwrite xi(k) with xi(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: Template:Nowrap, (diagonal dominant) matrix A, right-hand side vector b, convergence criterion
Output: Template:Nowrap
Comments: pseudocode based on the element-based formula above

Template:Nowrap
while convergence not reached do
    for i := 1 step until n do
        Template:Nowrap
        for j := 1 step until n do
            if ji then
                Template:Nowrap
            end
        end
        Template:Nowrap
    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:

ฯ(Dโˆ’1(L+U))<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:

|aii|>โˆ‘jโ‰ i|aij|.

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, A=(29212611115)โ‡’Dโˆ’1(L+U)=(022912913016550)โ‡’ฯ(Dโˆ’1(L+U))โ‰ˆ1.0661.

Examples

Example question

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

A=[2157], b=[1113]andx(0)=[11].

We use the equation x(k+1)=Dโˆ’1(bโˆ’(L+U)x(k)), described above, to estimate x. First, we rewrite the equation in a more convenient form Dโˆ’1(bโˆ’(L+U)x(k))=Tx(k)+C, where T=โˆ’Dโˆ’1(L+U) and C=Dโˆ’1b. From the known values Dโˆ’1=[1/2001/7], L=[0050]andU=[0100]. we determine T=โˆ’Dโˆ’1(L+U) as T=[1/2001/7]{[00โˆ’50]+[0โˆ’100]}=[0โˆ’1/2โˆ’5/70]. Further, C is found as C=[1/2001/7][1113]=[11/213/7]. With T and C calculated, we estimate x as x(1)=Tx(0)+C: x(1)=[0โˆ’1/2โˆ’5/70][11]+[11/213/7]=[5.08/7]โ‰ˆ[51.143]. The next iteration yields x(2)=[0โˆ’1/2โˆ’5/70][5.08/7]+[11/213/7]=[69/14โˆ’12/7]โ‰ˆ[4.929โˆ’1.714]. This process is repeated until convergence (i.e., until โ€–Ax(n)โˆ’bโ€– is small). The solution after 25 iterations is

x=[7.111โˆ’3.222].

Example question 2

Suppose we are given the following linear system:

10x1โˆ’x2+2x3=6,โˆ’x1+11x2โˆ’x3+3x4=25,2x1โˆ’x2+10x3โˆ’x4=โˆ’11,3x2โˆ’x3+8x4=15.

If we choose Template:Math as the initial approximation, then the first approximate solution is given by x1=(6+0โˆ’(2โˆ—0))/10=0.6,x2=(25+0+0โˆ’(3โˆ—0))/11=25/11=2.2727,x3=(โˆ’11โˆ’(2โˆ—0)+0+0)/10=โˆ’1.1,x4=(15โˆ’(3โˆ—0)+0)/8=1.875. 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.

x1 x2 x3 x4
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 Template:Math.

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 ฯ‰ to compute the iteration as

๐ฑ(k+1)=ฯ‰Dโˆ’1(๐›โˆ’(L+U)๐ฑ(k))+(1โˆ’ฯ‰)๐ฑ(k)

with ฯ‰=2/3 being the usual choice.[1] From the relation L+U=Aโˆ’D, this may also be expressed as

๐ฑ(k+1)=ฯ‰Dโˆ’1๐›+(Iโˆ’ฯ‰Dโˆ’1A)๐ฑ(k).

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 C=Cฯ‰=Iโˆ’ฯ‰Dโˆ’1A be the iteration matrix. Then, convergence is guaranteed for

ฯ(Cฯ‰)<1โŸบ0<ฯ‰<2ฮปmax(Dโˆ’1A),

where ฮปmax is the maximal eigenvalue.

The spectral radius can be minimized for a particular choice of ฯ‰=ฯ‰opt as follows minฯ‰ฯ(Cฯ‰)=ฯ(Cฯ‰opt)=1โˆ’2ฮบ(Dโˆ’1A)+1forฯ‰opt:=2ฮปmin(Dโˆ’1A)+ฮปmax(Dโˆ’1A), where ฮบ is the matrix condition number.

See also

References

Template:Reflist

Template:Numerical linear algebra Template:Authority control