Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
9. QR factorization
9-1
Least-squares methods
minimize kAx bk2
(A is m n and left-invertible)
normal equations
AT Ax = AT b
QR factorization
9-2
QR factorization
9-3
Example
1
b= 7
2
3 6
A = 4 8 ,
0
1
1. AT A =
25 50
50 101
and AT b =
2. Cholesky factorization: AT A =
3. solve
4. solve
QR factorization
5 0
10 1
5 10
0
1
z1
z2
x1
x2
25
48
5 0
10 1
25
48
5
2
5 10
0
1
: solution is z1 = 5, z2 = 2
: solution is x1 = 5, x2 = 2
9-4
QR factorization
if A is m n and left-invertible then it can be factored as
A = QR
R is n n and upper triangular with rii > 0
Q is m n and orthogonal (QT Q = I)
QR factorization
9-5
(QT Q = I)
(R nonsingular)
algorithm
1. QR factorization of A: A = QR (2mn2 flops)
2. form d = QT b (2mn flops)
3. solve Rx = d by back substitution (n2 flops)
cost for large m, n: 2mn2 flops
QR factorization
9-6
Example
3 6
A = 4 8 ,
0
1
1
b= 7
2
1. QR factorization: A = QR with
3/5 0
Q = 4/5 0 ,
0 1
2. calculate d = QT b =
3. solve
QR factorization
5 10
0
1
5
2
x1
x2
R=
5 10
0
1
=
5
2
: solution is x1 = 5, x2 = 2
9-7
a 1 A2
q1 Q2
r11 R12
0 R22
q1T
QT2
q1 Q2
"
q1T q1
QT2 q1
q1T Q2
QT2 Q2
1 0
0 I
i.e.,
q1T q1 = 1,
QR factorization
QT2 Q2 = I,
q1T Q2 = 0
9-8
r11 = ka1k,
q1 = (1/r11)a1
9-9
9-10
Example
we want to factor A as
A=
a1 a2 a3
=
=
with
9
0 26
12
0 7
A=
0
4
4
0 3 3
q1 q2 q3
q1T q1 = 1,
q1T q2 = 0,
q2T q2 = 1,
q1T q3 = 0,
q3T q3 = 1
q2T q3 = 0
9-11
3/5
4/5
q1 = (1/r11)a1 =
0
0
3/5
9
0 26
4/5
12
0 7
=
A=
0
0
4
4
0 3 3
0
QR factorization
q12
q22
q32
q42
q13
15
0 10
q23
0 r22 r23
q33
0
0 r33
q43
9-12
3/5
0 26
0 7 4/5
r22 r23
0 10 = q2 q3
4
0
0 r33
4
0
3 3
0
20
0 15
r22 = 5,
QR factorization
0
0
q2 =
4/5
3/5
9-13
20
T
T 15
=
q
q2
(q2r23 + q3r33) = r23
2
4
3
therefore, r23 = 5
QR factorization so far:
9
0 26
3/5
0
12
4/5
0 7
0
A=
=
0
4
4 0
4/5
0 3 3
0 3/5
QR factorization
q13
15 0 10
q23
0 5
5
q33
0 0 r33
q43
9-14
3/5
0
26
7 4/5
0 10
= q3r33
4 0
5
4/5
0 3/5
3
20
15
= q3r33
0
0
with kq3k = 1, hence
r33 = 25,
QR factorization
4/5
3/5
q3 =
0
0
9-15
in summary,
9
0 26
3/5
0
4/5
15 0 10
12
0 7
0
3/5
4/5
0 5 5
A=
=
4
4
0
4/5
0
0 0 25
0 3 3
0 3/5
0
= QR
QR factorization
9-16
0
b = 105
1
1 1
A = 0 105 ,
0
0
solution
normal equations AT Ax = AT b:
1
1
1 1 + 1010
x1
x2
0
1010
solution: x1 = 1, x2 = 1
let us compare both methods, rounding intermediate results to 8
significant decimal digits
QR factorization
9-17
1 1
1
1
AT b =
0
1010
1 0
Q = 0 1 ,
0 0
R=
1 1
0 105
QT b =
0
105
9-18
Summary
cost for dense A
method 1 (Cholesky factorization): mn2 + (1/3)n3 flops
method 2 (QR factorization): 2mn2 flops
method 1 is always faster (twice as fast if m n)
cost for large sparse A
method 1: we can form AT A fast, and use a sparse Cholesky
factorization (cost mn2 + (1/3)n3)
method 2: exploiting sparsity in QR factorization is more difficult
numerical stability: method 2 is more accurate
in practice: method 2 is preferred; method 1 is often used when A is very
large and sparse
QR factorization
9-19