当前位置:网站首页>Numerical calculation method chapter6 Iterative method for solving linear equations
Numerical calculation method chapter6 Iterative method for solving linear equations
2022-06-12 07:38:00 【Espresso Macchiato】
- Numerical calculation method Chapter6. Iterative methods for solving linear equations
0. Problem description
The problems to be solved in this chapter are the same as those in the previous chapter , Still n n n The problem of solving a system of linear equations .
{ a 11 x 1 + a 12 x 2 + . . . + a 1 n x n = y 1 a 21 x 1 + a 22 x 2 + . . . + a 2 n x n = y 2 . . . a n 1 x 1 + a n 2 x 2 + . . . + a n n x n = y n \left\{ \begin{aligned} a_{11}x_1 + a_{12}x_2 + ... + a_{1n}x_n &= y_1 \\ a_{21}x_1 + a_{22}x_2 + ... + a_{2n}x_n &= y_2 \\ ... \\ a_{n1}x_1 + a_{n2}x_2 + ... + a_{nn}x_n &= y_n \end{aligned} \right. ⎩⎪⎪⎪⎪⎨⎪⎪⎪⎪⎧a11x1+a12x2+...+a1nxna21x1+a22x2+...+a2nxn...an1x1+an2x2+...+annxn=y1=y2=yn
however , In the previous chapter, the linear transformation of the matrix is transformed into a triangular matrix or a diagonal matrix that can be solved quickly , The calculation result is accurate .
The idea of this chapter is to solve the problem A x = y Ax=y Ax=y convert to x = A ′ x x = A'x x=A′x The iterative form of , thus , Then we can give a group of iterated algebras x k + 1 = A ′ x k x_{k+1} = A'x_{k} xk+1=A′xk.
here , If x k x_k xk Satisfy the convergence condition , that x k x_{k} xk Will converge to x = A ′ x x = A'x x=A′x In a set of solutions of , The above questions can also be answered .
1. Jacobi iteration
1. Jacobi Iterative method
Linear transformation of the original equation , We obviously have :
{ x 1 = − a 12 a 11 x 2 − . . . − a 1 n a 11 x n + y 1 a 11 x 2 = − a 21 a 22 x 2 − . . . − a 2 n a 22 x n + y 2 a 22 . . . x n = − a n 1 a n n x 1 − a n 2 a n n x 2 − . . . + y n a n n \left\{ \begin{aligned} x_{1} = & &-\frac{a_{12}}{a_{11}}x_2 &-... &-\frac{a_{1n}}{a_{11}}x_n &+ \frac{y_1}{a_{11}} \\ x_{2} = &-\frac{a_{21}}{a_{22}}x_2 & &- ... &-\frac{a_{2n}}{a_{22}}x_n &+ \frac{y_2}{a_{22}} \\ ... \\ x_{n} = &-\frac{a_{n1}}{a_{nn}}x_1 &-\frac{a_{n2}}{a_{nn}}x_2 &- ... & &+ \frac{y_n}{a_{nn}} \end{aligned} \right. ⎩⎪⎪⎪⎪⎪⎪⎪⎨⎪⎪⎪⎪⎪⎪⎪⎧x1=x2=...xn=−a22a21x2−annan1x1−a11a12x2−annan2x2−...−...−...−a11a1nxn−a22a2nxn+a11y1+a22y2+annyn
We write it in matrix form, that is :
( x 1 x 2 . . . x n ) = ( 0 − a 12 a 11 . . . − a 1 n a 11 − a 21 a 22 0 . . . − a 2 n a 22 . . . . . . . . . . . . − a n 1 a n n − a n 2 a n n . . . 0 ) ( x 1 x 2 . . . x n ) + ( y 1 a 11 y 2 a 22 . . . y n a n n ) \begin{pmatrix} x_1 \\ x_2 \\ ... \\ x_n \end{pmatrix} = \begin{pmatrix} 0 & -\frac{a_{12}}{a_{11}} & ... & -\frac{a_{1n}}{a_{11}} \\ -\frac{a_{21}}{a_{22}} & 0 & ... & -\frac{a_{2n}}{a_{22}} \\ ... & ... & ... & ... \\ -\frac{a_{n1}}{a_{nn}} & -\frac{a_{n2}}{a_{nn}} & ... & 0 \end{pmatrix} \begin{pmatrix} x_1 \\ x_2 \\ ... \\ x_n \end{pmatrix} + \begin{pmatrix} \frac{y_1}{a_{11}} \\ \frac{y_2}{a_{22}} \\ ... \\ \frac{y_n}{a_{nn}} \end{pmatrix} ⎝⎜⎜⎛x1x2...xn⎠⎟⎟⎞=⎝⎜⎜⎛0−a22a21...−annan1−a11a120...−annan2............−a11a1n−a22a2n...0⎠⎟⎟⎞⎝⎜⎜⎛x1x2...xn⎠⎟⎟⎞+⎝⎜⎜⎛a11y1a22y2...annyn⎠⎟⎟⎞
We simplify it into a symbolic expression that is :
x = B x + g x = Bx + g x=Bx+g
Based on this , We can give it Jacobi The iterative formula is as follows :
x k + 1 = B x k + g x_{k+1} = Bx_{k} + g xk+1=Bxk+g
2. Jacobi Iterative matrix
We give a more rigorous data expression as follows , Make :
D = ( a 11 a 22 . . . a n n ) D = \begin{pmatrix} a_{11} \\ & a_{22} \\ & & ... \\ & & & a_{nn} \end{pmatrix} D=⎝⎜⎜⎛a11a22...ann⎠⎟⎟⎞
Then there are :
A x = ( D + A − D ) x = y Ax = (D + A - D)x = y Ax=(D+A−D)x=y
Then we can export :
D x = ( D − A ) x + y Dx = (D-A)x + y Dx=(D−A)x+y
Double left D − 1 D^{-1} D−1 That is to say :
x = D − 1 ( D − A ) x + D − 1 y x = D^{-1}(D-A)x + D^{-1}y x=D−1(D−A)x+D−1y
remember B = D − 1 ( D − A ) B=D^{-1}(D-A) B=D−1(D−A), g = D − 1 y g=D^{-1}y g=D−1y, You can get exactly the same content as in the previous section .
Iterative matrix B B B That is to say Jacobi Iterative matrix .
3. Jacobi Iterative convergence condition
Jacobi The necessary and sufficient condition for iterative convergence is :
Iterative matrix B B B The spectral radius of ρ ( B ) < 1 \rho(B) < 1 ρ(B)<1.
or :
- For iterative matrices B B B All eigenvalues of λ i \lambda_i λi, Both ∣ λ i ∣ < 1 |\lambda_i| < 1 ∣λi∣<1, Or equivalent m a x ( ∣ λ i ∣ ) < 1 max(|\lambda_i|) < 1 max(∣λi∣)<1.
however , In some specific cases , The above necessary and sufficient conditions can be appropriately relaxed .
To be specific , There are the following theorems :
Theorem 6.1
If the equations A x = y Ax=y Ax=y The coefficient matrix of A A A, Meet one of the following conditions , Then Jacobi Iterative convergence :
(1) A Is a row diagonally dominant matrix , namely ∣ a i i ∣ > ∑ j ≠ i ∣ a i j ∣ |a_{ii}| > \sum_{j \neq i} |a_{ij}| ∣aii∣>∑j=i∣aij∣, i = 1 , 2 , . . . , n i=1,2,...,n i=1,2,...,n;
(2) A Is a column diagonally dominant matrix , namely ∣ a j j ∣ > ∑ i ≠ j ∣ a i j ∣ |a_{jj}| > \sum_{i \neq j} |a_{ij}| ∣ajj∣>∑i=j∣aij∣, j = 1 , 2 , . . . , n j=1,2,...,n j=1,2,...,n;
4. python Pseudo code implementation
Last , We give Jacobi Iterative python The pseudocode is as follows :
def jacobi_iter(A, y, epsilon=1e-6):
n = len(A)
B = [[0 for _ in range(n)] for _ in range(n)]
g = [0 for _ in range(n)]
for i in range(n):
for j in range(n):
if j == i:
continue
B[i][j] = -A[i][j] / A[i][i]
g[i] = y[i] / A[i][i]
x = [0 for _ in range(n)]
for _ in range(10**6):
z = [0 for _ in range(n)]
for i in range(n):
z[i] += g[i]
for j in range(n):
z[i] += B[i][j] * x[j]
if max(abs(z[i] - x[i]) for i in range(n)) < epsilon:
break
x = z
return z
2. Gauss-Seidel iteration
1. Gauss-Seidel Iterative method
Gauss-Seidel Iterative equations and the above Jacobi Iterations are actually very similar , The only difference is that Jacobi Iteration is based on x ( k ) x^{(k)} x(k) Update iteratively for the whole each time , and Guass-Seidel Iteration is to calculate each x i ( k ) x^{(k)}_{i} xi(k) Is to use all that have been iteratively calculated x j ( k ) x^{(k)}_{j} xj(k) Result .
That is , Each element is updated iteratively .
Expressed by formula, it is :
{ x 1 ( k + 1 ) = − a 12 a 11 x 2 ( k ) − . . . − a 1 n a 11 x n ( k ) + y 1 a 11 x 2 ( k + 1 ) = − a 21 a 22 x 1 ( k + 1 ) − . . . − a 2 n a 22 x n ( k ) + y 2 a 22 . . . x n ( k + 1 ) = − a n 1 a n n x 1 ( k + 1 ) − a n 2 a n n x 2 ( k + 1 ) − . . . + y n a n n \left\{ \begin{aligned} x^{(k+1)}_{1} = & &-\frac{a_{12}}{a_{11}}x^{(k)}_2 &-... &-\frac{a_{1n}}{a_{11}}x^{(k)}_n &+ \frac{y_1}{a_{11}} \\ x^{(k+1)}_{2} = &-\frac{a_{21}}{a_{22}}x^{(k+1)}_1 & &- ... &-\frac{a_{2n}}{a_{22}}x^{(k)}_n &+ \frac{y_2}{a_{22}} \\ ... \\ x^{(k+1)}_{n} = &-\frac{a_{n1}}{a_{nn}}x^{(k+1)}_1 &-\frac{a_{n2}}{a_{nn}}x^{(k+1)}_2 &- ... & &+ \frac{y_n}{a_{nn}} \end{aligned} \right. ⎩⎪⎪⎪⎪⎪⎪⎪⎨⎪⎪⎪⎪⎪⎪⎪⎧x1(k+1)=x2(k+1)=...xn(k+1)=−a22a21x1(k+1)−annan1x1(k+1)−a11a12x2(k)−annan2x2(k+1)−...−...−...−a11a1nxn(k)−a22a2nxn(k)+a11y1+a22y2+annyn
2. Gauss-Seidel Iterative matrix
alike , We give a more rigorous mathematical derivation as follows :
A = D + L + U = ( a 11 a 22 . . . a n n ) + ( 0 a 21 0 . . . a n 1 a n 2 . . . 0 ) ( 0 a 12 . . . a 1 n 0 . . . a 2 n . . . 0 ) \begin{aligned} A &= D + L + U \\ &= \begin{pmatrix} a_{11} \\ & a_{22} \\ & & ... \\ & & & a_{nn} \end{pmatrix} + \begin{pmatrix} 0 \\ a_{21} & 0 \\ ... \\ a_{n1} & a_{n2} & ... & 0 \end{pmatrix} \begin{pmatrix} 0 & a_{12} & ... & a_{1n} \\ & 0 & ... & a_{2n} \\ & & ... \\ & & & 0 \end{pmatrix} \end{aligned} A=D+L+U=⎝⎜⎜⎛a11a22...ann⎠⎟⎟⎞+⎝⎜⎜⎛0a21...an10an2...0⎠⎟⎟⎞⎝⎜⎜⎛0a120.........a1na2n0⎠⎟⎟⎞
thus , We have :
A x = ( D + L + U ) x = y Ax = (D+L+U)x = y Ax=(D+L+U)x=y
or :
( D + L ) x = − U x + y (D+L)x = -Ux + y (D+L)x=−Ux+y
Multiply both sides by ( D + l ) − 1 (D+l)^{-1} (D+l)−1 That is to say :
x = − ( D + L ) − 1 U x + ( D + L ) − 1 y x = -(D+L)^{-1}Ux + (D+L)^{-1}y x=−(D+L)−1Ux+(D+L)−1y
Make S = − ( D + L ) − 1 U S = -(D+L)^{-1}U S=−(D+L)−1U, f = ( D + L ) − 1 y f = (D+L)^{-1}y f=(D+L)−1y, We can write Gauss-Seidel Iterative formula :
x ( k + 1 ) = S x ( k ) + f x^{(k+1)} = Sx^{(k)} + f x(k+1)=Sx(k)+f
It is called iterative matrix S S S That is to say Gauss-Seidel Iterative matrix .
Of course , As mentioned in the previous section , In fact, it is not necessary to calculate S S S and f f f, Just according to the previous J a c o b i Jacobi Jacobi The iteration matrix can be updated in real time .
3. Gauss-Seidel Iterative convergence condition
alike , We give the book about Gauss-Seidel The convergence conditions of the iteration are as follows :
Theorem 6.2
If the coefficient matrix of the system of equations is diagonally dominant in rows or columns , be Gauss-Seidel Iterative convergence .
Theorem 6.3
If the coefficient matrix of the system of equations A A A Is a symmetric positive definite matrix , be Gauss-Seidel Iterative convergence .
4. Pseudo code implementation
alike , We use it python The pseudo code given is as follows :
def gauss_seidel_iter(A, y, epsilon=1e-6):
n = len(A)
B = [[0 for _ in range(n)] for _ in range(n)]
g = [0 for _ in range(n)]
for i in range(n):
for j in range(n):
if j == i:
continue
B[i][j] = -A[i][j] / A[i][i]
g[i] = y[i] / A[i][i]
x = [0 for _ in range(n)]
cnt = 0
for _ in range(10**6):
for i in range(n):
z = g[i]
for j in range(n):
z += B[i][j] * x[j]
if abs(z-x[i]) < epsilon:
cnt += 1
else:
cnt = 0
x[i] = z
if cnt >= n:
break
if cnt >= n:
break
return x
3. Relaxation iteration
1. Relaxation iteration method
The prototype of relaxation iteration is still the same as before Jacobi iteration , however , and Gauss-Seidel The real-time parameter update of the iteration is different , Relaxation iteration is right here Jacobi Iterative batch update and Gauss-Seidel Iterative real-time updates take a compromise , Through a super parameter w w w To control the parameter update speed .
To be specific , That is to say :
{ x 1 ( k + 1 ) = ( 1 − w ) x 1 ( k ) + w ( b 12 x 2 ( k ) + b 13 x 3 ( k ) + . . . + b 1 n x n ( k ) + g 1 ) x 2 ( k + 1 ) = ( 1 − w ) x 2 ( k ) + w ( b 21 x 1 ( k + 1 ) + b 23 x 3 ( k ) + . . . + b 2 n x n ( k ) + g 2 ) . . . x n ( k + 1 ) = ( 1 − w ) x n ( k ) + w ( b n 1 x 1 ( k + 1 ) + b n 2 x 2 ( k + 1 ) + . . . + b n , n − 1 x n − 1 ( k + 1 ) + g n ) \left\{ \begin{aligned} x^{(k+1)}_1 &= (1-w)x^{(k)}_1 + w(b_{12}x^{(k)}_2 + b_{13}x^{(k)}_3 + ... + b_{1n}x^{(k)}_n + g_1) \\ x^{(k+1)}_2 &= (1-w)x^{(k)}_2 + w(b_{21}x^{(k+1)}_1 + b_{23}x^{(k)}_3 + ... + b_{2n}x^{(k)}_n + g_2) \\ ... \\ x^{(k+1)}_n &= (1-w)x^{(k)}_n + w(b_{n1}x^{(k+1)}_1 + b_{n2}x^{(k+1)}_2 + ... + b_{n,n-1}x^{(k+1)}_{n-1} + g_n) \end{aligned} \right. ⎩⎪⎪⎪⎪⎪⎨⎪⎪⎪⎪⎪⎧x1(k+1)x2(k+1)...xn(k+1)=(1−w)x1(k)+w(b12x2(k)+b13x3(k)+...+b1nxn(k)+g1)=(1−w)x2(k)+w(b21x1(k+1)+b23x3(k)+...+b2nxn(k)+g2)=(1−w)xn(k)+w(bn1x1(k+1)+bn2x2(k+1)+...+bn,n−1xn−1(k+1)+gn)
2. Relaxation iteration matrix
alike , We give the mathematical expression of relaxation iteration as follows :
x ( k + 1 ) = ( 1 − w ) x ( k ) + w ( L ~ x ( k + 1 ) + U ~ x ( k ) + g ) x^{(k+1)} = (1-w)x^{(k)} + w(\tilde{L}x^{(k+1)} + \tilde{U}x^{(k)} + g) x(k+1)=(1−w)x(k)+w(L~x(k+1)+U~x(k)+g)
Modelled on the Gauss-Seidel iteration , We can also give the iteration matrix format as follows :
x ( k + 1 ) = S w x ( k ) + f x^{(k+1)} = S_w x^{(k)} + f x(k+1)=Swx(k)+f
among ,
{ S w = ( I + w D − 1 L ) − 1 [ ( 1 − w ) I − w D − 1 U ] f = w ( I + w D − 1 L ) − 1 g \left\{ \begin{aligned} S_w &= (I + wD^{-1}L)^{-1}[(1-w)I - wD^{-1}U] \\ f &= w(I + wD^{-1}L)^{-1}g \end{aligned} \right. { Swf=(I+wD−1L)−1[(1−w)I−wD−1U]=w(I+wD−1L)−1g
3. Convergence condition of relaxation iteration
There are two theorems to judge the convergence of relaxation iteration :
Theorem 6.4
The necessary condition for the convergence of relaxation iteration is 0 < w < 2 0 < w < 2 0<w<2;
Theorem 6.5
if A A A For symmetric positive definite matrix , Then when 0 < w < 2 0 < w < 2 0<w<2 when , Relaxation iteration has constant convergence ;
Special , When 0 < w < 1 0 < w < 1 0<w<1 when , Call it Sub relaxation iteration ; When 1 < w < 2 1 < w < 2 1<w<2 when , Call it Over relaxation iteration ; When w = 1 w=1 w=1 when , Iterations degenerate into Gauss-Seidel iteration .
4. Pseudo code implementation
Last , We also give the pseudo code implementation of relaxation iteration as follows :
def loose_iter(A, y, w=0.5, epsilon=1e-6):
n = len(A)
B = [[0 for _ in range(n)] for _ in range(n)]
g = [0 for _ in range(n)]
for i in range(n):
for j in range(n):
if j == i:
continue
B[i][j] = -A[i][j] / A[i][i]
g[i] = y[i] / A[i][i]
x = [0 for _ in range(n)]
cnt = 0
for _ in range(10**6):
for i in range(n):
z = (1-w) * x[i] + w * g[i]
for j in range(n):
z += w * B[i][j] * x[j]
if abs(z-x[i]) < epsilon:
cnt += 1
else:
cnt = 0
x[i] = z
if cnt >= n:
break
if cnt >= n:
break
return x
4. Inverse matrix calculation
Last , Let's look at the inverse matrix calculation .
In principle, the calculation of inverse matrix is actually a special application of solving linear equations mentioned above , As a matter of fact n n n Then we can get our inverse matrix by splicing the solutions of the unit vectors .
We won't go into details here , Just give python The pseudo code is implemented as follows :
def cal_inverse_matrix(A):
n = len(A)
res = [[0 for _ in range(n)] for _ in range(n)]
for j in range(n):
y = [0 for _ in range(n)]
y[j] = 1
x = gauss_seidel_iter(A, y)
for i in range(n):
res[i][j] = x[i]
return res
边栏推荐
- Voice assistant -- Qu -- semantic role annotation and its application
- Voice assistant - Multi round conversation (theory and concept)
- Cold start problem of recommended system
- Shortcut key modification of TMUX and VIM
- Improved schemes for episodic memory based lifelong learning
- Test left shift real introduction
- Gd32f4 (5): gd32f450 clock is configured as 200m process analysis
- Source code learning - [FreeRTOS] privileged_ Understanding of function meaning
- Golang quickly generates model and queryset of database tables
- LeetCode笔记:Biweekly Contest 79
猜你喜欢

Knife4j first use

Arrangement of statistical learning knowledge points gradient descent, least square method, Newton method

Gd32f4 (5): gd32f450 clock is configured as 200m process analysis

GD32F4(5):GD32F450时钟配置为200M过程分析

2022年G3锅炉水处理复训题库及答案
![‘CMRESHandler‘ object has no attribute ‘_ timer‘,socket. gaierror: [Errno 8] nodename nor servname pro](/img/de/6756c1b8d9b792118bebb2d6c1e54c.png)
‘CMRESHandler‘ object has no attribute ‘_ timer‘,socket. gaierror: [Errno 8] nodename nor servname pro

Construction of running water lamp experiment with simulation software proteus

Formatting the generalization forgetting trade off in continuous learning

Summary of machine learning + pattern recognition learning (I) -- k-nearest neighbor method

C language sizeof strlen
随机推荐
2022年危险化学品经营单位安全管理人员特种作业证考试题库及答案
Summary of machine learning + pattern recognition learning (IV) -- decision tree
MySQL index (easy to handle in one article)
Scoring prediction problem
Use case design of software testing interview questions
‘CMRESHandler‘ object has no attribute ‘_timer‘,socket.gaierror: [Errno 8] nodename nor servname pro
R语言使用neuralnet包构建神经网络回归模型(前馈神经网络回归模型),计算模型在测试集上的MSE值(均方误差)
10 lessons from the recommended system
Voice assistant - future trends
Construction of running water lamp experiment with simulation software proteus
Voice assistant - Introduction and interaction process
Summary of software testing tools in 2021 - unit testing tools
R语言dplyr包mutate_at函数和one_of函数将dataframe数据中指定数据列(通过向量指定)的数据类型转化为因子类型
Qt实现托盘
Machine learning from entry to re entry: re understanding of SVM
Golang quickly generates model and queryset of database tables
Summary of semantic segmentation learning (II) -- UNET network
20220526 损失函数
ECMAScript6面试题
謀新局、促發展,桂林綠色數字經濟的頭雁效應