设矩阵 A = ( a i j ) n × n \ A=(a_{ij})_{n \times n} A=(aij)n×n的各阶顺序主子式不为零,A有分解式
[ a 11 a 12 ⋯ a 1 n a 21 a 22 ⋯ a 2 n ⋮ ⋮ ⋮ a n 1 a n 2 ⋯ a n n ] = [ 1 l 21 1 ⋮ ⋮ ⋱ l n 1 l n 2 ⋯ 1 ] [ u 11 u 12 ⋯ u 1 n u 22 ⋯ u 2 n ⋱ ⋮ u n n ] ≡ L U \ \begin{bmatrix} a_{11} \quad a_{12} \quad \cdots \quad a_{1n} \\ a_{21} \quad a_{22} \quad \cdots \quad a_{2n} \\ \vdots \qquad \vdots \qquad \qquad \vdots \\ a_{n1} \quad a_{n2} \quad \cdots \quad a_{nn} \\ \end{bmatrix} = \begin{bmatrix} 1 \qquad \qquad \qquad \\ l_{21} \quad 1 \qquad \qquad \\ \vdots \quad \vdots \quad \ddots \quad \\ l_{n1} \quad l_{n2} \quad \cdots \quad 1 \\ \end{bmatrix} \begin{bmatrix} u_{11} \quad u_{12} \quad \cdots \quad u_{1n} \\ \qquad u_{22} \quad \cdots \quad u_{2n} \\ \qquad \qquad \ddots \qquad \vdots \\ \qquad \qquad \qquad u_{nn} \end{bmatrix} \equiv LU ⎣⎢⎢⎢⎡a11a12⋯a1na21a22⋯a2n⋮⋮⋮an1an2⋯ann⎦⎥⎥⎥⎤=⎣⎢⎢⎢⎡1l211⋮⋮⋱ln1ln2⋯1⎦⎥⎥⎥⎤⎣⎢⎢⎢⎡u11u12⋯u1nu22⋯u2n⋱⋮unn⎦⎥⎥⎥⎤≡LU
可得出关系
a r i = ∑ k = 1 r l r k u k i ( i = r , ⋯ , n ; r = 1 , 2 , ⋯ , n ) \ a_{ri}= \sum_{k=1}^r l_{rk}u_{ki} (i=r,\cdots,n;r=1,2,\cdots,n) ari=k=1∑rlrkuki(i=r,⋯,n;r=1,2,⋯,n)
a i r = ∑ k = 1 r l i k u k r ( i = r + 1 , ⋯ , n ; r = 1 , ⋯ , n − 1 ) \ a_{ir} = \sum_{k=1}^r l_{ik}u_{kr} (i=r+1,\cdots,n;r=1,\cdots,n-1) air=k=1∑rlikukr(i=r+1,⋯,n;r=1,⋯,n−1)
由这两个关系可以解出L和U:
当r=1时,
u 1 i = a 1 i ( i = 1 , 2 , ⋯ , n ) \ u_{1i}=a_{1i} \quad (i=1,2,\cdots,n) u1i=a1i(i=1,2,⋯,n)
l i 1 = a i 1 u 11 ( i = 2 , 3 , ⋯ , n ) \ l_{i1}=\frac{a_{i1}}{u_{11}} \quad (i=2,3,\cdots,n) li1=u11ai1(i=2,3,⋯,n)
假设求出了U的第1至r-1行,L的1至r-1列,由上面两式得出U,L的第r行,列的计算公式
u r i = a r i − ∑ k = 1 r − 1 l i k u k r ( i = r , ⋯ , n ; r = 1 , 2 , ⋯ , n ) \ u_{ri}=a_{ri}-\sum_{k=1}^{r-1}l_{ik}u_{kr} \quad (i=r,\cdots,n;r=1,2,\cdots,n) uri=ari−k=1∑r−1likukr(i=r,⋯,n;r=1,2,⋯,n)
l i r = a i r − ∑ k = 1 r − 1 l i k u k r u r r ( i = r + 1 , ⋯ , n ; r = 1 , 2 , ⋯ , n − 1 ) \ l_{ir}=\frac{a_{ir}-\sum_{k=1}^{r-1}l_{ik}u_{kr}}{u_{rr}} \quad (i=r+1,\cdots,n;r=1,2,\cdots,n-1) lir=urrair−∑k=1r−1likukr(i=r+1,⋯,n;r=1,2,⋯,n−1)
规 定 ∑ k = 1 0 l i k u k r = 0 \ 规定\sum_{k=1}^0 l_{ik}u_{kr}=0 规定k=1∑0likukr=0
称上面所表示的矩阵分解为Doolittle分解,也称LU分解
在Doolittle的第r步分解,首先在数组A的第r列主对角元以下(含主对角元)选主元,具体步骤为:
(1) 在 r = 1 , 2 , ⋯ , n − 1 \ 在r=1,2,\cdots,n-1 在r=1,2,⋯,n−1时
A ( i , r ) = A ( i , r ) − ∑ k = 1 r − 1 A ( i , k ) ⋅ A ( k , r ) ( i = r , ⋯ , n ) \ A(i,r)=A(i,r)-\sum_{k=1}^{r-1}A(i,k) \cdot A(k,r) \quad (i=r,\cdots,n) A(i,r)=A(i,r)−k=1∑r−1A(i,k)⋅A(k,r)(i=r,⋯,n)
(2)挑选绝对值最大的主元,得出对应的行号idx,将第r行的元素与第idx行的元素进行交换
(3)分解计算
A ( i , r ) = A ( i , r ) A ( r , r ) ( i = r + 1 , ⋯ , n ; r = 1 , 2 , ⋯ , n − 1 ) \ A(i,r)=\frac{A(i,r)}{A(r,r)} \quad (i=r+1,\cdots,n;r=1,2,\cdots,n-1) A(i,r)=A(r,r)A(i,r)(i=r+1,⋯,n;r=1,2,⋯,n−1)
当 r ≠ n \ r \neq n r=n时
A ( r , i ) = A ( r , i ) − ∑ k = 1 r − 1 A ( r , k ) ⋅ A ( k , i ) ( i = r + 1 , ⋯ , n ; r = 1 , 2 , ⋯ , n ) \ A(r,i)=A(r,i)-\sum_{k=1}^{r-1}A(r,k) \cdot A(k,i) \quad (i=r+1,\cdots,n;r=1,2,\cdots,n) A(r,i)=A(r,i)−k=1∑r−1A(r,k)⋅A(k,i)(i=r+1,⋯,n;r=1,2,⋯,n)
( ∑ k = 1 0 A ( r , k ) ⋅ A ( k , i ) = 0 ) \ (\sum_{k=1}^0 A(r,k)\cdot A(k,i)=0) (k=1∑0A(r,k)⋅A(k,i)=0)
当 r = n \ r=n r=n时
A ( r , r ) = A ( r , r ) − ∑ k = 1 r − 1 A ( r , k ) ⋅ A ( k , r ) \ A(r,r)=A(r,r)-\sum_{k=1}^{r-1}A(r,k)\cdot A(k,r) A(r,r)=A(r,r)−k=1∑r−1A(r,k)⋅A(k,r)
按上述方法完成n步分解,便实现了系数矩阵分解 P A = L U \ PA=LU PA=LU,其中, P \ P P是排列矩阵
P = I i n − 1 n − 1 I i n − 2 n − 2 ⋯ I i 1 1 \ P=I_{i_{n-1}n-1}I_{i_{n-2}n-2} \cdots I_{i_11} P=Iin−1n−1Iin−2n−2⋯Ii11
其中, I i k k \ I_{i_kk} Iikk是单位矩阵在第k步分解中交换了第k行和第 i k \ i_k ik行(主元中最大绝对值的行数)后的矩阵
function [L, U, P] = Doolittle(A, pri)
%DOOLITTLE 对矩阵A进行doolittle分解
% inputs:要分解的矩阵A, pri:是否选主元
% outputs:单位下三角矩阵L和上三角矩阵U,若选主元,同时输出置换矩阵P
P = eye(size(A));
[row, col] = size(A);
if pri
for r = 1:row
% 计算中间量Si,存入A(i,r)
if r ~= row
A(r:end, r) = A(r:end, r) - A(r:end, 1:r-1) * A(1:r-1, r);
end
% 确定绝对值最大的行号
[m, idx] = max(abs(A(r:end, r)));
idx = idx + r - 1;
% 换行,同时更新排列矩阵P
I = eye(row, col);
temp = I(r, :);
I(r, :) = I(idx, :);
I(idx, :) = temp;
A = I * A;
P = I * P;
% 分解计算
if r ~= row
A(r+1:end, r) = A(r+1:end, r) / A(r, r);
end
if r ~= 1
if r ~= row
A(r, r+1:end) = A(r, r+1:end) - A(r, 1:r-1) * A(1:r-1, r+1:end);
else
A(r, r:end) = A(r, r:end) - A(r, 1:r-1) * A(1:r-1, r:end);
end
end
end
L = tril(A, -1) + eye(size(A));
U = triu(A, 0);
else
U = zeros(size(A));
L = eye(size(A));
for r = 1:row
if r == 1
U(1, :) = A(1, :);
L(2:end, 1) = A(2:end, 1) ./ U(1, 1);
else
U(r, r:end) = A(r, r:end) - L(r, 1:r-1) * U(1:r-1, r:end);
L(r+1:end, r) = (A(r+1:end, r) - L(r+1:end, 1:r-1) * U(1:r-1, r)) / U(r, r);
end
end
end
end