Na10f ch06
Na10f ch06
Department of Mathematics
National TsingHua University
Fall 2010
1
These slides are based on Prof. Tsung-Ming Huang(NTNU)’s original slides
Wei-Cheng Wang (NTHU) Direct methods for LS Fall 2010 1 / 81
Outline
2 Pivoting Strategies
3 Matrix factorization
Example
E1 : x1 + x2 + 3x4 = 4,
E2 : 2x1 + x2 − x3 + x4 = 1,
E3 : 3x1 − x2 − x3 + 2x4 = −3,
E4 : −x1 + 2x2 + 3x3 − x4 = 4.
E1 : x1 + x2 + 3x4 = 4,
E2 : − x2 − x3 − 5x4 = −7,
E3 : − 4x2 − x3 − 7x4 = −15,
E4 : 3x2 + 3x3 + 2x4 = 8.
E1 : x1 + x2 + 3x4 = 4,
E2 : − x2 − x3 − 5x4 = −7,
E3 : 3x3 + 13x4 = 13,
E4 : − 13x4 = −13.
4 E1 gives
x1 = 4 − 3x4 − x2 = 4 − 3 − 2 = −1.
0 3 3 2 8
(E3 − 4E2 ) → (E3 ) and (E4 + 3E2 ) → (E4 ):
1 1 0 3 4
0 −1 −1 −5 −7
.
0 0 3 13 13
0 0 0 −13 −13
Wei-Cheng Wang (NTHU) Direct methods for LS Fall 2010 7 / 81
The general Gaussian elimination procedure
Provided a11 6= 0, for each i = 2, 3, . . . , n,
ai1
Ei − E1 → (Ei ).
a11
Transform all the entries in the first column below the diagonal are
zero. Denote the new entry in the ith row and jth column by aij .
For i = 2, 3 . . . , n − 1, provided aii 6= 0,
aji
Ej − Ei → (Ej ), ∀ j = i + 1, i + 2, . . . , n.
aii
Transform all the entries in the ith column below the diagonal are
zero.
Result an upper triangular matrix:
a11 a12 · · · a1n b1
0 a22 · · · a2n b2
.. .
.. .. .. ..
. . . . .
0 ··· 0 ann bn
Wei-Cheng Wang (NTHU) Direct methods for LS Fall 2010 8 / 81
The process of Gaussian elimination result in a sequence of matrices as
follows:
For i = n, . . . , 1
tmp = 0
For j = i + 1, . . . , n
tmp = tmp + U (i, j) ∗ x(j)
End for
x(i) = (b(i) − tmp)/U (i, i)
End for
Solution:
1st step Use 6 as pivot element, the first row as pivot row, and
multipliers 2, 12 , −1 are produced to reduce the system to
6 −2 2 4 x1 12
0 −4 2 2 x2 10
=
0 −12 8 1 x3 21
0 2 3 −14 x4 −26
3rd step Use 2 as pivot element, the third row as pivot row, and
multipliers 2 is found to reduce the system to
6 −2 2 4 x1 12
0 −4 2 2
x2 = 10
0 0 2 −5 x3 −9
0 0 0 −3 x4 −3
(k)
This example is done since akk 6= 0 for all k = 1, 2, 3, 4.
(k)
How to do if akk = 0 for some k?
Solution:
1st step Use 1 as pivot element, the first row as pivot row, and
multipliers 2, 1, 1 are produced to reduce the system to
1 −1 2 −1 x1 −8
0
0 −1 −1 x2 = −4
0 2 −1 1 x3 6
0 0 2 4 x4 12
3rd step Use −1 as pivot element, the third row as pivot row, and
multipliers −2 is found to reduce the system to
1 −1 2 −1 x1 −8
0
2 −1 1
x2 = 6
0 0 −1 −1 x3 −4
0 0 0 2 x4 4
(k)
This example illustrates what is done if akk = 0 for some k.
(k)
If apk 6= 0 for some p with k + 1 ≤ p ≤ n, then the operation
(Ek ) ↔ (Ep ) is performed to obtain new matrix.
(k)
If apk = 0 for each p, then the linear system does not have a unique
solution and the procedure stops.
For k = 1, . . . , n − 1
Let p be the smallest integer with k ≤ p ≤ n and apk 6= 0.
If @ p, then stop.
If p 6= k, then perform (Ep ) ↔ (Ek ).
For i = k + 1, . . . , n
t = A(i, k)/A(k, k)
A(i, k) = 0
b(i) = b(i) − t × b(k)
For j = k + 1, . . . , n
A(i, j) = A(i, j) − t × A(k, j)
End for
End for
End for
Wei-Cheng Wang (NTHU) Direct methods for LS Fall 2010 19 / 81
Number of floating-point arithmetic operations
Multiplications/divisions
(n − k) + (n − k) + (n − k)(n − k) = (n − k)(n − k + 2)
Additions/subtractions
(n − k) + (n − k)(n − k) = (n − k)(n − k + 1)
Multiplications/divisions
n−1
X n2 + n
1+ [(n − i) + 1] =
2
i=1
Additions/subtractions
n−1
X n2 − n
[(n − i − 1) + 1] =
2
i=1
Wei-Cheng Wang (NTHU) Direct methods for LS Fall 2010 22 / 81
The total number of arithmetic operations in Gaussian elimination with
backward substitution is:
Multiplications/divisions
2n3 + 3n2 − 5n n2 + n n3 n n3
+ = + n2 − ≈
6 2 3 3 3
Additions/subtractions
n3 − n n2 − n n3 n2 5n n3
+ = + − ≈
3 2 3 2 6 3
(k)
ajk
|mjk | = (k)
> 1.
akk
(k) (k)
|apk | = max |aik |
k≤i≤n
is the same as that in previous example except that all the entries in the
first equation have been multiplied by 104 .
|api | |aki |
= max
sp i≤k≤n sk
Ly = b, U x = y.
and
1 ··· 0 0 ··· 0
.. . . .. .. ..
. . . . .
0 ··· 1 0 ··· 0
Mk = I − `k eTk =
.
0 ··· −`k+1,k 1 · · · 0
.. .. .. . . ..
. . . . .
0 ··· −`n,k 0 · · · 1
where
(2) (1) (1)
aij = aij − `i1 × a1j , for i = 2, . . . , n and j = 2, . . . , n.
(k)
If the pivot akk 6= 0, then the multipliers
(k)
aik
`ik = (k)
, i = k + 1, . . . , n,
akk
A(k+1) = Mk A(k)
(1) (1) (1) (1) (1) (1)
a11 a12 · · · a1,k−1 a1k a1,k+1 ··· a1n
(2) (2) (2) (2) (2)
0 a22 · · · a2,k−1 a2k a2,k+1 ··· a2n
. .. .. .. .. ..
..
.
. . . . . . .
(k−1) (k−1) (k−1) (k−1)
0 0 · · · ak−1,k−1 ak−1,k ak−1,k+1 ··· ak−1,n
= ,
(k) (k) (k)
0 0 ··· 0 akk ak,k+1 ··· akn
.. .. ..
(k+1) (k+1)
···
. . . 0 ak+1,k+1 ak+1,n
.. .. .. .. .. ..
. . . . . .
(k+1) (k+1)
0 0 ··· 0 0 an,k+1 ··· ann
U ≡ A(n) = Mn−1 · · · M2 M1 A
For k = 1, . . . , n − 1
For i = k + 1, . . . , n
A(i, k) = A(i, k)/A(k, k)
For j = k + 1, . . . , n
A(i, j) = A(i, j) − A(i, k) × A(k, j)
End for
End for
End for
x1 = b1 /`11 ,
x2 = (b2 − `21 x1 )/`22 ,
x3 = (b3 − `31 x1 − `32 x2 )/`33 ,
..
.
xn = (bn − `n1 x1 − `n2 x2 − · · · − `n,n−1 xn−1 )/`nn .
For i = 1, . . . , n
tmp = 0
For j = 1, . . . , i − 1
tmp = tmp + L(i, j) ∗ x(j)
End for
x(i) = (b(i) − tmp)/L(i, i)
End for
E1 : x1 + x2 + 3x4 = 4,
E2 : 2x1 + x2 − x3 + x4 = 1,
E3 : 3x1 − x2 − x3 + 2x4 = −3,
E4 : −x1 + 2x2 + 3x3 − x4 = 4.
Solution:
The sequence {(E2 − 2E1 ) → (E2 ), (E3 − 3E1 ) → (E3 ),
(E4 − (−1)E1 ) → (E4 ), (E3 − 4E2 ) → (E3 ),
(E4 − (−3)E2 ) → (E4 )} converts the system to the triangular system
x1 + x2 + 3x4 = 4,
− x2 − x3 − 5x4 = −7,
3x3 + 13x4 = 13,
− 13x4 = −13.
y1 = 8,
y2 = 7 − 2y1 = −9,
y3 = 14 − 3y1 − 4y2 = 26,
y4 = −7 + y1 + 3y2 = −26.
x4 = 2,
x3 = (26 − 13x4 )/3 = 0,
x2 = (−9 + 5x4 + x3 )/(−1) = −1,
x1 = 8 − 3x4 − x2 = 3.
and
therefore,
⇒ ···
Therefore, L is unit lower triangular.
Wei-Cheng Wang (NTHU) Direct methods for LS Fall 2010 54 / 81
Algorithm (LU -factorization with Partial Pivoting)
Given a nonsingular A ∈ Rn×n , this algorithm finds a permutation P , and
computes a unit lower triangular L and an upper triangular U such that
P A = LU . A is overwritten by L and U , and P is not formed. An integer
array p is instead used for storing the row/column indices.
p(1 : n) = 1 : n
For k = 1, . . . , n − 1
m=k
For i = k + 1, . . . , n
If |A(p(m), k)| < |A(p(i), k)|, then m = i
End For
` = p(k); p(k) = p(m); p(m) = `
For i = k + 1, . . . , n
A(p(i), k) = A(p(i), k)/A(p(k), k)
For j = k + 1, . . . , n
A(p(i), j) = A(p(i), j) − A(p(i), k)A(p(k), j)
End For
End For
End For
Wei-Cheng Wang (NTHU) Direct methods for LS Fall 2010 55 / 81
Since the Gaussian elimination with partial pivoting produces the
factorization (4), the linear system problem should comply accordingly
Ax = b =⇒ P Ax = P b =⇒ LU x = P b.
Example
Find an LU factorization of
0 1 −1 1
1 1 −1 2
A=
−1 −1
.
1 0
1 2 0 2
So
0 1 0 0 1 1 −1 2
1 0 0 0 0 1 −1 1
A = P −1 LU = (P T L)U =
.
−1 0 0 1 0 0 2 −1
1 1 1 0 0 0 0 2
Definition
A matrix A ∈ Rn×n is said to be strictly diagonally dominant if
n
X
|aii | > |aij |.
j=1,j6=i
Lemma
If A ∈ Rn×n is strictly diagonally dominant, then A is nonsingular.
|xi |
|xk | = max |xi | =⇒ ≤ 1, ∀ |xi |.
1≤i≤n |xk |
which implies
n n
X |xj | X
|akk | ≤ |akj | ≤ |akj |.
|xk |
j=1,j6=k j=1,j6=k
Definition
A matrix A is positive definite if it is symmetric and xT Ax > 0 ∀ x 6= 0.
Proof:
(a) If x satisfies Ax = 0, then xT Ax = 0. Since A is positive
definite, this implies x = 0. Consequently, Ax = 0 has only
the zero solution, and A is nonsingular.
(b) Since A is positive definite,
Since x 6= 0,
But AT = A, so
so
Theorem
The symmetric matrix A is positive definite if and only if Gaussian
elimination without row interchanges can be performed on Ax = b with all
pivot elements positive.
Corollary
The matrix A is positive definite if and only if A can be factored in the
form LDLT , where L is lower triangular with 1’s on its diagonal and D is
a diagonal matrix with positive diagonal entries.
A = L1 U1 and A = L2 U2
A = L1 U1 = L2 U2 =⇒ L−1 −1
2 L1 = U2 U1 .
L−1 −1
2 L1 = I = U2 U1
zkT Ak zk = xT Ax > 0,
A = GGT , (7)
Proof: “⇒”
A is positive definite
⇒ all leading principal submatrices of A are nonsingular
⇒ A has the LU factorization A = LU , where L is unit lower triangular
and U is upper triangular.
Since A is symmetric,
LU = A = AT = U T LT =⇒ U (LT )−1 = L−1 U T .
U (LT )−1 is upper triangular and L−1 U T is lower triangular
⇒ U (LT )−1 to be a diagonal matrix, say, U (LT )−1 = D.
⇒ U = DLT . Hence
A = LDLT .
Wei-Cheng Wang (NTHU) Direct methods for LS Fall 2010 74 / 81
Since A is positive definite,
This means D is also positive definite, and hence dii > 0. Thus D1/2 is
well-defined and we have
GT x 6= 0, ∀ x 6= 0.
Hence
Moreover,
k
X
aik = gij gkj , i = k + 1, . . . , n,
j=1
aij = 0 whenever p ≤ j − i or q ≤ i − j.
and the entries are computed by the simple algorithm which only costs 3n
flops.
Wei-Cheng Wang (NTHU) Direct methods for LS Fall 2010 80 / 81
Algorithm (Tridiagonal LU Factorization)
This algorithm computes the LU factorization for a tridiagonal matrix
without using pivoting strategy.
U (1, 1) = A(1, 1)
For i = 2, . . . , n
U (i − 1, i) = A(i − 1, i)
L(i, i − 1) = A(i, i − 1)/U (i − 1, i − 1)
U (i, i) = A(i, i) − L(i, i − 1)U (i − 1, i)
End For