# 线性方程组的SOR迭代法

3 篇文章 2 订阅

## 写在前面

• 1 SOR简介
• 2 SOR算法推导
• 3 SOR算法收敛性
• 4 实例分析
• 5 代码实现
• 6 参考文献与链接

### 迭代法收敛定理

ρ ( M ) = max ⁡ i { λ i ∣ i = 1 , 2 , ⋯ n } < 1 ( ∥ M ∥ 2 < 1 )    (1) \rho \left( \mathbf{M} \right) =\mathop {\max} \limits_i\left\{ \lambda _i\left| i=1,2,\cdots n \right. \right\} <1\left( \lVert \mathbf{M} \rVert _2<1 \right) \,\, \tag{1}

∥ M ∥ < 1 (2) \lVert \mathbf{M} \rVert <1 \tag{2}

## 1 SOR简介

SOR是Successive Over Relaxation（逐次超松弛）的缩写。该方法是求解大型稀疏矩阵方程组的有效方法之一，也可看作为Gauss-Seidel迭代法的加速，Gauss-Seidel是SOR迭代的一种特殊形式。

## 2 SOR算法推导

a i 1 x 1 + a i 2 x 2 + ⋯ + a i , i − 1 x i − 1 + a i i x i ⋯ + a i n x n = b i , ( i = 1 , 2 , ⋯   , n ) (2.1) a_{i 1} x_{1}+a_{i 2} x_{2}+\cdots+a_{i, i-1} x_{i-1}+a_{i i} x_{i} \cdots+a_{i n} x_{n}=b_{i}, \quad(i=1,2, \cdots, n)\tag{2.1}

⇒ a i i x i = b i − ( a i 1 x 1 + a i 2 x 2 + ⋯ + a i , i − 1 x i − 1 ) − ( a i , i + 1 x i + 1 + ⋯ + a i n x n ) ⇒ a i i x i = a i i x i + ( b i − a i 1 x 1 − a i 2 x 2 − ⋯ − a i , i − 1 x i − 1 − a i i x i − a i , i + 1 x i + 1 − ⋯ − a i n x n ) ⇒ x i = x i + 1 a i i ( b i − a i 1 x 1 − a i 2 x 2 − ⋯ − a i , i − 1 x i − 1 − a i t x i − a i , i + 1 x i + 1 − ⋯ − a i n x n ) \begin{aligned} &\Rightarrow a_{i i} x_{i}=b_{i}-\left(a_{i 1} x_{1}+a_{i 2} x_{2}+\cdots+a_{i, i-1} x_{i-1}\right)-\left(a_{i, i+1} x_{i+1}+\cdots+a_{i n} x_{n}\right)\\ &\Rightarrow a_{i i} x_{i}=a_{i i} x_{i}+\left(b_{i}-a_{i 1} x_{1}-a_{i 2} x_{2}-\cdots-a_{i, i-1} x_{i-1}-a_{i i} x_{i}-a_{i, i+1} x_{i+1}-\cdots-a_{i n} x_{n}\right)\\ &\Rightarrow x_{i}=x_{i}+\frac{1}{a_{i i}}\left(b_{i}-a_{i 1} x_{1}-a_{i 2} x_{2}-\cdots-a_{i, i-1} x_{i-1}-a_{i t} x_{i}-a_{i, i+1} x_{i+1}-\cdots-a_{i n} x_{n}\right) \end{aligned}

x i ( k + 1 ) = x i ( k ) + 1 a i i ( b i − a i 1 x 1 ( k + 1 ) − ⋯ − a i , i − 1 x i − 1 ( k + 1 ) − a i n x i ( k ) − ⋯ − a i n x n ( k ) ) = x i ( k ) + 1 a i i ( b i − ∑ j = 1 i − 1 a i j x j ( k + 1 ) − ∑ j = i n a i j x j ( k ) ) r i ( k ) = ( b i − ∑ j = 1 i − 1 a i j x j ( k + 1 ) − ∑ j = i n a i j x j ( k ) ) , i = 1 , 2 , ⋯   , n (2.2) \begin{array}{c} x_{i}^{(k+1)}=x_{i}^{(k)}+\frac{1}{a_{i i}}\left(b_{i}-a_{i 1} x_{1}^{(k+1)}-\cdots-a_{i, i-1} x_{i-1}^{(k+1)}-a_{i n} x_{i}^{(k)}-\cdots-a_{i n} x_{n}^{(k)}\right) \\ =x_{i}^{(k)}+\frac{1}{a_{i i}}\left(b_{i}-\sum_{j=1}^{i-1} a_{i j} x_{j}^{(k+1)}-\sum_{j=i}^{n} a_{i j} x_{j}^{(k)}\right) \\ r_{i}^{(k)}=\left(b_{i}-\sum_{j=1}^{i-1} a_{i j} x_{j}^{(k+1)}-\sum_{j=i}^{n} a_{i j} x_{j}^{(k)}\right), \quad i=1,2, \cdots, n \end{array}\tag{2.2}

r i ( k ) = ( b i − ∑ j = 1 i − 1 a i j x j ( k + 1 ) − ∑ j = i n a i j x j ( k ) ) , i = 1 , 2 , ⋯   , n r_{i}^{(k)}=\left(b_{i}-\sum_{j=1}^{i-1} a_{i j} x_{j}^{(k+1)}-\sum_{j=i}^{n} a_{i j} x_{j}^{(k)}\right), \quad i=1,2, \cdots, n

x i ( k + 1 ) = x i ( k ) + 1 a i i r i ( k ) (2.3) x_{i}^{(k+1)}=x_{i}^{(k)}+\frac{1}{a_{i i}} r_{i}^{(k)}\tag{2.3}

x i ( k + 1 ) = x i ( k ) + ω a i i r i ( k ) , i = 1 , 2 , ⋯   , n (2.4) x_{i}^{(k+1)}=x_{i}^{(k)}+\frac{\omega}{a_{i i}} r_{i}^{(k)}, \quad i=1,2, \cdots, n\tag{2.4}

x i ( k + 1 ) = ( 1 − ω ) x i ( k ) + ω a i i ( b i − ∑ j = 1 i − 1 a i j x j ( k + 1 ) − ∑ j = i + 1 n a i j x j ( k ) ) , i = 1 , 2 , ⋯   , n (2.5) x_{i}^{(k+1)}=(1-\omega) x_{i}^{(k)}+\frac{\omega}{a_{i i}}\left(b_{i}-\sum_{j=1}^{i-1} a_{i j} x_{j}^{(k+1)}-\sum_{j=i+1}^{n} a_{i j} x_{j}^{(k)}\right), \quad i=1,2, \cdots, n\tag{2.5}

X ( k + 1 ) = ( 1 − ω ) X ( k ) + ω D − 1 ( b + L X ( k ) + U X ( k ) ) (2.6) \mathbf{X}^{(k+1)}=(1-\omega) \mathbf{X}^{(k)}+\omega \mathbf{D}^{-1}\left(b+\mathbf{L} \mathbf{X}^{(k)}+\mathbf{U} \mathbf{X}^{(k)}\right)\tag{2.6}

D = ( a 11 a 22 ⋱ a n n ) , L = ( 0 a 21 0 ⋮ ⋱ ⋱ a n 1 a n 2 ⋯ 0 ) , U = ( 0 a 12 ⋯ a 1 n 0 ⋱ a 2 n ⋱ ⋮ 0 ) \mathbf{D}=\left( \begin{matrix} a_{11}& & & \\ & a_{22}& & \\ & & \ddots& \\ & & & a_{nn}\\ \end{matrix} \right), \mathbf{L}=\left( \begin{matrix} 0& & & \\ a_{21}& 0& & \\ \vdots& \ddots& \ddots& \\ a_{n1}& a_{n2}& \cdots& 0\\ \end{matrix} \right) , \mathbf{U}=\left( \begin{matrix} 0& a_{12}& \cdots& a_{1n}\\ & 0& \ddots& a_{2n}\\ & & \ddots& \vdots\\ & & & 0\\ \end{matrix} \right)

## 3 SOR算法收敛性

D X ( k + 1 ) = ( 1 − ω ) D X ( k ) + ω ( b + L X ( k + 1 ) + U X ( k ) ) \mathbf{DX}^{\left( k+1 \right)}=\left( 1-\omega \right) \mathbf{DX}^{\left( k \right)}+\omega \left( b+\mathbf{LX}^{\left( k+1 \right)}+\mathbf{UX}^{\left( k \right)} \right)

D X ( k + 1 ) − ω L X ( k + 1 ) = ( 1 − ω ) D X ( k ) + ω U X ( k ) + ω b \mathbf{D} \mathbf{X}^{(k+1)}-\omega \mathbf{L} \mathbf{X}^{(k+1)}=(1-\omega) \mathbf{D} \mathbf{X}^{(k)}+\omega \mathbf{U} \mathbf{X}^{(k)}+\omega b

( D − ω L ) X ( k + 1 ) = [ ( 1 − ω ) D + ω U ] X ( k ) + ω b ⇒ X ( k + 1 ) = ( D − ω L ) − 1 [ ( 1 − ω ) D + ω U ] X ( k ) + ω ( D − ω L ) − 1 b \begin{array}{l} (\mathbf{D}-\omega \mathbf{L}) \mathbf{X}^{(k+1)}=[(1-\omega) \mathbf{D}+\omega \mathbf{U}] \mathbf{X}^{(k)}+\omega b \\ \Rightarrow \mathbf{X}^{(k+1)}=(\mathbf{D}-\omega \mathbf{L})^{-1}[(1-\omega) \mathbf{D}+\omega \mathbf{U}] \mathbf{X}^{(k)}+\omega(\mathbf{D}-\omega \mathbf{L})^{-1} b \end{array}

{ B ω = ( D − ω L ) − 1 [ ( 1 − ω ) D + ω U ] F ω = ω ( D − ω L ) − 1 b (3.1) \left\{\begin{array}{c} \mathbf{B}_{\omega}=(\mathbf{D}-\omega \mathbf{L})^{-1}[(1-\omega) \mathbf{D}+\omega \mathbf{U}] \\ \mathbf{F}_{\omega}=\omega(\mathbf{D}-\omega \mathbf{L})^{-1} b \end{array}\right. \tag{3.1}

X ( k + 1 ) = B ω ( X ) ( k ) + F ω (3.2) \mathbf{X}^{(k+1)}=\mathbf{B_{\omega}} \mathbf(X)^{(k)}+\mathbf{F_{\omega}} \tag{3.2}

∣ det ⁡ B ω ∣ = ∣ λ 1 λ 2 ⋯ λ n ∣ \left|\operatorname{det} \mathbf{B}_{\omega}\right|=\left|\lambda_{1} \lambda_{2} \cdots \lambda_{n}\right|

∣ λ i ∣ ≤ ∣ ρ ( B ω ) ∣ \left|\lambda_{i}\right| \leq\left|\rho\left(\mathbf{B}_{\omega}\right)\right|

∣ det ⁡ B ω ∣ = ∣ λ 1 λ 2 ⋯ λ n ∣ ≤ [ ρ ( B ω ) ] n < 1 \left|\operatorname{det} \mathbf{B}_{\omega}\right|=\left|\lambda_{1} \lambda_{2} \cdots \lambda_{n}\right| \leq\left[\rho\left(\mathbf{B}_{\omega}\right)\right]^{n}<1

B ω = ( D − ω L ) − 1 [ ( 1 − ω ) D + ω U ] \mathbf{B}_{\omega}=(\mathbf{D}-\omega \mathbf{L})^{-1}[(1-\omega) \mathbf{D}+\omega \mathbf{U}]

∣ det ⁡ B ω ∣ = ∣ det ⁡ ( D − ω L ) − 1 ∣ ⋅ ∣ det ⁡ [ ( 1 − ω ) D + ω U ] \left|\operatorname{det} \mathbf{B}_{\omega}\right|=\left|\operatorname{det}(\mathbf{D}-\omega \mathbf{L})^{-1}\right| \cdot | \operatorname{det}[(1-\omega) \mathbf{D}+\omega \mathbf{U}]

∣ det ⁡ B ω ∣ = ∣ det ⁡ [ ( 1 − ω ) D + ω U ] ∣ ∣ det ⁡ ( D − ω L ) ∣ = ∣ 1 − ω ∣ n \left|\operatorname{det} \mathbf{B}_{\omega}\right|=\frac{|\operatorname{det}[(1-\omega) \mathbf{D}+\omega \mathbf{U}]|}{|\operatorname{det}(\mathbf{D}-\omega \mathbf{L})|}=|1-\omega|^{n}

## 4 实例分析

A = [ 12 − 2 1 − 2 12 − 2 1 1 − 2 12 − 2 1 ⋱ ⋱ ⋱ ⋱ ⋱ 1 − 2 12 − 2 1 1 − 2 12 − 2 1 − 2 12 ] [ x 1 x 2 x 3 ⋮ x 18 x 19 x 20 ] = [ 5 5 5 ⋮ 5 5 5 ] (4.1) \mathbf{A}=\left[\begin{array}{ccccccc} 12 & -2 & 1 & & & & \\ -2 & 12 & -2 & 1 & & & \\ 1 & -2 & 12 & -2 & 1 & & \\ & \ddots & \ddots & \ddots & \ddots & \ddots & \\ & & 1 & -2 & 12 & -2 & 1 \\ & & & 1 & -2 & 12 & -2 \\ & & & & 1 & -2 & 12 \end{array}\right]\left[\begin{array}{c} x_{1} \\ x_{2} \\ x_{3} \\ \vdots \\ x_{18} \\ x_{19} \\ x_{20} \end{array}\right]=\left[\begin{array}{c} 5 \\ 5 \\ 5 \\ \vdots \\ 5 \\ 5 \\ 5 \end{array}\right]\tag{4.1}

w

0.3
120
0.6
50
0.9
25
1.2
30
1.5
50
1.8
150

.

### 小结

1. 在SOR迭代算法中，松弛因子 ω \omega 越接近1时，迭代的次数越小，收敛速度越快，故 ω \omega 最优值应选择 ω = 1 \omega=1
2. 在SOR迭代算法中，松弛因子 ω \omega 距离1越远时，迭代次数越多，收敛速度越慢。
3. 在SOR迭代算法中，松弛因子应选择 0 < ω < 2 0<\omega<2 ，当 ω \omega 超过这个范围时，不满足收敛定理，即谱半径不小于1，此时方程无解。

## 5 代码实现

close all;clear;clc;%清空环境变量
b=5*ones(20,1);%导入矩阵b
D=diag(diag(A));%求解对角阵
LA=tril(A);%抽取下三角矩阵
U=LA-A;%得到去除对角线元素的上三角阵
L=D-LA;%得到去除对角线元素的下三角阵
XXX=[];%存储不同松弛因子的迭代值
I=[];%记录迭代终止次数
for w=0.3:0.3:2;%设置松弛因子大小0<w<2
XX=[];
%% SOR迭代公式
M=(D-w*L)\((1-w)*D+w*U);
f=w*((D-w*L)\b);
MaxEigM = max(abs(eig(M)));%求谱半径
x=[];
x(:,1)=5.*randn(size(b));%给出任意的迭代初始值
N=500;%最大迭代次数
%% 如果谱半径小于1则说明收敛，否则不收敛
if MaxEigM<1
i=1;
while i<N
if norm(A*x(:,i)-b)>=1e-10;
x(:,i+1)=M*x(:,i)+f;
z=x(:,i+1);
i=i+1;
else
n=i;
z=x(:,i);
i=N;
end
end
XX=[XX,x];
I=[I length(XX)];
XXX=[XXX XX];
e=norm(A*z-b);
else
out='谱半径大于等于1，该方程不能用SOR方法求解'
end
end
%% 绘图
subplot(2,3,1)
plot(1:I(1,1),XXX(:,1:I(1,1)),'linewidth',1.5)
grid on
title('\omega = 0.3')
subplot(2,3,2)
plot(1:I(1,2),XXX(:,1:I(1,2)),'linewidth',1.5)
grid on
title('\omega = 0.6')
subplot(2,3,3)
plot(1:I(1,3),XXX(:,1:I(1,3)),'linewidth',1.5)
grid on
title('\omega = 0.9')
subplot(2,3,4)
plot(1:I(1,4),XXX(:,1:I(1,4)),'linewidth',1.5)
grid on
title('\omega = 1.2')
subplot(2,3,5)
plot(1:I(1,5),XXX(:,1:I(1,5)),'linewidth',1.5)
grid on
title('\omega = 1.5')
subplot(2,3,6)
plot(1:I(1,6),XXX(:,1:I(1,6)),'linewidth',1.5)
grid on
title('\omega = 1.8')
suptitle('不同\omega值对SOR迭代法的影响')


## 6 参考文献与链接

[1] 数值分析 曾繁慧
[2] 科学计算与应用软件讲义_迭代思想 胡行华
[3] https://mdnice.com/
[4] Markdown Nice插件下载
[5] Markdown三线表制作方法

Markdown真香，更多内容请关注公众号获取

• 16
点赞
• 150
收藏
觉得还不错? 一键收藏
• 打赏
• 5
评论
05-12
03-19
03-26 4068
03-29 173
07-25 3012
09-05

### “相关推荐”对你有帮助么？

• 非常没帮助
• 没帮助
• 一般
• 有帮助
• 非常有帮助

¥1 ¥2 ¥4 ¥6 ¥10 ¥20

1.余额是钱包充值的虚拟货币，按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载，可以购买VIP、付费专栏及课程。