Chap 03
Chap 03
Scientific Computing
An Introductory Survey
Second Edition
by Michael T. Heath
Chapter 3
Copyright
c 2001. Reproduction permitted only for
noncommercial, educational use in conjunction with the
book.
1
Method of Least Squares
2
Linear Least Squares
min kr k2 2
2 = min kb − Axk2
x x
3
Example: Data Fitting
∼ b, with a =
Written in matrix form as Ax = ij
φj (ti) and bi = yi
4
Example: Data Fitting
Polynomial fitting,
5
Example: Data Fitting
6
Example: Data Fitting
For data
2 •.
...
....
..
.
.....
.
.
.... ..
.....
.
•........ 1 .
......
..... ....
..... ...
.
...... ..
...... •
....... ..
........•
.
.........
............ ..
..
..
..
.........
..............................................
•
−1 0 1
8
Existence and Uniqueness
∼ b always
Linear least squares problem Ax =
has solution
9
Normal Equations
kr k2 T
2=r r
of residual vector
r = b − Ax
To minimize
kr k2
2 = r T r = (b − Ax)T (b − Ax)
= bT b − 2xT AT b + xT AT Ax,
take derivative with respect to x and set to o,
2AT Ax − 2AT b = o,
which reduces to n × n linear system
AT Ax = AT b
known as system of normal equations
10
Orthogonality
Thus,
o = AT r = AT (b − Ax),
or
AT Ax = AT b
11
Orthogonality, continued
..
.. ...........
.
.. ..... ..
.
. .
....... . r = b − Ax
b ..... . ..
. .
... . ..................... ...
................ . ..
.................................................................................................................
.
.
.......
..
....... ..
. .......
. . .
..
..... ......
.
..
.
. ..
.....
. . .
....... ............. ..
.......
....
. . .
.....θ .... .. .....
..
.. . ... . .
.
..... ...
.
....... ............................................................................................... .. .......
. .
....... y = Ax .
.....
.
. .
....... .
.....
.
. .
....... ..
.....
.... span(A) ....
......................................................................................................................................................................
12
Orthogonal Projectors
v = (P + ( I − P )) v = P v + P⊥ v
∼ b, if rank(A) =
For least squares problem Ax =
n, then
P = A(AT A)−1AT
is orthogonal projector onto span(A), and
b = P b + P⊥b = Ax + (b − Ax) = y + r
13
Pseudoinverse and Condition Number
A+ = (AT A)−1AT
and
cond(A) = kAk2 · kA+k2
∼ b is given by
Least squares solution of Ax =
x = A+ b
14
Sensitivity and Conditioning
∼b
Sensitivity of least squares solution to Ax =
depends on b as well as A
15
Sensitivity and Conditioning, cont.
16
Normal Equations Method
AT A = LLT ,
can be used to obtain solution x to system of
normal equations
AT Ax = AT b,
which has same solution as linear least squares
problem Ax =∼b
17
Example: Normal Equations Method
AT A =
−1.0 −0.5 0.0 0.5 1.0
AT b =
1.0
1 1 1 1 1 0.5
4.0
−1.0 −0.5 0.0 0.5 1.0 0.0 = 1.0
1.0 0.25 0.0 0.25 1.0 0.5
3.25
2.0
18
Example Continued
AT A =
0.0 2.5 0.0 =
0 1.581 0 0 1.581 0
= LLT
19
Example Continued
z=
0.632
1.336
x=
0.400
1.429
20
Shortcomings of Normal Equations
A=
0,
0
√
where is positive number smaller than mach
cond(AT A) = [cond(A)]2
21
Augmented System Method
22
Augmented System Method, continued
23
Orthogonal Transformations
kQv k2
2 = ( Qv ) T Qv = v T QT Qv = v T v = kv k2
2
24
Triangular Least Squares Problems
Residual is
kr k2 2 2
2 = kb1 − Rxk2 + kb2 k2
25
Triangular Least Squares Problems, cont.
kr k2 2
2 = kb2 k2
26
QR Factorization
Then
" # " #
R R
A=Q = [Q1 Q2] = Q1R
O O
is reduced QR factorization of A
∼ b given
Solution to least squares problem Ax =
by solution to square system
QT1 Ax = Rx = c1 = QT1 b
28
QR Factorization
• Householder transformations
• Givens rotations
• Gram-Schmidt orthogonalization
29
Householder Transformations
v = a − αe1
and α = ±kak2, with sign chosen to avoid can-
cellation
30
Example: Householder Transformation
Let a = [ 2 1 2 ]T
By foregoing recipe,
2
1
2
α
v = a − αe1 =
1 − α0 = 1 − 0,
2 0 2 0
where α = ±kak2 = ±3
−3
2
5
Thus, v = 1 − 0 = 1
2 0 2
32
Householder QR Factorization, cont.
If Q = H1 · · · Hn, then
" #
R
A=Q
O
34
Example: Householder QR Factorization
35
Example Continued
36
Example Continued
37
Example Continued
−1.789
0.632
H2H1b = −1.035
−0.816
0.404
38
Example Continued
39
Givens Rotations
40
Givens Rotations, continued
q
Finally, c2 + s2 = 1, or α = a2
1 + a 2 , implies
2
a1 a2
c=q , s=q
a2
1 + a 2
2 a2
1 + a 2
2
41
Example: Givens Rotation
Let a = [ 4 3 ]T
a2 3
s=q = = 0.6
a2 + a 2 5
1 2
Rotation given by
" # " #
c s 0.8 0.6
G= =
−s c −0.6 0.8
42
Givens QR Factorization
0 0 0 0 1 a5 a5
a1 a...2
....... . .
.. ..............
..... ..
..... ....... ..........
..... . ... .....
..... ... ...
..... ... ...
..... ...
.... ...
........ .
. ...
. ........
... q2
.. . .
. .
.
q1 ......... ..... ...
..
... ... .
...
..... .. ......
..... ... .
..... .. .....
..
..... ... .
..
..... .. ....
....... ....
.......... a2 − (q1T a2 )q1
for k = 1 to n
qk = ak
for j = 1 to k − 1
rjk = qjT ak
qk = qk − rjk qj
end
rkk = kqk k2
qk = qk /rkk
end
44
Modified Gram-Schmidt
for k = 1 to n
rkk = kak k2
qk = ak /rkk
for j = k + 1 to n
rkj = qkT aj
aj = aj − rkj qk
end
end
45
Rank Deficiency
46
Example: Near Rank Deficiency
Consider 3 × 2 matrix
0.641 0.242
A=
0.321 0.121
0.962 0.363
Computing QR factorization,
" #
1.1997 0.4527
R=
0 0.0002
48
QR with Column Pivoting, cont.
∼b
Basic solution to least squares problem Ax =
can now be computed by solving triangular sys-
tem Rz = c1, where c1 contains first k com-
ponents of QT b, and then taking
" #
z
x=P
o
49
Singular Value Decomposition
A = U ΣV T ,
where U is m × m orthogonal matrix, V is n × n
orthogonal matrix, and Σ is m × n diagonal
matrix, with
(
0 for i 6= j
σij =
σi ≥ 0 for i = j
50
Example: SVD
SVD of
1 2 3
4 5 6
A =
7 8 9
10 11 12
given by U ΣV T =
.141 .825 −.420 −.351
.344 .426 .298 .782
.547
.0278 .664 −.509
.750 −.371 −.542 .0790
25.5 0 0
.504 .574 .644
0 1.29 0
−.761 −.057 .646
0 0 0
.408 −.816 .408
0 0 0
51
Applications of SVD
∼ b:
Minimum norm solution to Ax =
X uTi b
x= vi
σ 6=0
σi
i
For ill-conditioned or rank deficient problems,
“small” singular values can be dropped from
summation to stabilize solution
cond(A) = σmax/σmin
A+ = V Σ+U T
∼b
In all cases, minimum-norm solution to Ax =
is given by A+ b
53
Orthogonal Bases
54
Lower-Rank Matrix Approximation
56
Comparison of Methods
cond(A) + kr k2 [cond(A)]2,
which is best possible, since this is inherent
sensitivity of solution to least squares problem
cond(A) ≈ 1/mach
or worse
58
Comparison of Methods, continued
59