11.8  QR, Householder and Hessenberg

Section 2 turned a basis into an orthonormal basis one vector at a time, and every step was bookkeeping: each new vector recorded in terms of those already produced. Collect that bookkeeping into a matrix and the Gram–Schmidt process becomes a factorization A=QR — an orthogonal counterpart of the LU factorization of Definition 3.6.1. This section proves it and its uniqueness, then builds it a second time out of reflections, a route that survives dependent columns. The same reflections, applied on both sides, bring any square matrix to an almost-triangular form by a unitary similarity. Throughout, F is R or C, and Fm carries the standard inner product, linear in the first slot.

11.8.1. Gram–Schmidt in matrix form

Let A∈Mm×n(F) have columns a1,…,an, and suppose they are linearly independent. Apply Theorem 11.2.2 to the list (a1,…,an). It returns an orthonormal list (q1,…,qn) in Fm with span(q1,…,qk)=span(a1,…,ak) for every k. In particular ak lies in span(q1,…,qk), and Theorem 11.2.1 (a), applied inside that subspace, expands it: (∗)ak=∑i=1k⟨ak,qi⟩qi(k=1,…,n).

Now read (∗) as a matrix product. Put Q=(q1∣⋯∣qn)∈Mm×n(F) and let R∈Mn(F) have entries rik={⟨ak,qi⟩,i≤k,0,i>k. Then R is upper triangular (Definition 0.9.5), and (∗) says that the k-th column of A equals Q times the k-th column of R. That is exactly A=QR. Nothing has been computed; the factorization is the Gram–Schmidt output, rewritten.

Two features of the rewriting matter later. First the diagonal: in the notation of Theorem 11.2.2, qk=wk/‖wk‖ with wk=ak−∑i<k⟨ak,qi⟩qi, so comparing with (∗) gives rkk=⟨ak,qk⟩=‖wk‖>0, strictly positive because wk≠0. Second, R is recoverable from Q and A: since the columns of Q are orthonormal, (Q∗Q)ij=∑p=1mqpi―qpj=⟨qj,qi⟩=δij, by Definition 11.1.2, so Q∗Q=In and R=Q∗A.

Theorem 11.8.1 (QR Factorization)

Let A∈Mm×n(F) have linearly independent columns. Then there are matrices Q∈Mm×n(F) and R∈Mn(F) with

  • (a) the columns of Q orthonormal, equivalently Q∗Q=In;
  • (b) R upper triangular with positive real diagonal entries;
  • (c) A=QR.

Moreover Q and R are unique: any pair satisfying (a), (b), (c) is this one. The pair (Q,R) is the QR factorization of A.

Idea. Existence is the paragraph above: run Gram–Schmidt and read off the coefficients. For uniqueness, suppose Q1R1=Q2R2. We cannot cancel Q, which is not square, but Q∗Q=I turns A∗A into R∗R and makes the Q’s vanish. That leaves R1∗R1=R2∗R2, so the matrix S carrying R1 to R2 is upper triangular with positive diagonal and satisfies S∗S=I. Such a matrix has no room to be anything but I: column by column, orthogonality to the earlier columns kills every entry above the diagonal.

Proof. Existence. Apply Theorem 11.2.2 to the columns of A, which is legitimate because they are independent, and define Q and R as above. Then (a) holds by orthonormality of the output, (b) holds because rkk=‖wk‖>0, and (c) is (∗).

Uniqueness. Suppose A=Q1R1=Q2R2 with both pairs satisfying (a) and (b). Each Rt has non-zero diagonal entries, hence is invertible by Lemma 3.6.2. Using Qt∗Qt=In twice, R1∗R1=R1∗Q1∗Q1R1=A∗A=R2∗Q2∗Q2R2=R2∗R2. Put S=R2R1−1, so that R2=SR1. The matrix R1−1 is upper triangular: its j-th column is the solution x of R1x=ej, and solving from the bottom row upward gives xi=0 for every i>j, exactly as in the proof of Lemma 3.6.2. Hence S is upper triangular, being a product of upper triangular matrices: in (S)ij=∑k(R2)ik(R1−1)kj a term can be non-zero only when i≤k and k≤j, which is impossible for i>j, and for i=j only the term k=i survives. So its diagonal entries are (S)kk=(R2)kk(R1)kk−1>0, a quotient of positive reals. Substituting R2=SR1 into the display gives R1∗R1=R1∗S∗SR1, and multiplying by (R1∗)−1=(R1−1)∗ on the left and R1−1 on the right leaves S∗S=In.

Claim. An upper triangular S∈Mn(F) with S∗S=In and positive real diagonal entries is In.

Proof. Write s1,…,sn for the columns of S. As computed before the theorem, S∗S=In says ⟨sj,si⟩=δij. We show sj=ej by induction on j. Let 1≤j≤n and suppose si=ei for every i<j (no assumption when j=1). For i<j, 0=⟨sj,si⟩=⟨sj,ei⟩=sij, so every entry of sj above the diagonal vanishes; and sij=0 for i>j because S is upper triangular. Hence sj=sjjej, and 1=⟨sj,sj⟩=|sjj|2 forces |sjj|=1. Since sjj>0, this gives sjj=1 and sj=ej.

By the Claim, S=In, so R2=R1 and therefore Q2=AR2−1=AR1−1=Q1. This proves uniqueness.

The positivity in (b) is a normalization and nothing deeper: without it, scaling qk by any c of modulus 1 and row k of R by c― gives another factorization. Exercise (C1: All the QR factorizations of a matrix) describes all of them.

Warning. In A=QR the matrix Q is usually not square, and QQ∗≠I. Only Q∗Q=In holds. For the 3×2 matrix of Example (A 3×2 QR, and a least-squares problem) below, QQ∗=118(244417−14−117), whose trace is 2, not 3. This is the “identity on what?” trap of Theorem 11.7.3: the columns of Q are an orthonormal basis of a plane, and QQ∗ is the orthogonal projection onto it (Theorem 11.3.3).

Quick check. Each factor of a QR factorization is recoverable from the other: R=Q∗A and Q=AR−1. One of the two recoveries needs an invertibility hypothesis and the other does not. Which, and why?

Solution. The second. Multiplying A=QR on the left by Q∗ gives Q∗QR=R, which uses only Q∗Q=In: nothing is inverted, and Q is not even square. Multiplying on the right by R−1 presupposes that R is invertible — true by Lemma 3.6.2, but only because clause (b) makes the diagonal positive.

11.8.2. Least squares through QR

An inconsistent system Ax=b was handled in Section 4 by the normal equations A∗Ax=A∗b (Theorem 11.4.2). When the columns of A are independent, the QR factorization simplifies those equations to a triangular system.

Substituting A=QR and using Q∗Q=In, A∗A=R∗Q∗QR=R∗R,A∗b=R∗Q∗b, so the normal equations read R∗Rx=R∗Q∗b. Now R is invertible by Lemma 3.6.2, hence so is R∗, with (R∗)−1=(R−1)∗ — conjugate-transpose RR−1=In. So R∗ cancels: (†)Rx=Q∗b. By Corollary 11.4.4 the least-squares solution is unique here, and (†) is a triangular system, solved by back substitution. The deeper reason to prefer it is not the operation count: forming A∗A squares the sensitivity of the problem to rounding, while (†) never forms that product at all. Chapter 24 makes “sensitivity” precise and proves the comparison; here we record only the practice.

Example (A 3×2 QR, and a least-squares problem)

Let A=(112123),b=(111).

  • (a) Find the QR factorization of A.
  • (b) Find the x∈R2 minimizing ‖Ax−b‖, using (a).

Solution.

  • (a) Write a1=(1,2,2) and a2=(1,1,3). They are independent, since neither is a multiple of the other.

    Step 1. ‖a1‖2=1+4+4=9, so r11=3 and q1=13(1,2,2).

    Step 2. r12=⟨a2,q1⟩=13(1+2+6)=3, so w2=(1,1,3)−3⋅13(1,2,2)=(0,−1,1), with ‖w2‖=2=r22 and q2=12(0,−1,1). Hence Q=(13023−122312),R=(3302). Check. QR has first column 3q1=(1,2,2) and second column 3q1+2q2=(1,2,2)+(0,−1,1)=(1,1,3), which is A.

  • (b) By (†) we need Q∗b. Here ⟨b,q1⟩=13(1+2+2)=53 and ⟨b,q2⟩=12(0−1+1)=0, so the system is (3302)x=(530). Back substitution gives 2x2=0, so x2=0, and then 3x1=53, so x1=59. The minimizer is x=(59,0).

Check against the normal equations. A⊤A=(99911) and A⊤b=(5,5). Subtracting the first equation from the second gives 2x2=0, and then 9x1=5. The same answer, with the same arithmetic done in a worse order.

11.8.3. Reflections

Gram–Schmidt builds Q out of the columns of A. There is an entirely different route to a triangular R, modeled on elimination: hit A on the left with simple matrices that create zeros, one column at a time, and collect the inverses. Chapter 3 used shears and got A=LU; if every matrix we hit A with is unitary instead, the collected product is unitary and we get A=QR. Which unitary matrices are simple enough? A rotation in the plane of two coordinates is one answer, taken up below. The more efficient answer is a reflection, because one reflection can flatten an entire column at once.

A reflection in a hyperplane sends a vector to its mirror image: keep the part perpendicular to w, and reverse the part along w.

Definition 11.8.1 (Householder Reflection)

Let w∈Fm be non-zero. The Householder reflection determined by w is Hw=Im−2ww∗‖w‖2∈Mm(F).

In words: ww∗ is an m×m matrix (a column times a row), and for any v∈Fm the product w∗v is the scalar ∑pwp―vp=⟨v,w⟩. So the definition says (‡)Hwv=v−2⟨v,w⟩‖w‖2w=v−2Pspan(w)v, where the last equality is Theorem 11.3.3 with the orthonormal basis (w/‖w‖) of the line span(w). Writing v=Pspan(w)v+(v−Pspan(w)v) as in Theorem 11.3.2, we see that Hw keeps the component of v in span(w)⊥ and reverses the component along w. That is a mirror reflection in the hyperplane span(w)⊥.

Note at once that Hcw=Hw for every non-zero scalar c, since (cw)(cw)∗=|c|2ww∗ and ‖cw‖2=|c|2‖w‖2. Only the line through w matters.

Examples.

  • The smallest case. In F1 take w=1: then Hw=−1, the map x↦−x. The “hyperplane” is {0}, and this is the only non-trivial isometry of the line.
  • A coordinate reflection. In R2 take w=e2, so ww⊤=(0001) and Hw=diag(1,−1): the reflection in the x-axis.
  • A diagonal reflection. In R2 take w=(1,−1), so ‖w‖2=2 and Hw=I2−(1−1−11)=(0110), which swaps the coordinates. It is the reflection in the line y=x, and span(w)⊥ is that line.
  • A complex one. In Cm take w=e1: then Hw=diag(−1,1,…,1), over either field.

Non-example by minimal change. Drop the factor 2: the matrix Im−ww∗/‖w‖2 is Im−Pspan(w), the orthogonal projection onto span(w)⊥. It is Hermitian, as Hw is, but not unitary and not invertible: it sends w to 0. Halving the coefficient turns “reverse the component along w” into “delete it”, an isometry into a shadow.

Proposition 11.8.2 (Properties of a Householder Reflection)

Let w∈Fm be non-zero and H=Hw. Then

  • (a) H∗=H (H is Hermitian);
  • (b) H2=Im, so H−1=H;
  • (c) H is unitary;
  • (d) Hw=−w, and Hv=v for every v⊥w;
  • (e) detH=−1.

Proof.

  • (a) By Definition 11.1.2, (ww∗)∗=w∗∗w∗=ww∗, and ‖w‖2 is a real number (Theorem 11.1.1 (a)), so H∗=Im−2ww∗/‖w‖2=H.

  • (b) Since w∗w=⟨w,w⟩=‖w‖2, H2=Im−4ww∗‖w‖2+4w(w∗w)w∗‖w‖4=Im, because the last two terms cancel.

  • (c) By (a) and (b), H∗H=H2=Im, which is the criterion of Definition 11.7.2.

  • (d) Both statements are read off (‡): Pspan(w)w=w gives Hw=w−2w=−w, and ⟨v,w⟩=0 gives Hv=v.

  • (e) Extend the unit vector w/‖w‖ to an orthonormal basis (f1,…,fm) of Fm with f1=w/‖w‖, which is possible by Corollary 11.2.3, and let P=(f1∣⋯∣fm). By (d), Hf1=−f1 and Hfi=fi for i≥2, that is, HP=PD with D=diag(−1,1,…,1). The matrix P is unitary, hence invertible, so H=PDP−1. Taking determinants, detH=detD by Theorem 7.5.4 and Corollary 7.5.6, and detD=−1 by Theorem 7.4.6.

So a Householder reflection is a unitary involution of determinant −1: cheap to store (one vector) and cheap to apply, by (‡). What makes it useful is the following choice of w.

Theorem 11.8.3 (A Reflection Flattening a Vector)

Let x∈Fm be non-zero, and let α={x1/|x1|,x1≠0,1,x1=0,w=x+α‖x‖e1. Then w≠0 and Hwx=−α‖x‖e1. In particular Hwx is a multiple of e1 of length ‖x‖. Over R, α is the sign of x1 (or 1 if x1=0), and Hwx=∓‖x‖e1 according to that sign.

Idea. Picture the real plane. We want a mirror line taking x to a point on the first axis at the same distance from the origin. There are two such points, ±‖x‖e1, and for each the mirror is the perpendicular bisector of the segment joining x to it — whose normal direction is the difference x∓‖x‖e1. So the vector w is forced, up to which of the two targets we aim at, and all that remains is to check that the coefficient 2⟨x,w⟩/‖w‖2 in (‡) comes out exactly 1, so that Hwx=x−w. The role of α is to choose the target on the far side from x.

Proof. Note first that α―x1=|x1| in both cases, and |α|=1. Expanding with (IP1) and Theorem 11.1.1 (b), ‖w‖2=‖x‖2+α―‖x‖⟨x,e1⟩+α‖x‖⟨e1,x⟩+|α|2‖x‖2=2‖x‖2+2‖x‖|x1|, where the second line uses ⟨x,e1⟩=x1, ⟨e1,x⟩=x1― and α―x1+αx1―=2|x1|. Since x≠0 we have ‖x‖>0, so ‖w‖2>0 and w≠0. Likewise ⟨x,w⟩=‖x‖2+α―‖x‖x1=‖x‖2+‖x‖|x1|, so that 2⟨x,w⟩=‖w‖2. Hence by (‡), Hwx=x−2⟨x,w⟩‖w‖2w=x−w=−α‖x‖e1. Finally ‖−α‖x‖e1‖=|α|‖x‖=‖x‖ by Theorem 11.1.2 (b), as it must be, since Hw is unitary. This proves the theorem.

Why that sign. The opposite choice w′=x−α‖x‖e1 also works whenever w′≠0, giving Hw′x=+α‖x‖e1; in exact arithmetic the two are equally good, and in floating point they are not. The first entry of w′ is x1−α‖x‖, a difference of two numbers of modulus |x1| and ‖x‖ — and when x is close to a multiple of e1 those two are nearly equal, so the leading digits cancel and the computed first entry keeps only the few digits they did not share. The other entries of w′ are copied from x and stay exact, so the computed w′ points in a noticeably wrong direction, and so does the reflection built from it. With w=x+α‖x‖e1 the first entry has modulus |x1|+‖x‖: like-signed quantities, nothing to cancel. (The same computation shows w≠0 always, whereas w′=0 exactly when x=α‖x‖e1, the extreme case of that cancellation.) Chapter 24 quantifies the loss; the summary here is that both signs are correct mathematics and only one is correct arithmetic.

Warning. Do not build the matrix Hw in order to use it. Forming it and multiplying costs m2 operations per column, while (‡) applies the same reflection with one inner product and one scaled subtraction, about 4m. Every “multiply by H” below is really an instance of (‡); the matrix is a proof device.

Quick check. Let x=(0,3,4)∈R3. Find w and Hwx as in Theorem 11.8.3, and say why the sign question does not arise here.

Solution. ‖x‖=5 and x1=0, so α=1 and w=(0,3,4)+5(1,0,0)=(5,3,4). Then Hwx=−5e1=(−5,0,0). With x1=0 there is no cancellation to avoid: the first entry of w is 0±5 either way, and both choices are equally accurate. The convention α=1 is only a convention.

11.8.4. QR by reflections

One reflection makes the first column a multiple of e1 — exactly the zeros an upper triangular matrix needs in column 1. Repeating on the trailing submatrix triangularizes everything.

Theorem 11.8.4 (QR by Householder Reflections)

Let A∈Mm×n(F). Then there are a unitary Q∈Mm(F) and an R∈Mm×n(F) with rij=0 whenever i>j, such that A=QR. Moreover Q can be taken to be a product of at most min(n,m−1) Householder reflections. No hypothesis on the columns of A is needed.

Idea. Induction on the number of columns. Step one is Theorem 11.8.3 applied to the first column: after it, the first column is ρe1 and what is left to triangularize is the trailing (m−1)×(n−1) block. Feed that block to the induction hypothesis, and lift the unitary matrix it returns to Fm by putting a 1 in the top-left corner — a block matrix of that shape does not touch the first row or the first column, so it cannot spoil the zeros just created.

Proof. We induct on n, the statement being asserted for every m≥1 at once.

If m=1, then A has no entries below its diagonal, so Q=I1 and R=A work. Assume from now on that m≥2.

Let a be the first column of A. If a=0, put H=Im and ρ=0; otherwise let H=Hw be the reflection of Theorem 11.8.3 for x=a, and ρ=−α‖a‖. In both cases H is unitary and Hermitian with H−1=H — by Proposition 11.8.2 (a)–(c) for a reflection, and because Im∗=Im=Im−1 in the degenerate case — and Ha=ρe1. Hence, by Theorem 8.1.1, HA=(ρb∗0A′) for some b∈Fn−1 and A′∈M(m−1)×(n−1)(F), where the 0 is a column of m−1 zeros.

Base case n=1. There is no block A′, and HA=ρe1 already has ri1=0 for i>1. So A=H(HA) is of the required form with Q=H.

Induction step. Let n≥2 and assume the statement for n−1 columns. Applied to A′, which has m−1≥1 rows, it gives a unitary Q′∈Mm−1(F) and an R′ with zeros below the diagonal and A′=Q′R′. Put U=(10∗0Q′),R=(ρb∗0R′). Then U∗U=Im by Theorem 8.1.1, so U is unitary, and UR=HA by the same computation. Also R has zeros below its diagonal: in column 1 this is the block 0; and for j≥2 and i>j, the (i,j)-entry of R is the (i−1,j−1)-entry of R′, which vanishes because i−1>j−1.

Therefore A=HUR, and Q=HU is unitary as a product of unitary matrices (Proposition 11.7.4). Unwinding the induction, Q is a product of one reflection (or Im) for each of the columns 1,…,min(n,m−1), since the recursion stops once one row is left. This proves the theorem.

Example (A 3×3 QR by reflections)

Triangularize A=(201152254) by Householder reflections, and read off Q and R.

Solution. Step 1. The first column is a=(2,1,2) with ‖a‖=3 and a1=2>0, so α=1 and w1=(2,1,2)+3(1,0,0)=(5,1,2),‖w1‖2=30. Apply (‡) to each column: H1v=v−115⟨v,w1⟩w1. All three columns pair with w1 to give 15, so each loses exactly one copy of w1: H1A=(−3−5−4041032). (As predicted, the first column is −‖a‖e1.)

Step 2. Work now in the trailing 2×2 block, whose first column is y=(4,3) with ‖y‖=5 and y1>0. So w2=(9,3), and inside R3 we reflect in w~2=(0,9,3), which fixes e1 and so leaves column 1 alone; here H2v=v−145⟨v,w~2⟩w~2. The second and third columns of H1A pair with w~2 to give 36+9=45 and 9+6=15, so they lose one copy and a third of a copy respectively: R=H2H1A=(−3−5−40−5−2001).

The unitary factor. By Proposition 11.8.2 (b), A=H1H2R, so Q=H1H2. Computing the product, Q=13(−22−1−1−2−2−2−12), whose columns have length 1 and are pairwise orthogonal, as one checks from the integer entries: for instance (−2)(2)+(−1)(−2)+(−2)(−1)=0.

Check. detA=15 by expansion along the first row, and detR=(−3)(−5)(1)=15 by Theorem 7.4.6, consistent with detQ=(−1)(−1)=1 from Proposition 11.8.2 (e).

The diagonal of R here is (−3,−5,1), not positive: the reflection route produces a factorization, not the one of Theorem 11.8.1. The two are related by flipping the sign of each row of R with a negative diagonal entry, and of the matching column of Q; Exercise (B2: The same matrix by reflections) carries this out on the matrix of Example (A 3×2 QR, and a least-squares problem).

Warning. “The QR factorization” is definite only with the positivity normalization. Theorem 11.8.1 pins the pair down by demanding rkk>0; the reflection algorithm ignores that demand and chooses signs for stability instead. So two correct computations of “the QR factorization of A” can differ by signs. Compare |rkk|, and the lines spanned by the columns of Q.

Where Gram–Schmidt cannot follow. Theorem 11.8.4 assumed nothing about the columns, and that is a genuine gain. Let the columns of A be dependent, and let k be the first index with ak∈span(a1,…,ak−1). The Gram–Schmidt recursion then produces wk=0 and stops, because the next step divides by ‖wk‖; Exercise (C2: Gram–Schmidt on a dependent list) works this out. Nor is the failure an artifact of the method: if A=QR with Q∗Q=In and R upper triangular with positive diagonal, then R is invertible by Lemma 3.6.2, so rankA=rankQ=n and the columns were independent after all. A QR factorization in the sense of Theorem 11.8.1 exists exactly for matrices of full column rank. The reflection route is untroubled: a dependent column simply puts a zero on the diagonal of R where the dependence appears, and the algorithm continues (Exercise (C2: Reflections do not mind dependence)).

11.8.5. Givens rotations

A reflection zeroes a whole column at once. Sometimes that is too much: if A is nearly triangular already, we would rather kill the few offending entries one at a time and leave the rest alone.

Definition 11.8.2 (Givens Rotation)

Let 1≤i<j≤m and let c,s∈R with c2+s2=1. The Givens rotation G(i,j;c,s)∈Mm(R) is the identity matrix with the four entries in rows and columns i,j replaced by (giigijgjigjj)=(cs−sc).

The two columns involved are orthonormal, since c2+s2=1 and cs−sc=0, and every other column of G is a standard basis vector, orthogonal to both; so G⊤G=Im and G is orthogonal, with detG=c2+s2=1 by expansion along those other columns (Theorem 7.6.1). Moreover G acts as the identity on every coordinate other than i and j. Given a vector v with (vi,vj)≠(0,0), set r=vi2+vj2,c=vir,s=vjr. Then the i-th entry of Gv is (vi2+vj2)/r=r and the j-th is (−vjvi+vivj)/r=0, while every other entry is unchanged. One rotation, one new zero.

Here is one rotation at work. To clear the (3,1)-entry of the matrix A below, take i=1, j=3 and for v its first column, so that (v1,v3)=(3,4) and r=5, c=35, s=45. Then G=G(1,3;35,45) replaces row 1 by 35(row 1)+45(row 3) and row 3 by −45(row 1)+35(row 3), and leaves row 2 alone: A=(350021405),GA=(5340210−43). The new (1,1)-entry is 15(3⋅3+4⋅4)=5=r and the new (3,1)-entry is 15(−4⋅3+3⋅4)=0, as designed; the zero already sitting in position (2,1) survives because row 2 was never touched. A reflection would have flattened the whole first column in one step, at the price of rewriting row 2 as well.

Applied in a suitable order, rotations triangularize any real matrix, which is a second proof of Theorem 11.8.4 over R at the cost of more steps: a full m×n matrix needs about mn rotations where reflections need n. For a nearly triangular matrix the count reverses, which is why the Hessenberg matrices below are handled with rotations in practice. Over C one takes c∈R, s∈C with c2+|s|2=1, and −s― in place of −s; to zero the j-th entry of v one puts r=|vi|2+|vj|2 and takes c=|vi|/r and s=(vi/|vi|)vj―/r when vi≠0, and c=0, s=1 when vi=0.

11.8.6. Hessenberg form

So far the unitary matrices acted on one side. A similarity needs both: to preserve eigenvalues we must pass from A to Q∗AQ, not to Q∗A. What can reflections achieve under that constraint?

Not triangularity, and the reason is worth seeing before the theorem. Suppose we reflect so that the first column becomes ρe1. Multiplying on the right must not disturb column 1, so the right factor must fix e1 — and so must the left factor, since they are the same matrix. But a reflection fixing e1 acts only on the coordinates 2,…,n, so in column 1 the best it can do is compress rows 2,…,n into row 2. The entry just below the diagonal survives, by necessity. That is exactly the pattern we can reach.

Theorem 11.8.5 (Reduction to Hessenberg Form)

Let A∈Mn(F), n≥1. Then there is a unitary Q∈Mn(F) such that Z=Q∗AQ is upper Hessenberg, that is, zij=0whenever i>j+1. The matrix Q can be taken to be a product of n−2 factors, each a Householder reflection or an identity matrix (and Q=In when n≤2). For n=4 the pattern is Z=(∗∗∗∗∗∗∗∗0∗∗∗00∗∗).

Idea. Work column by column, as in Theorem 11.8.4, but apply each reflection on both sides. At step k it is chosen to fix e1,…,ek and to flatten the part of column k in rows k+1,…,n. Two observations do the bookkeeping. On the left it only recombines rows k+1,…,n, and in the earlier columns those rows are already zero, so a combination of them is still zero. On the right it only recombines columns k+1,…,n, so the columns already in shape are untouched.

Proof. For 0≤k≤n−2 say that B∈Mn(F) satisfies (∗k) if bij=0 whenever j≤k and i≥j+2. Every matrix satisfies (∗0) vacuously, and (∗n−2) says precisely that B is upper Hessenberg, since the conditions with j=n−1 and j=n are empty.

Put A0=A. Let 1≤k≤n−2 and suppose Ak−1 satisfies (∗k−1). Let a∈Fn−k be the vector of entries in rows k+1,…,n of column k of Ak−1. If a=0, put Hk=In−k; otherwise let Hk∈Mn−k(F) be the reflection of Theorem 11.8.3 with Hka=ρe1, where ρ=−α‖a‖. Set Qk=(Ik00Hk)∈Mn(F),Ak=QkAk−1Qk. The block Hk is unitary and Hermitian with Hk−1=Hk — by Proposition 11.8.2 (a)–(c) for a reflection, and because In−k∗=In−k=In−k−1 otherwise — so by Theorem 8.1.1 Qk is unitary and Hermitian with Qk−1=Qk, and Qkej=ej for every j≤k.

Claim 1. QkAk−1 satisfies (∗k−1), and its entries in rows i≥k+2 of column k are 0.

Proof. By Theorem 8.1.1, the rows 1,…,k of QkAk−1 are those of Ak−1, and each of the rows k+1,…,n is a linear combination of the rows k+1,…,n of Ak−1. Fix a column j≤k−1. By (∗k−1), the entries of that column in rows i≥j+2 vanish, and k+1≥j+2, so all the entries being combined are 0 and the combination is 0. Hence (∗k−1) survives. In column k, the entries in rows k+1,…,n form the vector Hka=ρe1, whose entries after the first are 0; these sit in rows k+2,…,n.

Claim 2. Ak=(QkAk−1)Qk has the same first k columns as QkAk−1.

Proof. For j≤k, the j-th column of BQk is B(Qkej)=Bej, the j-th column of B.

Combining the two claims, Ak satisfies (∗k): columns 1,…,k−1 keep the zeros guaranteed by Claim 1, and column k has zeros in rows k+2,…,n, also by Claim 1, and both survive the right multiplication by Claim 2.

Running k=1,…,n−2 produces An−2 satisfying (∗n−2), that is, upper Hessenberg. Put Q=Q1Q2⋯Qn−2, unitary as a product of unitary matrices (Proposition 11.7.4). Since each Qk∗=Qk, Q∗AQ=Qn−2⋯Q1AQ1⋯Qn−2=An−2, which proves the theorem. (For n≤2 there are no steps and every matrix is already Hessenberg.)

Because Q−1=Q∗, the matrices A and Z are similar (Definition 4.2.2), so they share their characteristic polynomial, their eigenvalues and their trace. The reduction is not merely tidying: it removes (n−12) entries and keeps the whole spectrum.

Example (Hessenberg form of a 3×3 matrix)

Reduce A=(210031104) to upper Hessenberg form by a unitary similarity.

Solution. Only k=1 occurs, and only the entry a31 has to be killed. The relevant vector is a=(a21,a31)=(0,1)∈R2, with ‖a‖=1 and a1=0, so α=1 and w=(0,1)+(1,0)=(1,1),‖w‖2=2. Hence H1=I2−ww⊤=(0−1−10), and Q1=(10000−10−10). Left multiplication by Q1 exchanges rows 2 and 3 and negates them, and right multiplication does the same to columns 2 and 3: Q1A=(210−10−40−3−1),Q1AQ1=(20−1−140013). Entry (3,1) is 0 and entry (2,1) is −1=−‖a‖, as Theorem 11.8.3 predicts. Watch column 1 through the second multiplication: it is untouched, because Q1e1=e1. Both matrices have trace 9, as similarity requires.

Warning. Hessenberg form is not one small step from triangular form. A few more reflections will not clear the subdiagonal, and not merely because the argument above breaks. The diagonal of a triangular matrix similar to A lists the eigenvalues of A (Theorem 9.7.4), so a finite procedure using only arithmetic and square roots that always produced one would extract the roots of an arbitrary polynomial from its coefficients by those operations alone. No such procedure exists: from degree five on, the roots of a general polynomial cannot be written with arithmetic and radicals at all. That is a theorem of Abel and Ruffini, which this book does not prove and which nothing later depends on; we quote it only to explain why the algorithms of Chapter 24 iterate instead of terminating. Over C a triangularizing unitary does exist (Theorem 9.7.2); what does not exist is a finite algorithm of this kind producing it. Over R even the existence fails: a rotation in O(2) with no real eigenvalue is already Hessenberg and is orthogonally similar to no real triangular matrix.

Hessenberg form is where the practical computation of eigenvalues begins. One applies the reduction once, then iterates a cheap step that preserves the pattern: factor Z=QR and replace Z by RQ=Q∗ZQ, again a unitary similarity. Chapter 24 develops that iteration and explains why every implementation starts with the reduction proved here.

Quick check. In the reduction of a 5×5 matrix, how many reflections are used, and how many entries does the second one set to zero?

Solution. Three, namely k=1,2,3. The step k=2 chooses a reflection acting on the coordinates 3,4,5 and sets the entries in rows 4 and 5 of column 2 to zero: two entries. (Step 1 sets three, step 3 sets one, for (42)=6 in total.)

11.8.7. Exercises

A. Check your understanding

Exercise (A1)
  • (a) State Theorem 11.8.1 in full, including the two normalizations that make Q and R unique.
  • (b) Which hypothesis on A does Theorem 11.8.1 need, and which does Theorem 11.8.4 need? Explain the difference in one sentence.
  • (c) Write down the Householder reflection determined by w, and list three of its properties.
  • (d) In Theorem 11.8.3, which of the two possible targets ±‖x‖e1 is chosen, and why?
  • (e) True or false: applying reflections on both sides, as in Theorem 11.8.5, can be pushed to make every complex matrix unitarily similar to an upper triangular one. Justify your answer.
  • (f) Why must the reflection used at step k of Theorem 11.8.5 fix e1,…,ek?

Solution.

  • (a) If the columns of A∈Mm×n(F) are independent, then A=QR with R upper triangular; the normalizations are that the columns of Q are orthonormal and that the diagonal of R is positive real. With both, the pair is unique.

  • (b) Theorem 11.8.1 needs independent columns; Theorem 11.8.4 needs nothing. A positive diagonal forces R to be invertible and hence rankA=n, while the reflection route is content to put a zero on the diagonal where a dependence occurs.

  • (c) Hw=Im−2ww∗/‖w‖2 (Definition 11.8.1); it is Hermitian, unitary, equal to its own inverse, and has determinant −1 (Proposition 11.8.2).

  • (d) The target −α‖x‖e1, where α is the phase (over R, the sign) of x1 — that is, the target on the opposite side from x1. The reason is arithmetic: this makes the first entry of w=x+α‖x‖e1 a sum of like-signed quantities, with no cancellation of leading digits.

  • (e) False. A reflection preserving the zeros already created must fix e1,…,ek, and then it cannot touch the entry in row k+1 of column k. More decisively, such a finite procedure would compute the roots of an arbitrary polynomial by arithmetic and square roots alone, which the theorem of Abel and Ruffini quoted in the warning rules out.

  • (f) Because the same matrix multiplies on the right, and right multiplication by Qk changes column j only if Qkej≠ej. Fixing e1,…,ek is exactly what leaves columns 1,…,k, and the zeros in them, alone.

B. Practice

Exercise (B1: QR by Gram–Schmidt)

Find the QR factorization of A=(111110100) in the sense of Theorem 11.8.1, and verify that R=Q⊤A for the top-left 2×2 entries.

Solution. Step 1. a1=(1,1,1) has ‖a1‖=3, so r11=3 and q1=13(1,1,1).

Step 2. r12=⟨a2,q1⟩=23, so w2=(1,1,0)−23(1,1,1)=13(1,1,−2), with ‖w2‖2=19⋅6=23. Hence r22=2/3 and q2=16(1,1,−2).

Step 3. r13=⟨a3,q1⟩=13 and r23=⟨a3,q2⟩=16, so w3=(1,0,0)−13(1,1,1)−16(1,1,−2)=(12,−12,0), with ‖w3‖=12=r33 and q3=12(1,−1,0). Therefore Q=(1316121316−1213−260),R=(32313026160012), where r22=2/3=2/6. All three diagonal entries are positive, as required.

For the verification, (Q⊤A)11=⟨a1,q1⟩=3/3=3=r11 and (Q⊤A)12=⟨a2,q1⟩=2/3=r12; also (Q⊤A)21=⟨a1,q2⟩=(1+1−2)/6=0=r21 and (Q⊤A)22=⟨a2,q2⟩=2/6=r22.

Exercise (B2: The same matrix by reflections)

Let A=(112123), the matrix of Example (A 3×2 QR, and a least-squares problem).

  • (a) Find w1 and the reflection H1 of Theorem 11.8.3 for the first column of A, and compute H1A.
  • (b) Find the second reflection and hence a factorization A=QR with Q∈M3(R) orthogonal and R∈M3×2(R) upper triangular.
  • (c) Compare the R of (b) with the R of Example (A 3×2 QR, and a least-squares problem), and say exactly how the two factorizations differ.

Solution.

  • (a) The first column is a=(1,2,2) with ‖a‖=3 and a1=1>0, so α=1 and w1=(1,2,2)+3e1=(4,2,2), with ‖w1‖2=24. By (‡), H1v=v−112⟨v,w1⟩w1. Since ⟨a,w1⟩=4+4+4=12 and ⟨(1,1,3),w1⟩=4+2+6=12, each column loses one copy of w1: H1A=(−3−30−101).

  • (b) The trailing vector is y=(−1,1), with ‖y‖=2 and y1=−1<0, so α=−1 and w2=(−1,1)−2(1,0)=(−1−2,1). By Theorem 11.8.3, the reflection sends y to +2e1. Embedding it as H2=I1⊕Hw2, we get R=H2H1A=(−3−30200),Q=H1H2, and A=QR because each Hi is its own inverse (Proposition 11.8.2 (b)).

  • (c) In Example (A 3×2 QR, and a least-squares problem), R0=(3302). Deleting the zero row of R leaves R0 with its first row negated, and correspondingly the first column of Q is −q1 while the second is q2. The reflection route did not aim for a positive diagonal, and by the uniqueness in Theorem 11.8.1 signs are the only discrepancy possible.

Exercise (B3: A least-squares fit through QR)

Fit a line y=c0+c1t to the data (t,y)=(0,1),(1,3),(2,2) in the least-squares sense, by finding the QR factorization of the design matrix and solving Rx=Q⊤b. Compute the residual and check the answer against the normal equations.

Solution. The system is Ax=b with A=(101112),b=(132),x=(c0,c1). Gram–Schmidt: ‖a1‖=3, so r11=3 and q1=13(1,1,1). Then r12=⟨a2,q1⟩=3/3=3 and w2=(0,1,2)−(1,1,1)=(−1,0,1), so r22=2 and q2=12(−1,0,1). Now ⟨b,q1⟩=6/3=23 and ⟨b,q2⟩=(−1+0+2)/2=1/2, so (†) reads (3302)x=(231/2). Back substitution gives c1=12 and then 3(c0+12)=23, so c0=32. The fitted line is y=32+12t, with residual Ax−b=(12,−1,12) and ‖Ax−b‖2=32.

Check. A⊤A=(3335) and A⊤b=(6,7). Subtracting the first normal equation from the second gives 2c1=1, and then 3c0+32=6, so c0=32. The residual is orthogonal to both columns of A: 12−1+12=0 and 0⋅12−1⋅1+2⋅12=0, which is what the normal equations of Theorem 11.4.2 say.

Exercise (B4: Determine which are QR factorizations)

Determine which of the following are QR factorizations of the matrix on the left in the sense of Theorem 11.8.1. Justify your answer; for those that are not, name the clause that fails and repair it if possible.

  • (a) (3147)=15(3−443)(53150175).
  • (b) (1011)=(1−111)(112012).
  • (c) (−1001)=(1001)(−1001).

Solution.

  • (a) Yes. The product is 15(15935−685201245+515)=15(1552035)=(3147), the columns of the left factor are 15(3,4) and 15(−4,3), both of length 1 and orthogonal, and the diagonal entries 5 and 175 are positive. All three clauses hold, so by the uniqueness in Theorem 11.8.1 this is the QR factorization.

  • (b) No. The identity is correct, and R is upper triangular with positive diagonal, but the columns of the left factor have length 2, not 1, so clause (a) of Theorem 11.8.1 fails. Repair it by dividing each column of Q by 2 and multiplying the matching row of R by 2: Q=12(1−111),R=(212012).

  • (c) No. The identity is correct and the columns of Q=I2 are orthonormal, but r11=−1<0, so clause (b) fails. Repair it by moving the sign across: Q=diag(−1,1), whose columns are still orthonormal, and R=I2, whose diagonal is positive. This is the move described in Exercise (C1: All the QR factorizations of a matrix) with D=diag(−1,1).

C. Going deeper

Exercise (C1: All the QR factorizations of a matrix)

Let A∈Mm×n(F) have independent columns, with QR factorization A=QR as in Theorem 11.8.1.

  • (a) Prove that an upper triangular S∈Mn(F) with S∗S=In is diagonal, with diagonal entries of modulus 1.
  • (b) Deduce that the pairs (Q1,R1) with Q1∗Q1=In, R1 upper triangular and invertible, and A=Q1R1, are exactly the pairs (QD−1,DR) for D=diag(d1,…,dn) with |dk|=1.
  • (c) Hence give a second proof of the uniqueness statement of Theorem 11.8.1.

Solution.

  • (a) Let s1,…,sn be the columns of S; as in the proof of Theorem 11.8.1, S∗S=In says ⟨sj,si⟩=δij. We show sj=sjjej with |sjj|=1, by induction on j. Suppose this holds for every i<j. For such i, 0=⟨sj,si⟩=sii―⟨sj,ei⟩=sii―sij, and sii≠0, so sij=0. Together with upper triangularity this gives sj=sjjej, and ‖sj‖=1 gives |sjj|=1.

  • (b) (⇐) If |dk|=1 for all k, then D∗D=In, so (QD−1)∗(QD−1)=(D−1)∗Q∗QD−1=(DD∗)−1=In; the matrix DR is upper triangular and invertible; and (QD−1)(DR)=QR=A.

    (⇒) Suppose A=Q1R1 as stated. Exactly as in the proof of Theorem 11.8.1, R1∗R1=A∗A=R∗R, and S=R1R−1 is upper triangular with S∗S=In. By (a), S=D is diagonal with |dk|=1. Then R1=DR and Q1=AR1−1=QRR−1D−1=QD−1.

  • (c) If in addition both R and R1=DR have positive real diagonal entries, then dk=(R1)kk/(R)kk is a positive real number of modulus 1, so dk=1 for every k. Hence D=In, R1=R and Q1=Q.
Exercise (C2: Reflections do not mind dependence)

Let A=(112213235), whose third column is the sum of the first two.

  • (a) Run the Gram–Schmidt process of Theorem 11.2.2 on the columns of A and say precisely which step fails.
  • (b) Carry out the Householder reduction of Theorem 11.8.4 on A and exhibit R.
  • (c) Explain, using Theorem 11.8.1, why no factorization A=QR with Q∗Q=I3 and R upper triangular with positive diagonal can exist.

Solution.

  • (a) Steps 1 and 2 go through: q1=13(1,2,2) and, since ⟨a2,q1⟩=13(1+2+6)=3, w2=(1,1,3)−(1,2,2)=(0,−1,1) and q2=12(0,−1,1). At step 3, a3=a1+a2 lies in span(a1,a2)=span(q1,q2), so by Theorem 11.2.1 (a) the vector subtracted from a3 is a3 itself and w3=0. The normalization q3=w3/‖w3‖ divides by 0 and fails. This is the situation of Exercise (C2: Gram–Schmidt on a dependent list).

  • (b) The first column is (1,2,2), so as in Exercise (B2: The same matrix by reflections) we take w1=(4,2,2) with ‖w1‖2=24, and H1v=v−112⟨v,w1⟩w1. The inner products of the three columns with w1 are 12, 12 and 24, so H1A=(−3−3−60−1−1011). The trailing vector of column 2 is (−1,1), which by Exercise (B2: The same matrix by reflections) (b) the second reflection sends to 2e1; it sends the trailing vector of column 3, which is the same vector (−1,1), to the same place. Hence R=(−3−3−6022000), upper triangular, with a zero in position (3,3) exactly where the dependence sits. No step of the algorithm divided by zero.

  • (c) Such an R would be invertible by Lemma 3.6.2, so rankA=rank(QR)=rankQ=3. But a3=a1+a2, so the columns are dependent and rankA≤2, a contradiction. The positive-diagonal factorization exists precisely for matrices of full column rank.

Exercise (C3: Triangularizing with rotations)
  • (a) Let (a,b)∈R2 be non-zero and r=a2+b2. Verify that the Givens rotation G of Definition 11.8.2 with c=a/r and s=b/r satisfies G(a,b)=(r,0), and that G∈SO(2).
  • (b) Use (a) to write A=(3142) as QR with Q∈SO(2) and R upper triangular with positive diagonal.
  • (c) How many Givens rotations does it take to triangularize a general 3×3 real matrix, and which entries does each one kill? Compare with the number of Householder reflections.

Solution.

  • (a) G(a,b)=(ca+sb, −sa+cb)=((a2+b2)/r, (−ab+ab)/r)=(r,0). Also c2+s2=1, so the columns of G are orthonormal and detG=c2+s2=1; hence G∈SO(2).

  • (b) The first column is (3,4), so r=5, c=35, s=45 and G=15(34−43). Then GA=15(9+163+8−12+12−4+6)=(5115025)=:R, whose diagonal entries 5 and 25 are positive. Since G−1=G⊤∈SO(2), we get A=QR with Q=G⊤=15(3−443). As a check, detA=2=5⋅25=detR.

  • (c) Three: one for a21 (rows 1,2), one for a31 (rows 1,3), and one for the new (3,2)-entry (rows 2,3). The last acts on rows 2 and 3, which by then have zeros in column 1, so it does not undo the earlier work. Householder needs two reflections, one per column, since each clears a whole column at once.

Found a typo or a mistake? Report it, or read this page’s source

The text of this book is licensed under CC BY-NC-SA 4.0.