设三对角矩阵 A {A} A ,如果存在Doolittle分解,则有
A = [ a 1 c 1 b 2 a 2 c 2 ⋱ ⋱ ⋱ b n − 1 a n − 1 c n − 1 b n a n ] A= \begin{bmatrix} a_1 & c_1 & & & \\ b_2 & a_2 & c_2 & & \\ & \ddots & \ddots & \ddots & \\ & & b_{n-1} & a_{n-1} & c_{n-1} \\ & & & b_n & a_n \end{bmatrix} A= a1b2c1a2⋱c2⋱bn−1⋱an−1bncn−1an
L U = A = [ 1 p 2 1 p 3 1 ⋱ ⋱ p n 1 ] [ q 1 c 1 q 2 c 2 ⋱ ⋱ q n − 1 c n − 1 q n ] LU=A= \begin{bmatrix} 1 & & & \\ p_2 & 1 & & \\ & p3 & 1& \\ & & \ddots & \ddots \\ &&&p_n&1 \end{bmatrix} \begin{bmatrix} q_1 & c_1 & & & \\ & q_2 & c_2 & & \\ & & \ddots & \ddots & \\ & & & q_{n-1} & c_{n-1} \\ & & & & q_n \end{bmatrix} LU=A= 1p21p31⋱⋱pn1 q1c1q2c2⋱⋱qn−1cn−1qn
步骤:
q 1 = a 1 p i = b i q i − 1 , i = 2 , 3 , ⋯ n , 我自己除以我上面 q i = a i − p i c i − 1 , 我自己减去我左边乘以我上面 \begin{align*} q_1=& a_1 \\ \\ p_i=& \frac{b_i}{q_{i-1}} \,\,,\,\, i=2,3, \cdots n\,\,,\,\, 我自己除以我上面 \\ \\ q_i=& a_i-p_ic_{i-1} \,\,,\,\, 我自己减去我左边乘以我上面 \end{align*} q1=pi=qi=a1qi−1bi,i=2,3,⋯n,我自己除以我上面ai−pici−1,我自己减去我左边乘以我上面
{ L y = b U x = y \begin{cases} Ly=b \\ Ux=y \end{cases} {Ly=bUx=y
y 1 = b 1 y i = b i − p i ⋅ y i − 1 , i = 2 , 3 , ⋯ , n \begin{align*} y_1=&b_1\\ \\ y_i=& b_i-p_i \cdot y_{i-1} \,\,,\,\, i=2,3,\cdots ,n \end{align*} y1=yi=b1bi−pi⋅yi−1,i=2,3,⋯,n
x n = y n q n x i = ( y i − c i ⋅ x i + 1 ) / q i , i = n − 1 , ⋯ , 2 , 1 \begin{align*} x_n=& \frac{y_n}{q_n} \\ \\ x_i=& (y_i-c_i \cdot x_{i+1})/q_i \,\,,\,\, i=n-1,\cdots ,2,1 \end{align*} xn=xi=qnyn(yi−ci⋅xi+1)/qi,i=n−1,⋯,2,1
[!example]-
A = [ 2 2 − 1 1 2 − 1 1 2 − 1 1 2 − 1 1 ] , b = [ 6 7 9 11 1 ] A= \begin{bmatrix} 2 & 2 & & & \\ -1 & 1 & 2 & & \\ & -1 & 1 & 2 & \\ & & -1 & 1 & 2 \\ & & & -1 & 1 \end{bmatrix} \,\,,\,\, b=\begin{bmatrix} 6\\7\\9\\11\\1 \end{bmatrix} A= 2−121−121−121−121 ,b= 679111
解:
[ 2 2 − 1 2 1 − ( − 1 2 ) ⋅ 2 = 2 2 − 1 2 2 2 − 1 2 2 2 − 1 2 2 ] \begin{bmatrix} 2 & 2 & & & \\ - \frac{1}{2} & 1-(- \frac{1}{2})\cdot 2=2 & 2 & & \\ & - \frac{1}{2} & 2 & 2 & \\ & & - \frac{1}{2} & 2 & 2 \\ & & & - \frac{1}{2} & 2 \end{bmatrix} 2−2121−(−21)⋅2=2−2122−2122−2122
写成LU的形式
L = [ 1 − 1 / 2 1 − 1 / 2 1 − 1 / 2 1 − 1 / 2 1 ] , U = [ 2 2 2 2 2 2 2 2 2 ] L= \begin{bmatrix} 1 & & & & \\ -1/2 & 1& & & \\ & -1/2 & 1 & & \\ & & -1/2 & 1 & \\ & & & -1/2 & 1 \end{bmatrix} \,\,,\,\, U= \begin{bmatrix} 2 & 2 & & & \\ & 2 & 2 & & \\ & & 2 & 2 & \\ & & & 2 & 2 \\ & & & & 2 \end{bmatrix} L= 1−1/21−1/21−1/21−1/21 ,U= 222222222
L y = b {Ly=b} Ly=b
[ 1 − 1 / 2 1 − 1 / 2 1 − 1 / 2 1 − 1 / 2 1 ] [ y 1 y 2 y 3 y 4 y 5 ] = [ 6 7 9 11 1 ] → { y 1 = 6 − y 1 / 2 + y 2 = 7 → y 2 = 10 − y 2 / 2 + y 3 = 9 → y 2 = 14 − y 3 / 2 + y 4 = 11 → y 3 = 18 − y 4 / 2 + y 5 = 1 → y 5 = 10 \begin{bmatrix} 1 & & & & \\ -1/2 & 1& & & \\ & -1/2 & 1 & & \\ & & -1/2 & 1 & \\ & & & -1/2 & 1 \end{bmatrix} \begin{bmatrix} y_1\\y_2\\y_3\\y_4\\y_5 \end{bmatrix}= \begin{bmatrix} 6\\7\\9\\11\\1 \end{bmatrix}\to \begin{cases} y_1=6\\ -y_1/2+y_2=7\to y_2=10 \\ -y_2/2+y_3=9\to y_2=14 \\ -y_3/2+y_4=11\to y_3=18\\ -y_4/2+y_5=1\to y_5=10 \end{cases} 1−1/21−1/21−1/21−1/21 y1y2y3y4y5 = 679111 →⎩ ⎨ ⎧y1=6−y1/2+y2=7→y2=10−y2/2+y3=9→y2=14−y3/2+y4=11→y3=18−y4/2+y5=1→y5=10
U x = y {Ux=y} Ux=y
[ 2 2 2 2 2 2 2 2 2 ] [ x 1 x 2 x 3 x 4 x 5 ] = [ 6 10 14 18 10 ] → [ 1 2 3 4 5 ] \begin{bmatrix} 2 & 2 & & & \\ & 2 & 2 & & \\ & & 2 & 2 & \\ & & & 2 & 2 \\ & & & & 2 \end{bmatrix}\begin{bmatrix} x_1\\x_2\\x_3\\x_4\\x_5 \end{bmatrix}= \begin{bmatrix} 6\\10\\14\\18\\10 \end{bmatrix} \to \begin{bmatrix} 1\\2\\3\\4\\5 \end{bmatrix} 222222222 x1x2x3x4x5 = 610141810 → 12345
matlab编程实现
%% 追赶法例子
a = [2 1 1 1 1];
b = [0 -1 -1 -1 -1];
c = [2 2 2 2 0];
B = [6 7 9 11 1];
x = tridiagSolver(a,b,c,B,5)
A = diag(a)+diag(repmat([-1],1,4), -1)+ diag(repmat([2],1,4),1)
A*x'
%% 追赶法解三对角线性方程组 傻逼版
% 输入主对角元素向量,下次对角元素向量,上次对角元素向量,方程右边的向量,阶数
function x = tridiagSolver(a,b,c,B,n)
q(1) = a(1)
for i = 2:n
p(i) = b(i)/q(i-1)
q(i) = a(i)-p(i)*c(i-1)
end
y(1) = B(1)
for i = 2:n
y(i) = B(i)-p(i)*y(i-1)
end
x(n) = y(n)/q(n)
for i = n-1:-1:1
x(i)=(y(i)-c(i)*x(i+1))/q(i)
end
end