Jim Lambers MAT 610 Summer Session 2009-10 Lecture 9 Notes

These notes correspond to Section 5.1 in the text.

The QR Factorization

Let A be an m × n with full column . The QR factorization of A is a decomposition A = QR, where Q is an m × m and R is an m × n upper . There are three ways to compute this decomposition:

1. Using Householder matrices, developed by Alston S. Householder

2. Using Givens rotations, also known as Jacobi rotations, used by W. Givens and originally invented by Jacobi for use with in solving the symmetric eigenvalue problem in 1846.

3. A third, less frequently used approach is the Gram-Schmidt orthogonalization.

Givens Rotations We illustrate the process in the case where A is a 2×2 matrix. In , we compute L−1A = U where L−1 is unit lower triangular and U is upper triangular. Specifically, " #  1 0   a a  a(2) a(2) a 11 12 = 11 12 , m = − 21 . m 1 a a (2) 21 a 21 21 22 0 a22 11

By contrast, the QR decomposition computes QT A = R, or

 − T  a a   r r  11 12 = 11 12 ,  a21 a22 0 r22 where 2 + 2 = 1. From the relationship −a11 + a21 = 0 we obtain

a21 = a11 2 2 2 2 2 2 a21 =  a11 = (1 − )a11 which yields a = ± 11 . p 2 2 a21 + a11

1 It is conventional to choose the + sign. Then, we obtain

2 2 2 2 a11 a21  = 1 − = 1 − 2 2 = 2 2 , a21 + a11 a21 + a11 or a  = ± 21 . p 2 2 a21 + a11 Again, we choose the + sign. As a result, we have a a q r = a 11 + a 21 = a2 + a2 . 11 11 p 2 2 21 p 2 2 21 11 a21 + a11 a21 + a11 The matrix  − T Q =  is called a Givens . It is called a rotation because it is orthogonal, and therefore length- preserving, and also because there is an angle  such that sin  =  and cos  = , and its effect is to rotate a vector clockwise through the angle . In particular,

 − T      =  0 where  = p 2 + 2, =  cos  and =  sin . It is easy to verify that the product of two rotations is itself a rotation. Now, in the case where A is an n × n matrix, suppose that we have the vector ⎡ × ⎤ ⎢ . ⎥ ⎢ . ⎥ ⎢ ⎥ ⎢ × ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ × ⎥ ⎢ ⎥ ⎢ . ⎥ ⎢ . ⎥ . ⎢ ⎥ ⎢ × ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ × ⎥ ⎢ ⎥ ⎢ . ⎥ ⎣ . ⎦ ×

2 Then ⎡ 1 ⎤ ⎡ × ⎤ ⎡ × ⎤ ⎢ .. ⎥ ⎢ . ⎥ ⎢ . ⎥ ⎢ . ⎥ ⎢ . ⎥ ⎢ . ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ 1 ⎥ ⎢ × ⎥ ⎢ × ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢  ⎥ ⎢ ⎥ ⎢  ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ 1 ⎥ ⎢ × ⎥ ⎢ × ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ .. ⎥ ⎢ . ⎥ ⎢ . ⎥ ⎢ . ⎥ ⎢ . ⎥ = ⎢ . ⎥ . ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ 1 ⎥ ⎢ × ⎥ ⎢ × ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ − ⎥ ⎢ ⎥ ⎢ 0 ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ 1 ⎥ ⎢ × ⎥ ⎢ × ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ .. ⎥ ⎢ . ⎥ ⎢ . ⎥ ⎣ . ⎦ ⎣ . ⎦ ⎣ . ⎦ 1 × × So, in order to transform A into an upper triangular matrix R, we can find a product of rotations Q such that QT A = R. It is easy to see that O(n2) rotations are required. Each rotation takes O(n) operations, so the entire process of computing the QR factorization requires O(n3) operations. It is important to note that the straightforward approach to computing the entries and  of the ,

= ,  = , p 2 + 2 p + 2 + 2 is not always advisable, because in floating-point arithmetic, the computation of p 2 + 2 could overflow. To get around this problem, suppose that ∣ ∣ ≥ ∣ ∣. Then, we can instead compute 1  = ,  = √ , = , 1 +  2 which is guaranteed not to overflow since the only number that is squared is less than one in magnitude. On the other hand, if ∣ ∣ ≥ ∣ ∣, then we compute 1  = , = √ ,  = . 1 +  2 Now, we describe the entire algorithm for computing the QR factorization using Givens rota- tions. Let [c, s] = givens(a, b) be a Matlab-style function that computes c and s such that

T  c −s   a   r  p = , r = a2 + b2. s c b 0

Then, let G(i, j, c, s)T be the Givens that rotates the ith and jth elements of a vector v clockwise by the angle  such that cos  = c and sin  = s, so that if vi = a√and vj = b, T 2 2 and [c, s] = givens(a, b), then in the updated vector u = G(i, j, c, s) v, ui = r = a + b and uj = 0. The QR factorization of an m × n matrix A is then computed as follows.

3 Q = I R = A for j = 1 : n do for i = m : −1 : j + 1 do [c, s] = givens(ri−1,j, rij) R = G(i, j, c, s)T R Q = QG(i, j, c, s) end end Note that the matrix Q is accumulated by column rotations of the identity matrix, because the matrix by which A is multiplied to reduce A to upper-triangular form, a product of row rotations, is QT . Example We use Givens rotations to compute the QR factorization of ⎡ 0.8147 0.0975 0.1576 ⎤ ⎢ 0.9058 0.2785 0.9706 ⎥ ⎢ ⎥ A = ⎢ 0.1270 0.5469 0.9572 ⎥ . ⎢ ⎥ ⎣ 0.9134 0.9575 0.4854 ⎦ 0.6324 0.9649 0.8003

First, we compute a Givens rotation that, when applied to a41 and a51, zeros a51:  0.8222 −0.5692 T  0.9134   1.1109  = . 0.5692 0.8222 0.6324 0 Applying this rotation to rows 4 and 5 yields ⎡ 1 0 0 0 0 ⎤T ⎡ 0.8147 0.0975 0.1576 ⎤ ⎡ 0.8147 0.0975 0.1576 ⎤ ⎢ 0 1 0 0 0 ⎥ ⎢ 0.9058 0.2785 0.9706 ⎥ ⎢ 0.9058 0.2785 0.9706 ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ 0 0 1 0 0 ⎥ ⎢ 0.1270 0.5469 0.9572 ⎥ = ⎢ 0.1270 0.5469 0.9572 ⎥ . ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎣ 0 0 0 0.8222 −0.5692 ⎦ ⎣ 0.9134 0.9575 0.4854 ⎦ ⎣ 1.1109 1.3365 0.8546 ⎦ 0 0 0 0.5692 0.8222 0.6324 0.9649 0.8003 0 0.2483 0.3817

Next, we compute a Givens rotation that, when applied to a31 and a41, zeros a41:  0.1136 −0.9935 T  0.1270   1.1181  = . 0.9935 0.1136 1.1109 0 Applying this rotation to rows 3 and 4 yields ⎡ 1 0 0 0 0 ⎤T ⎡ 0.8147 0.0975 0.1576 ⎤ ⎡ 0.8147 0.0975 0.1576 ⎤ ⎢ 0 1 0 0 0 ⎥ ⎢ 0.9058 0.2785 0.9706 ⎥ ⎢ 0.9058 0.2785 0.9706 ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ 0 0 0.1136 −0.9935 0 ⎥ ⎢ 0.1270 0.5469 0.9572 ⎥ = ⎢ 1.1181 1.3899 0.9578 ⎥ . ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎣ 0 0 0.9935 0.1136 0 ⎦ ⎣ 1.1109 1.3365 0.8546 ⎦ ⎣ 0 −0.3916 −0.8539 ⎦ 0 0 0 0 1 0 0.2483 0.3817 0 0.2483 0.3817

4 Next, we compute a Givens rotation that, when applied to a21 and a31, zeros a31:

 0.6295 −0.7770 T  0.9058   1.4390  = . 0.7770 0.6295 1.1181 0

Applying this rotation to rows 2 and 3 yields

⎡ 1 0 0 0 0 ⎤T ⎡ 0.8147 0.0975 0.1576 ⎤ ⎡ 0.8147 0.0975 0.1576 ⎤ ⎢ 0 0.6295 −0.7770 0 0 ⎥ ⎢ 0.9058 0.2785 0.9706 ⎥ ⎢ 1.4390 1.2553 1.3552 ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ 0 0.7770 0.6295 0 0 ⎥ ⎢ 1.1181 1.3899 0.9578 ⎥ = ⎢ 0 0.6585 −0.1513 ⎥ . ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎣ 0 0 0 1 0 ⎦ ⎣ 0 −0.3916 −0.8539 ⎦ ⎣ 0 −0.3916 −0.8539 ⎦ 0 0 0 0 1 0 0.2483 0.3817 0 0.2483 0.3817

To complete the first column, we compute a Givens rotation that, when applied to a11 and a21, zeros a21:  0.4927 −0.8702 T  0.8147   1.6536  = . 0.8702 0.4927 1.4390 0 Applying this rotation to rows 1 and 2 yields

⎡ 0.4927 −0.8702 0 0 0 ⎤T ⎡ 0.8147 0.0975 0.1576 ⎤ ⎡ 1.6536 1.1405 1.2569 ⎤ ⎢ 0.8702 0.4927 0 0 0 ⎥ ⎢ 1.4390 1.2553 1.3552 ⎥ ⎢ 0 0.5336 0.5305 ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ 0 0 1 0 0 ⎥ ⎢ 0 0.6585 −0.1513 ⎥ = ⎢ 0 0.6585 −0.1513 ⎥ . ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎣ 0 0 0 1 0 ⎦ ⎣ 0 −0.3916 −0.8539 ⎦ ⎣ 0 −0.3916 −0.8539 ⎦ 0 0 0 0 1 0 0.2483 0.3817 0 0.2483 0.3817

Moving to the second column, we compute a Givens rotation that, when applied to a42 and a52, zeros a52:  0.8445 0.5355 T  −0.3916   0.4636  = . −0.5355 0.8445 0.2483 0 Applying this rotation to rows 4 and 5 yields

⎡ 1 0 0 0 0 ⎤T ⎡ 1.6536 1.1405 1.2569 ⎤ ⎡ 1.6536 1.1405 1.2569 ⎤ ⎢ 0 1 0 0 0 ⎥ ⎢ 0 0.5336 0.5305 ⎥ ⎢ 0 0.5336 0.5305 ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ 0 0 1 0 0 ⎥ ⎢ 0 0.6585 −0.1513 ⎥ = ⎢ 0 0.6585 −0.1513 ⎥ . ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎣ 0 0 0 0.8445 0.5355 ⎦ ⎣ 0 −0.3916 −0.8539 ⎦ ⎣ 0 −0.4636 −0.9256 ⎦ 0 0 0 −0.5355 0.8445 0 0.2483 0.3817 0 0 −0.1349

Next, we compute a Givens rotation that, when applied to a32 and a42, zeros a42:

 0.8177 0.5757 T  0.6585   0.8054  = . −0.5757 0.8177 −0.4636 0

5 Applying this rotation to rows 3 and 4 yields ⎡ 1 0 0 0 0 ⎤T ⎡ 1.6536 1.1405 1.2569 ⎤ ⎡ 1.6536 1.1405 1.2569 ⎤ ⎢ 0 1 0 0 0 ⎥ ⎢ 0 0.5336 0.5305 ⎥ ⎢ 0 0.5336 0.5305 ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ 0 0 0.8177 0.5757 0 ⎥ ⎢ 0 0.6585 −0.1513 ⎥ = ⎢ 0 0.8054 0.4091 ⎥ . ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎣ 0 0 −0.5757 0.8177 0 ⎦ ⎣ 0 −0.4636 −0.9256 ⎦ ⎣ 0 0 −0.8439 ⎦ 0 0 0 0 1 0 0 −0.1349 0 0 −0.1349

Next, we compute a Givens rotation that, when applied to a22 and a32, zeros a32:  0.5523 −0.8336 T  0.5336   0.9661  = . 0.8336 0.5523 0.8054 0 Applying this rotation to rows 3 and 4 yields ⎡ 1 0 0 0 0 ⎤T ⎡ 1.6536 1.1405 1.2569 ⎤ ⎡ 1.6536 1.1405 1.2569 ⎤ ⎢ 0 0.5523 −0.8336 0 0 ⎥ ⎢ 0 0.5336 0.5305 ⎥ ⎢ 0 0.9661 0.6341 ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ 0 0.8336 0.5523 0 0 ⎥ ⎢ 0 0.8054 0.4091 ⎥ = ⎢ 0 0 −0.2163 ⎥ . ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎣ 0 0 0 1 0 ⎦ ⎣ 0 0 −0.8439 ⎦ ⎣ 0 0 −0.8439 ⎦ 0 0 0 0 1 0 0 −0.1349 0 0 −0.1349

Moving to the third column, we compute a Givens rotation that, when applied to a43 and a53, zeros a53:  0.9875 −0.1579 T  −0.8439   0.8546  = . 0.1579 0.9875 −0.1349 0 Applying this rotation to rows 4 and 5 yields ⎡ 1 0 0 0 0 ⎤T ⎡ 1.6536 1.1405 1.2569 ⎤ ⎡ 1.6536 1.1405 1.2569 ⎤ ⎢ 0 1 0 0 0 ⎥ ⎢ 0 0.9661 0.6341 ⎥ ⎢ 0 0.9661 0.6341 ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ 0 0 1 0 0 ⎥ ⎢ 0 0 −0.2163 ⎥ = ⎢ 0 0 −0.2163 ⎥ . ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎣ 0 0 0 0.9875 −0.1579 ⎦ ⎣ 0 0 −0.8439 ⎦ ⎣ 0 0 −0.8546 ⎦ 0 0 0 0.1579 0.9875 0 0 −0.1349 0 0 0

Finally, we compute a Givens rotation that, when applied to a33 and a43, zeros a43:  0.2453 −0.9694 T  −0.2163   0.8816  = . 0.9694 0.2453 −0.8546 0 Applying this rotation to rows 3 and 4 yields ⎡ 1 0 0 0 0 ⎤T ⎡ 1.6536 1.1405 1.2569 ⎤ ⎡ 1.6536 1.1405 1.2569 ⎤ ⎢ 0 1 0 0 0 ⎥ ⎢ 0 0.9661 0.6341 ⎥ ⎢ 0 0.9661 0.6341 ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ 0 0 0.2453 −0.9694 0 ⎥ ⎢ 0 0 −0.2163 ⎥ = ⎢ 0 0 −0.8816 ⎥ = R. ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎣ 0 0 0.9694 0.2453 0 ⎦ ⎣ 0 0 −0.8546 ⎦ ⎣ 0 0 0 ⎦ 0 0 0 0 1 0 0 0 0 0 0

6 Applying the transpose of each Givens rotation, in order, to the columns of the identity matrix yields the matrix ⎡ 0.4927 −0.4806 0.1780 −0.7033 0 ⎤ ⎢ 0.5478 −0.3583 −0.5777 0.4825 0.0706 ⎥ ⎢ ⎥ Q = ⎢ 0.0768 0.4754 −0.6343 −0.4317 −0.4235 ⎥ ⎢ ⎥ ⎣ 0.5523 0.3391 0.4808 0.2769 −0.5216 ⎦ 0.3824 0.5473 0.0311 −0.0983 0.7373 such that QT A = R is upper triangular. □

Householder Reflections It is natural to ask whether we can introduce more zeros with each orthogonal rotation. To that end, we examine Householder reflections. Consider a matrix of the form P = I − uuT , where u ∕= 0 and  is a nonzero constant. It is clear that P is a symmetric rank-1 change of I. Can we choose  so that P is also orthogonal? From the desired relation P T P = I we obtain

P T P = (I − uuT )T (I − uuT ) = I − 2uuT +  2uuT uuT = I − 2uuT +  2(uT u)uuT = I + ( 2uT u − 2)uuT = I + (uT u − 2)uuT .

It follows that if  = 2/uT u, then P T P = I for any nonzero u. Without loss of generality, we can stipulate that uT u = 1, and therefore P takes the form P = I − 2vvT , where vT v = 1. Why is the matrix P called a reflection? This is because for any nonzero vector x, P x is the reflection of x across the hyperplane that is normal to v. To see this, we consider the 2 × 2 case and set v =  1 0 T and x =  1 2 T . Then

P = I − 2vvT  1  = I − 2  1 0  0  1 0   1 0  = − 2 0 1 0 0  −1 0  = 0 1 Therefore  −1 0   1   −1  P x = = . 0 1 2 2

7 Now, let x be any vector. We wish to construct P so that P x = e1 for some , where  T e1 = 1 0 ⋅ ⋅ ⋅ 0 . From the relations

∥P x∥2 = ∥x∥2, ∥ e1∥2 = ∣ ∣∥e1∥2 = ∣ ∣, we obtain = ±∥x∥2. To determine P , we begin with the equation

T T P x = (I − 2vv )x = x − 2vv x = e1.

Rearranging, we obtain 1 (x − e ) = (vT x)v. 2 1

It follows that the vector v, which is a unit vector, must be a scalar multiple of x − e1. Therefore, v is defined by the equations

x1 − v1 = ∥x − e1∥2 x − = 1 p 2 2 ∥x∥2 − 2 x1 + x − = √ 1 2 2 − 2 x1 − x1 = −p 2 ( − x1) r − x = −sgn( ) 1 , 2 x2 v2 = p 2 ( − x1) x = − 2 , 2 v1 . . xn vn = − . 2 v1 To avoid catastrophic cancellation, it is best to choose the sign of so that it has the opposite sign of x1. It can be seen that the computation of v requires about 3n operations. Note that the matrix P is never formed explicitly. For any vector b, the product P b can be computed as follows: P b = (I − 2vvT )b = b − 2(vT b)v. This process requires only 4n operations. It is easy to see that we can represent P simply by storing only v.

8 Now, suppose that that x = a1 is the first column of a matrix A. Then we construct a T Householder reflection H1 = I − 2v1v1 such that Hx = e1, and we have ⎡ ⎤ r11 r12 ⋅ ⋅ ⋅ r1n ⎢ 0 ⎥ A(2) = H A = ⎢ ⎥ . 1 ⎢ . (2) (2) ⎥ ⎣ . a2:m,2 ⋅ ⋅ ⋅ a2:m,n ⎦ 0

(2) where we denote the constant by r11, as it is the (1, 1) element of the updated matrix A . Now, we can construct H˜2 such that ⎡ ⎤ ⎡ ⎤ r11 r12 r13 ⋅ ⋅ ⋅ r1n r22 ⎢ 0 r22 r23 ⋅ ⋅ ⋅ r2n ⎥ ⎢ 0 ⎥  1 0  ⎢ ⎥ ˜ (2) ⎢ ⎥ (3) (2) ⎢ 0 0 ⎥ H2a2:m,2 = . ,A = ˜ A = . ⎢ . ⎥ 0 H2 ⎢ . . ⎥ ⎣ ⎦ ⎢ . . a(3) ⋅ ⋅ ⋅ a(3) ⎥ 0 ⎣ 3:m,3 3:m,n ⎦ 0 0

(2) Note that the first column of A is unchanged by H˜2, because H˜2 only operates on rows 2 through m, which, in the first column, have zero entries. Continuing this process, we obtain

(n+1) Hn ⋅ ⋅ ⋅ H1A = A = R, where, for j = 1, 2, . . . , n,   Ij−1 0 Hj = 0 H˜j and R is an upper triangular matrix. We have thus factored A = QR, where Q = H1H2 ⋅ ⋅ ⋅ Hn is an orthogonal matrix. Note that for each j = 1, 2, . . . , n, H˜j is also a Householder reflection, based on a vector whose first j − 1 components are equal to zero. Therefore, application of Hj to a matrix does not affect the first j rows or columns. We also note that

AT A = RT QT QR = RT R, and thus R is the Cholesky factor of AT A. Example We apply Householder reflections to compute the QR factorization of the matrix from the previous example, ⎡ 0.8147 0.0975 0.1576 ⎤ ⎢ 0.9058 0.2785 0.9706 ⎥ (1) ⎢ ⎥ A = A = ⎢ 0.1270 0.5469 0.9572 ⎥ . ⎢ ⎥ ⎣ 0.9134 0.9575 0.4854 ⎦ 0.6324 0.9649 0.8003

9 First, we work with the first column of A,

⎡ 0.8147 ⎤ ⎢ 0.9058 ⎥ (1) ⎢ ⎥ x1 = a = ⎢ 0.1270 ⎥ , ∥x1∥2 = 1.6536. 1:5,1 ⎢ ⎥ ⎣ 0.9134 ⎦ 0.6324

The corresponding Householder vector is

⎡ 0.8147 ⎤ ⎡ 1.0000 ⎤ ⎡ 2.4684 ⎤ ⎢ 0.9058 ⎥ ⎢ 0 ⎥ ⎢ 0.9058 ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ v˜1 = x1 + ∥x1∥2e1 = ⎢ 0.1270 ⎥ + 1.6536 ⎢ 0 ⎥ = ⎢ 0.1270 ⎥ . ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎣ 0.9134 ⎦ ⎣ 0 ⎦ ⎣ 0.9134 ⎦ 0.6324 0 0.6324

From this vector, we build the Householder reflection

2 ˜ T c = T = 0.2450, H1 = I − cv˜1v˜1 . v˜1 v˜1

Applying this reflection to A(1) yields

⎡ −1.6536 −1.1405 −1.2569 ⎤ ⎡ −1.6536 −1.1405 −1.2569 ⎤ ⎢ 0 −0.1758 0.4515 ⎥ ⎢ 0 −0.1758 0.4515 ⎥ ˜ (1) ⎢ ⎥ (2) ⎢ ⎥ H1A = ⎢ 0 0.4832 0.8844 ⎥ ,A = ⎢ 0 0.4832 0.8844 ⎥ . 1:5,1:3 ⎢ ⎥ ⎢ ⎥ ⎣ 0 0.4994 −0.0381 ⎦ ⎣ 0 0.4994 −0.0381 ⎦ 0 0.6477 0.4379 0 0.6477 0.4379

Next, we take the “interesting” portion of the second column of the updated matrix A(2), from rows 2 to 5: ⎡ −0.1758 ⎤ (2) ⎢ 0.4832 ⎥ x2 = a = ⎢ ⎥ , ∥x2∥2 = 0.9661. 2:5,2 ⎣ 0.4994 ⎦ 0.6477 The corresponding Householder vector is

⎡ −0.1758 ⎤ ⎡ 1.0000 ⎤ ⎡ −1.1419 ⎤ ⎢ 0.4832 ⎥ ⎢ 0 ⎥ ⎢ 0.4832 ⎥ v˜2 = x2 − ∥x2∥2e1 = ⎢ ⎥ − 0.9661 ⎢ ⎥ = ⎢ ⎥ . ⎣ 0.4994 ⎦ ⎣ 0 ⎦ ⎣ 0.4994 ⎦ 0.6477 0 0.6477

10 From this vector, we build the Householder reflection

2 ˜ T c = T = 0.9065, H2 = I − cv˜2v˜2 . v˜2 v˜2 Applying this reflection to A(2) yields ⎡ −1.6536 −1.1405 −1.2569 ⎤ ⎡ 0.9661 0.6341 ⎤ 0 0.9661 0.6341 0 0.8071 ⎢ ⎥ H˜ A(2) = ⎢ ⎥ ,A(3) = ⎢ 0 0 0.8071 ⎥ . 2 2:5,2:3 ⎢ 0 −0.1179 ⎥ ⎢ ⎥ ⎣ ⎦ ⎢ 0 0 −0.1179 ⎥ 0 0.3343 ⎣ ⎦ 0 0 0.3343

Finally, we take the interesting portion of the third column of A(3), from rows 3 to 5: ⎡ 0.8071 ⎤ (3) x3 = a3:5,3 = ⎣ −0.1179 ⎦ , ∥x3∥2 = 0.8816. 0.3343 The corresponding Householder vector is ⎡ 0.8071 ⎤ ⎡ 1.0000 ⎤ ⎡ 1.6887 ⎤ v˜3 = x3 + ∥x3∥2e1 = ⎣ −0.1179 ⎦ + 0.8816 ⎣ 0 ⎦ = ⎣ −0.1179 ⎦ . 0.3343 0 0.3343 From this vector, we build the Householder reflection

2 ˜ T c = T = 0.6717, H3 = I − cv˜3v˜3 . v˜3 v˜3 Applying this reflection to A(3) yields ⎡ −1.6536 −1.1405 −1.2569 ⎤ ⎡ ⎤ −0.8816 ⎢ 0 0.9661 0.6341 ⎥ ˜ (3) (4) ⎢ ⎥ H3A = ⎣ 0 ⎦ ,R = A = ⎢ 0 0 −0.8816 ⎥ . 3:5,3:3 ⎢ ⎥ 0 ⎣ 0 0 0 ⎦ 0 0 0 Applying these same Householder reflections, in order, on the right of the identity matrix, yields the orthogonal matrix ⎡ −0.4927 −0.4806 0.1780 −0.6015 −0.3644 ⎤ ⎢ −0.5478 −0.3583 −0.5777 0.3760 0.3104 ⎥ ⎢ ⎥ Q = H1H2H3 = ⎢ −0.0768 0.4754 −0.6343 −0.1497 −0.5859 ⎥ ⎢ ⎥ ⎣ −0.5523 0.3391 0.4808 0.5071 −0.3026 ⎦ −0.3824 0.5473 0.0311 −0.4661 0.5796

11 such that ⎡ −1.6536 −1.1405 −1.2569 ⎤ ⎢ 0 0.9661 0.6341 ⎥ T ⎢ ⎥ R = Q A = H3H2H1A = ⎢ 0 0 −0.8816 ⎥ ⎢ ⎥ ⎣ 0 0 0 ⎦ 0 0 0 is upper triangular, where ⎡ ⎤   1 0 0 ˜ 1 0 H1 = H1,H2 = ,H3 = ⎣ 0 1 0 ⎦ , 0 H˜2 0 0 H˜3 are the same Householder transformations before, defined in such a way that they can be applied to the entire matrix A. Note that for j = 1, 2, 3,,   T 0 Hj = I − 2vjvj , vj = , ∥vj∥2 = ∥v˜j∥2 = 1, v˜j where the first j − 1 components of vj are equal to zero. Also, note that the first n = 3 columns of Q are the same as those of the matrix Q that was computed in the previous example, except for possible negation. The fourth and fifth columns are not the same, but they do span the same subspace, the orthogonal complement of the range of A. □

Givens Rotations vs. Householder Reflections We showed how to construct Givens rotations in order to rotate two elements of a column vector so that one element would be zero, and that approximately n2/2 such rotations could be used to transform A into an upper triangular matrix R. Because each rotation only modifies two rows of A, it is possible to interchange the order of rotations that affect different rows, and thus apply sets of rotations in parallel. This is the main reason why Givens rotations can be preferable to Householder reflections. Other reasons are that they are easy to use when the QR factorization needs to be updated as a result of adding a row to A or deleting a column of A. They are also more efficient when A is sparse.

12