24.5  The QR Algorithm

Chapter 11 §08 brought a square matrix to upper Hessenberg form with reflections and then stopped, with a warning attached: no finite procedure built from arithmetic and square roots can carry that reduction on to triangular form, because such a procedure would extract the roots of an arbitrary polynomial from its coefficients, and the theorem of Abel and Ruffini forbids it — a theorem this book quotes, there and here, and does not prove. Every eigenvalue method must therefore iterate, and nothing proved below rests on that quotation. The iteration this section develops is the one Chapter 11 named in a single sentence — factor Z=QR, then replace Z by RQ — and we now ask why it works, why it is always started from a Hessenberg matrix, and why it is always run with a shift.

24.5.1. Factor and multiply back

Section 4 iterated a matrix against a vector: the power method drives x(k)=Ax(k−1) towards the dominant eigenvector, one eigenvalue at a time. The whole spectrum at once needs an iteration on matrices, and it must be an iteration by similarity, or the spectrum would not survive it. Chapter 11’s reflections already gave us a supply of similarities that cost little: A↦Q∗AQ with Q unitary. The question is which Q to take.

Here is the answer, and it looks like sleight of hand. Factor A=QR and then multiply the two factors back in the other order. Since Q∗Q=I, the product RQ is Q∗(QR)Q=Q∗AQ, so nothing has been lost; and the reversal shifts weight from the upper triangle into the lower one in a way that, repeated, empties the lower triangle altogether.

Factor the matrix, then put the factors back the wrong way round, and repeat.

Definition 24.5.1 (The QR Iteration)

Let A∈Mn(F), where F=R or F=C. Set A(1)=A, and for k≥1 define A(k)=Q(k)R(k),A(k+1)=R(k)Q(k), where A(k)=Q(k)R(k) is a factorization with Q(k)∈Mn(F) unitary and R(k)∈Mn(F) upper triangular. The sequence A(1),A(2),… is the unshifted QR iteration started at A.

In words: at every step we factor the current matrix, then form the product of its factors in the reversed order, and that product is the next matrix. The superscript in parentheses counts steps, never coordinates.

Well-definedness. A factorization exists at every step, for every square matrix and with no hypothesis on its columns, by Theorem 11.8.4. It need not be unique: if D is diagonal with |dj|=1, then (QD)(D∗R) is another one. When A(k) is invertible the ambiguity is exactly that, and demanding a positive real diagonal in R(k) removes it, by Theorem 11.8.1; and if A is invertible then so is every A(k), being similar to A. We do not need the normalization for anything below, so the definition leaves the choice open.

Proposition 24.5.1 (Every Step Is a Unitary Similarity)

In the notation of Definition 24.5.1, A(k+1)=(Q(k))∗A(k)Q(k) for every k. Consequently all the matrices A(k) are unitarily similar to A, and they share its characteristic polynomial, its eigenvalues with multiplicities, its trace and its determinant.

Proof. Since Q(k) is unitary, (Q(k))∗Q(k)=In (Definition 11.7.2), so (Q(k))∗A(k)Q(k)=(Q(k))∗Q(k)R(k)Q(k)=R(k)Q(k)=A(k+1). A unitary matrix is invertible with Q−1=Q∗, so this exhibits A(k+1) as similar to A(k) (Definition 4.2.2); composing these similarities for 1,…,k−1 makes A(k) similar to A(1)=A. Similar matrices have the same characteristic polynomial (Theorem 7.10.3), hence the same eigenvalues with multiplicities, and the same trace and determinant. This proves the proposition.

Two examples fix what the iteration does and does not do.

Example (Two matrices the iteration cannot move)

Determine the QR iterates of A=diag(3,1) and of the rotation B=(0−110).

Solution. For A: the factorization A=I2A has I2 unitary and A upper triangular with positive diagonal, so by the uniqueness in Theorem 11.8.1 it is the factorization. Then A(2)=AI2=A, and the iteration stands still. It has nothing to do: A is already triangular and its diagonal already lists the eigenvalues (Theorem 9.7.4).

For B: here B is itself unitary, since its columns (0,1) and (−1,0) are orthonormal, so B=BI2 is a factorization with I2 upper triangular with positive diagonal — again the unique one. So B(2)=I2B=B, and the iteration stands still here too. This time it has everything to do: the eigenvalues of B are ±i, and B is not triangular. The iteration is stuck.

The second matrix is the section’s standing negative example, and the reason it is stuck is visible already: |i|=|−i|. We return to it after the convergence theorem, and repair it with a shift.

Warning. Reversing the factors is not a similarity for just any factorization. The step works because Q is unitary, so that Q−1=Q∗ and RQ=Q∗AQ. Do the same with an LU factorization and you get UL=L−1AL, which is still a similarity — but with L−1 in place of L∗, and L−1 can be enormous. That is the older LR iteration, and its instability under rounding is exactly the instability of elimination without pivoting met in Section 2.

24.5.2. The iteration is the power method in disguise

Nothing said so far suggests that the iterates go anywhere. The identity that explains them is the following, and it is the heart of the section: the accumulated factors of k steps are a QR factorization of the k-th power of A. Powers of A are what the power method of Section 4 runs on, so the identity says the two methods are the same method, one applied to a vector and the other to a whole basis at once.

Write Uk=Q(1)Q(2)⋯Q(k),Tk=R(k)⋯R(2)R(1). The first is unitary, as a product of unitary matrices (Proposition 11.7.4), and the second is upper triangular, as a product of upper triangular matrices.

Theorem 24.5.2 (QR Iterates Factor the Powers)

Let A∈Mn(F) and let A(k), Q(k), R(k) be as in Definition 24.5.1. Then for every k≥1, A(k+1)=Uk∗AUkandAk=UkTk. In particular UkTk is a QR factorization of Ak.

Idea. Induction on k, with the two statements proved together, because each feeds the other. The similarity statement is Proposition 24.5.1 telescoped. For the factorization, the move to find is the one that turns AUk into something with a Q at the front: the similarity statement, read backwards, says AUk=UkA(k+1), and A(k+1) is by definition Q(k+1)R(k+1). One line of bookkeeping then converts A⋅Ak into Uk+1Tk+1.

Proof. Both statements by induction on k.

For k=1: U1=Q(1) and T1=R(1), so U1T1=Q(1)R(1)=A(1)=A, and U1∗AU1=A(2) by Proposition 24.5.1.

Let k≥1 and suppose both statements hold for k. By Proposition 24.5.1 applied at step k+1 and the inductive hypothesis, A(k+2)=(Q(k+1))∗A(k+1)Q(k+1)=(Q(k+1))∗Uk∗AUkQ(k+1)=Uk+1∗AUk+1, where the last equality uses Uk+1=UkQ(k+1) and (XY)∗=Y∗X∗. That is the first statement for k+1.

For the second, multiply the inductive similarity A(k+1)=Uk∗AUk on the left by Uk, which is legitimate because UkUk∗=In: AUk=UkA(k+1)=UkQ(k+1)R(k+1)=Uk+1R(k+1). Hence, using the inductive factorization Ak=UkTk, Ak+1=A(UkTk)=(AUk)Tk=Uk+1R(k+1)Tk=Uk+1Tk+1, since Tk+1=R(k+1)Tk by definition. As Uk+1 is unitary and Tk+1 upper triangular, this is a QR factorization of Ak+1, and the induction is complete.

The consequence to keep is about the first column. Comparing first columns in Ak=UkTk and writing τk=(Tk)11, we get

Ake1=UkTke1=τkUke1,
(24.5.1)

because the first column of an upper triangular matrix is τke1. So whenever τk≠0, which the Quick check just below records for invertible A, the first column of Uk is the normalized vector Ake1/‖Ake1‖, up to a scalar of modulus one — which is precisely the k-th iterate of the power method (Theorem 24.4.1) started at e1. The QR algorithm runs the power method in its first column, and, as the next theorem shows, that alone forces the first column of A(k+1) to converge.

Quick check. Why is τk≠0 when A is invertible?

Solution. Each A(j) is similar to A (Proposition 24.5.1), hence invertible, and R(j)=(Q(j))∗A(j) is then invertible as a product of invertible matrices. So Tk is invertible, being a product of invertible matrices; an upper triangular matrix is invertible exactly when its diagonal entries are all non-zero (Lemma 3.6.2), so τk=(Tk)11≠0.

24.5.3. What converges, and how fast

Theorem 24.5.3 (Convergence of the First Column)

Let A∈Mn(C) be invertible and diagonalizable, say A=XΛX−1 with Λ=diag(λ1,…,λn) and with v1,…,vn the columns of X. Assume a single dominant eigenvalue, |λ1|>|λ2|≥⋯≥|λn|>0, and write e1=c1v1+⋯+cnvn, assuming c1≠0. Put t=|λ2/λ1|<1. Then there is a constant C, depending on A and X but not on k, such that the unshifted QR iterates satisfy ‖A(k+1)e1−λ1e1‖2≤Ctk(k≥1). In particular a11(k)→λ1 and ai1(k)→0 for every i≥2, each at the rate tk. For n=2 this says that the iterates converge to upper triangular form, with a11(k)→λ1 and a22(k)→λ2.

Idea. By Eq. 24.5.1 the first column u1 of Uk is the power-method iterate, so it is close to the dominant eigenvector, and the vector Au1−λ1u1 is small. Now read A(k+1)=Uk∗AUk column by column: its first column is Uk∗Au1, and subtracting λ1e1=Uk∗(λ1u1) leaves Uk∗(Au1−λ1u1). A unitary matrix does not change lengths, so the whole error in the first column equals the length of that small vector. Nothing else is needed.

Proof. Write u1=Uke1 for the first column of Uk, suppressing k from the notation.

Step 1: the error in the first column is a residual. Since Uk is unitary and A(k+1)=Uk∗AUk by Theorem 24.5.2, A(k+1)e1−λ1e1=Uk∗Au1−λ1Uk∗u1=Uk∗(Au1−λ1u1), using u1=Uke1 twice. A unitary matrix preserves the Euclidean norm (Theorem 11.7.3), so (∗)‖A(k+1)e1−λ1e1‖2=‖Au1−λ1u1‖2.

Step 2: u1 is a power-method iterate. By Eq. 24.5.1, Ake1=τku1 with τk≠0, as the Quick check above records. Since Avi=λivi, Ake1=∑i=1nciλikvi=c1λ1k(v1+zk),zk=∑i≥2cic1(λiλ1)kvi, which is legitimate because c1≠0 and λ1≠0. Every ratio obeys |λi/λ1|≤t, so ‖zk‖2≤Mtk,M=∑i≥2|ci||c1|‖vi‖2, by the triangle inequality (Corollary 11.1.6). Put yk=v1+zk. Then u1=Ake1/τk=ωkyk/‖yk‖2 for the scalar ωk=c1λ1k‖yk‖2/τk, and |ωk|=1 because ‖u1‖2=1.

Step 3: the residual is small. Since Av1=λ1v1, the vector v1 drops out of (A−λ1I)yk, leaving Au1−λ1u1=ωk(A−λ1I)zk‖yk‖2,so‖Au1−λ1u1‖2≤(‖A‖2+|λ1|)Mtk‖yk‖2. Choose k0 with Mtk0≤12‖v1‖2, possible because t<1. For k≥k0 the triangle inequality gives ‖yk‖2≥‖v1‖2−Mtk≥12‖v1‖2>0, whence ‖Au1−λ1u1‖2≤C1tk,C1=2(‖A‖2+|λ1|)M‖v1‖2. For the finitely many k<k0 the crude bound ‖Au1−λ1u1‖2≤‖A‖2+|λ1| holds, since ‖u1‖2=1. So the displayed estimate holds for all k≥1 with C=max{C1, (‖A‖2+|λ1|)t−k0}, and combining with (∗) proves the main estimate. The entrywise statements follow because each coordinate of a vector is at most its Euclidean norm.

For n=2, the estimate forces a21(k)→0 and a11(k)→λ1; and a22(k)=trA(k)−a11(k)=λ1+λ2−a11(k)→λ2, the trace being preserved by Proposition 24.5.1. This proves the theorem.

What is proved here, and what is not. The theorem above settles the first column, for every n, and with it the whole 2×2 case. The general statement is this: if A is diagonalizable with |λ1|>|λ2|>⋯>|λn|>0, and if X−1 admits an LU factorization without row swaps (Theorem 3.6.4), then the whole of A(k) below the diagonal tends to zero, with ai+1,i(k)=O(|λi+1/λi|k)andaii(k)→λi(1≤i≤n). This is the classical convergence theorem of the algorithm, due to Rutishauser, Francis and Kublanovskaya; it is not proved here. The proof runs through the factorization Ak=XΛkLU of Theorem 24.5.2’s identity, the observation that ΛkLΛ−k→I, and a continuity argument for the QR factorization that this book has not developed. Nothing in this section or later depends on it: the Hessenberg and shifting results below are proved outright, and the worked example at the end exhibits the rates rather than assuming them. The extra hypothesis on X−1 is not cosmetic, and the strict ordering of the moduli is not either — the next example shows what happens without it.

Example (The unshifted algorithm on a rotation)

Let B=(0−110). Explain why no unshifted QR iteration can bring B closer to triangular form, and say which hypothesis of Theorem 24.5.3 fails.

Solution. By Example (Two matrices the iteration cannot move), B(k)=B for every k: the iteration is stationary, and B is as far from triangular as a 2×2 matrix can be, with b21=1. The eigenvalues are ±i, so |λ1|=|λ2|=1 and the hypothesis |λ1|>|λ2| fails. The failure is not an artifact of the proof. Over R the matrix is orthogonally similar to no real triangular matrix at all, since a real triangular matrix has real eigenvalues; and over C the power method has nothing to converge to, because Bke1 simply rotates around the plane forever (Theorem 24.4.1).

Warning. Convergence is to triangular form, not to diagonal form. Even when the iterates do converge, the strictly upper triangular part generally does not: only the entries below the diagonal die out. What is more, in the convergence theorem quoted above — the one this section does not prove — the order in which the eigenvalues appear on the diagonal is decided by the moduli, largest first, so that a run it covers reveals λ1 in the top-left corner and λn in the bottom-right. With shifts, which is how the algorithm is actually run, even that ordering goes away.

24.5.4. Hessenberg first

As written, one step costs a QR factorization of a full n×n matrix and a matrix product: that is O(n3) flops, in the counting convention of Proposition 24.2.3, and the count really does grow like n3, since the product alone touches n2 entries with n terms each. The iteration needs many steps, and no amount of cleverness about the steps rescues a method that spends n3 operations on each of them.

The remedy is Chapter 11’s. Reduce A once to upper Hessenberg form by Theorem 11.8.5, at a cost of O(n3) paid a single time, and then iterate. This pays off only if the pattern survives the step, which is the content of the next proposition — and it is the sentence Chapter 11 §08 closed on: “Chapter 24 develops that iteration and explains why every implementation starts with the reduction proved here.”

Proposition 24.5.4 (A QR Step Preserves Hessenberg Form)

Let Z∈Mn(R) be upper Hessenberg, n≥2. Then Z has a factorization Z=QR with Q orthogonal and R upper triangular in which Q is a product of n−1 Givens rotations and is itself upper Hessenberg; and for this factorization RQ is again upper Hessenberg. Producing R and then RQ costs about 6n2 flops.

Idea. A Hessenberg matrix has only n−1 entries in the way of triangularity, one per column, and Definition 11.8.2 removes one entry per rotation. So the natural factorization to use is the rotation one, not the reflection one — this is the case Chapter 11 §08 flagged, where “the count reverses”. Then two bookkeeping facts finish it: the accumulated product of the rotations is Hessenberg, and upper triangular times upper Hessenberg is upper Hessenberg.

Proof. For 1≤i≤n−1 let Gi=G(i,i+1;ci,si) be a Givens rotation in the coordinates i,i+1 (Definition 11.8.2). Working left to right, choose Gi to annihilate the entry in position (i+1,i) of the matrix produced so far: if that matrix has entries a in position (i,i) and b in position (i+1,i) with (a,b)≠(0,0), take ci=a/r and si=b/r with r=a2+b2, as in Chapter 11 §08; if (a,b)=(0,0), take Gi=In. This is the only entry below the diagonal in column i: the entries in rows i+2,…,n of that column were zero in Z, because Z is upper Hessenberg, and the earlier rotations G1,…,Gi−1 touch only rows 1,…,i. Left multiplication by Gi recombines rows i and i+1 only, so it cannot disturb the zeros already created: in a column j≤i−1 both of the rows being combined are already zero, since i≥j+1. Hence R=Gn−1⋯G1Z is upper triangular, and Z=QR with Q=G1⊤G2⊤⋯Gn−1⊤, orthogonal as a product of orthogonal matrices.

Claim. Pm=G1⊤⋯Gm⊤ is upper Hessenberg for 1≤m≤n−1, and its columns m+2,…,n are em+2,…,en.

Proof. Induction on m. Each Gi⊤ fixes ej for j∉{i,i+1}, so Pmej=ej whenever j>m+1, which is the second assertion. For m=1, P1=G1⊤ differs from In only in rows and columns 1,2, so its only non-zero entry below the diagonal is in position (2,1), and it is upper Hessenberg. Let m≥2 and suppose the claim holds for m−1. Right multiplication by Gm⊤ changes only columns m and m+1, replacing them by the two combinations cmPm−1em+smPm−1em+1and−smPm−1em+cmPm−1em+1. By the inductive hypothesis Pm−1em has zero entries in rows m+2,…,n, being column m of an upper Hessenberg matrix, and Pm−1em+1=em+1 since m+1>(m−1)+1. So both combinations vanish in rows m+2,…,n. Column m of Pm therefore vanishes below row m+1, as an upper Hessenberg matrix requires; and column m+1 vanishes below row m+1, which is more than required. All other columns are unchanged, so Pm is upper Hessenberg.

By the Claim, Q=Pn−1 is upper Hessenberg. Finally, (RQ)pq=∑krpkqkq has a non-zero term only when k≥p, because R is upper triangular, and k≤q+1, because Q is upper Hessenberg; together these force p≤q+1. So RQ is upper Hessenberg.

Cost. Rotation Gi alters rows i,i+1 in columns i,…,n only, since in the earlier columns both of those rows are already zero: that is n−i+1 pairs of entries, each pair replaced by two combinations of two terms, so 6(n−i+1) flops. Summing over i=1,…,n−1 gives 3n2+O(n). Forming RQ=RG1⊤⋯Gn−1⊤ applies Gi⊤ on the right to columns i,i+1 of the matrix built so far, and the same induction as in the Claim shows that those two columns vanish below row i+1; so 6(i+1) flops suffice, and summing gives 3n2+O(n) again. The total is 6n2+O(n), which proves the proposition.

So the reduction is done once, for O(n3), and every subsequent step costs O(n2) — a saving of a factor of n on each of the many steps. That is the whole reason every implementation begins with Theorem 11.8.5.

Remark. The proposition is stated over R because Definition 11.8.2 is. Over C one uses the complex rotations described in Chapter 11 §08 and the argument is unchanged. The conclusion also does not depend on which QR factorization is used, as long as Z is invertible: two factorizations then differ by Q↦QD and R↦D∗R with D unitary diagonal, and (D∗R)(QD)=D∗(RQ)D has exactly the same pattern of zeros as RQ. Invertibility is doing work there: for Z=e1e3⊤∈M3(R), which is upper Hessenberg and singular, the reversal permutation Q (with Qej=e4−j) and R=e3e3⊤ give an orthogonal Q, an upper triangular R and QR=Z, while RQ=e3e1⊤ has a non-zero (3,1) entry and is not upper Hessenberg.

Quick check. A symmetric matrix is upper Hessenberg exactly when it is tridiagonal. What does Proposition 24.5.4 then say about a QR step applied to a symmetric tridiagonal matrix?

Solution. That the step returns a symmetric tridiagonal matrix. Symmetry survives because RQ=Q⊤ZQ is a congruence by an orthogonal matrix as well as a similarity, so (Q⊤ZQ)⊤=Q⊤Z⊤Q=Q⊤ZQ; and Hessenberg form survives by the proposition. A symmetric Hessenberg matrix has zij=0 whenever i>j+1, hence also whenever j>i+1, which is tridiagonality. The cost then drops further, to O(n) per step.

24.5.5. Shifts

The rate |λi+1/λi| is a property of A, and we cannot change A. We can change the matrix we iterate on. For any μ∈F, the matrix A−μI has eigenvalues λi−μ, so its ratios of moduli are |λi+1−μ|/|λi−μ| — and a μ close to λn makes the last of these tiny. This is the same observation that turned the power method into inverse iteration in Section 4, where the shift μ was used to make (A−μI)−1 have a huge dominant eigenvalue (Theorem 24.4.3).

The shifted QR step is A(k)−μkI=Q(k)R(k),A(k+1)=R(k)Q(k)+μkI, and it is still a unitary similarity: R(k)Q(k)=(Q(k))∗(A(k)−μkI)Q(k), so adding μkI back gives A(k+1)=(Q(k))∗A(k)Q(k) exactly as in Proposition 24.5.1. The shift may be changed at every step, which is why the ratio can be driven down as the information improves. And since A(k)−μkI is Hessenberg whenever A(k) is, Proposition 24.5.4 applies to the shifted step: as it stands for a real μk, and in the complex form recorded in the Remark after it for a μk off the real line, which the second of the two shifts below produces.

Two shifts are standard. The Rayleigh shift takes μk=ann(k), the trailing diagonal entry; when A is Hermitian this is the Rayleigh quotient RA(k)(en) of Definition 17.1.1, hence a good eigenvalue estimate as soon as en is nearly an eigenvector. The Wilkinson shift takes μk to be the eigenvalue of the trailing 2×2 block of A(k) nearer to ann(k); it costs one quadratic formula and, unlike the Rayleigh shift, it can leave the real line, which is what lets it break the deadlock of a rotation.

The extreme case says exactly why shifting works.

Proposition 24.5.5 (An Exact Shift Deflates in One Step)

Let Z∈Mn(F) be upper Hessenberg, n≥2, with all its subdiagonal entries zi+1,i non-zero — such a matrix is called unreduced, the word Lemma 17.4.5 used for the tridiagonal case. Let μ∈F be an eigenvalue of Z. Let Z−μI=QR with Q unitary and R upper triangular, and put Z′=RQ+μI. Then the last row of R is zero, and the last row of Z′ is μen⊤. In particular zn,n−1′=0 and znn′=μ.

Idea. An unreduced Hessenberg matrix cannot lose more than one dimension of rank: its first n−1 columns are independent whatever the matrix does, because the subdiagonal alone makes them so. Shifting by an eigenvalue makes the matrix singular, so the one missing dimension must be the last one, and in a QR factorization “the last dimension is missing” reads as a zero last row of R.

Proof. Write B=Z−μI, again upper Hessenberg with the same non-zero subdiagonal entries.

First, the columns b1,…,bn−1 of B are linearly independent. Delete the first row: what remains is the (n−1)×(n−1) matrix with entries bi+1,j for 1≤i,j≤n−1, which is lower triangular, since bi+1,j=0 for i+1>j+1, that is for i>j; and its diagonal entries bj+1,j are non-zero. A triangular matrix with non-zero diagonal is invertible (Lemma 3.6.2), so those n−1 truncated columns are independent, and the full columns are independent a fortiori.

Second, rankB=n−1: it is at least n−1 by the previous paragraph and at most n−1 because B is singular, μ being an eigenvalue of Z.

Now B=QR with Q invertible, so rankR=rankB=n−1 and the columns Re1,…,Ren−1 are independent, being Q∗b1,…,Q∗bn−1. Since R is upper triangular, its last row has the single possibly non-zero entry rnn; if rnn≠0, then R would be invertible (Lemma 3.6.2 applied after noting that independence of the first n−1 columns forces r11,…,rn−1,n−1≠0), contradicting rankR=n−1. Hence rnn=0 and the last row of R is zero.

A matrix with zero last row keeps it under multiplication on the right: (RQ)nj=∑krnkqkj=0. So the last row of RQ is zero and the last row of Z′=RQ+μI is μen⊤, as claimed.

The proposition is the ideal case, and it explains the practice: the closer μk is to an eigenvalue, the smaller zn,n−1′ is observed to become, and the algorithm watches that one entry. When it falls below a tolerance it is set to zero, the matrix splits into a smaller Hessenberg block and a known eigenvalue, and the iteration restarts on the block. This is deflation, and with it the algorithm is observed to finish after O(n) steps in total rather than converging forever.

Two claims in that paragraph are descriptions of observed behavior, not theorems, and this book proves neither: that a nearer shift always gives a smaller subdiagonal entry, and that the shifted algorithm terminates after O(n) steps. Nothing in this section or later depends on them. What is proved is the exact case, Proposition 24.5.5, and the example below exhibits it.

Example (The shift repairs the rotation, and deflates a symmetric example)
  • (a) Apply one shifted QR step with μ=i to B=(0−110).
  • (b) Apply one shifted QR step with μ=2 to the symmetric tridiagonal matrix A with diagonal (2,2,2) and off-diagonal entries 1.

Solution.

  • (a) Here μ=i is an eigenvalue, so Proposition 24.5.5 predicts an exact deflation. Indeed B−iI=(−i−11−i), whose second column is −i times the first, so the matrix has rank 1. Its first column has norm 2, so take q1=12(−i,1) and q2=12(1,−i), which is a unit vector orthogonal to q1 since (−i)―⋅1+1―⋅(−i)=i−i=0. With Q=(q1∣q2) one computes R=Q∗(B−iI), which is R=(2−i200), with zero last row as predicted. Then RQ=diag(−2i,0), and B′=RQ+iI=diag(−i,i). One step, and the eigenvalues are on the diagonal. The unshifted iteration would have run forever.

  • (b) The matrix is A=(210121012),A−2I=(010101010), and 2 is an eigenvalue of A, since (A−2I)(1,0,−1)=0. Two Givens rotations triangularize A−2I, as in the proof of Proposition 24.5.4. The first uses the entries 0 and 1 in positions (1,1) and (2,1), so r=1, c1=0, s1=1, and G1 exchanges rows 1 and 2 with a sign, producing rows (1,0,1), (0,−1,0), (0,1,0). The second uses the entries −1 and 1 now in positions (2,2) and (3,2), so r=2, c2=−1/2, s2=1/2, and it turns those two rows into (0,2,0) and 0. Hence R=(101020000),Q=G1⊤G2⊤=(01212100012−12), with the last row of R zero, as Proposition 24.5.5 predicts. One checks QR=A−2I column by column. Multiplying back and restoring the shift, A′=RQ+2I=(220220002). The last row and column have split off, carrying the eigenvalue 2, and the remaining 2×2 block has eigenvalues 2±2 — the other two eigenvalues of A. One shifted step, and the problem is finished.

24.5.6. Three unshifted steps, watched

Example (The subdiagonal shrinking at the predicted rate)

Run the unshifted QR iteration on the symmetric tridiagonal matrix A=(210121012), whose eigenvalues are 2+2, 2 and 2−2. Carry out the first step exactly, and tabulate three steps.

Solution. Step one, by hand. Apply Theorem 11.2.2 to the columns a1=(2,1,0), a2=(1,2,1), a3=(0,1,2).

From a1: r11=‖a1‖=5 and q1=15(2,1,0).

From a2: r12=⟨a2,q1⟩=4/5, and w2=a2−45(2,1,0)=15(−3,6,5),r22=‖w2‖=14/5, since 9+36+25=70 and 70/5=14/5; so q2=170(−3,6,5).

From a3: r13=1/5 and r23=16/70, and w3=a3−15(2,1,0)−1670(−3,6,5)=27(1,−2,3),r33=2147, so q3=114(1,−2,3). Now A(2)=RQ. Its (1,1) entry is the first row of R against the first column of Q, namely 5⋅25+45⋅15+15⋅0=2+45=145, and its (2,1) entry is 14/5⋅15+1670⋅0=14/5. Continuing, A(2)=(14514501458235257025767). Three checks: the matrix is symmetric and tridiagonal, as the Quick check after Proposition 24.5.4 predicted; its trace is 145+8235+67=98+82+3035=6=trA; and the entry (3,1) is zero, not merely small.

Three steps, to eight places. The diagonal entries and the two subdiagonal entries run as follows.

k a11(k) a22(k) a33(k) |a21(k)| |a32(k)|
1 2.00000000 2.00000000 2.00000000 1.000000 1.000000
2 2.80000000 2.34285714 0.85714286 0.748331 0.638877
3 3.14285714 2.24844720 0.60869565 0.559397 0.187848
4 3.30841121 2.10394692 0.58764187 0.372193 0.052177

The three diagonal entries are heading for 2+2=3.41421356, 2 and 2−2=0.58578644, largest modulus first — the order the convergence theorem quoted above predicts, exhibited here rather than proved. The two subdiagonal entries shrink by factors 0.748, 0.748, 0.665,…and0.639, 0.294, 0.278,… The predicted asymptotic factors are |λ2/λ1|=2/(2+2)=0.585786 and |λ3/λ2|=(2−2)/2=0.292893. The second entry has already settled onto its rate; the first is still approaching it, and by step 10 its factor is 0.5859. Convergence is linear, and slow: each step buys about a quarter of a decimal digit in the (2,1) entry. That is the cost of not shifting.

24.5.7. Exercises

A. Check your understanding

Exercise (A1)
  • (a) Write down one step of the unshifted QR iteration, and one step of the shifted one, and prove in one line each that both are similarities.
  • (b) State Theorem 24.5.2, and say in one sentence what it has to do with the power method.
  • (c) True or false: the QR iterates of a matrix always converge to an upper triangular matrix. Justify your answer.
  • (d) Why is the iteration run on an upper Hessenberg matrix rather than on a full one? Give the two costs.
  • (e) In Proposition 24.5.5, which hypothesis on Z is doing the work, and where exactly is it used?

Solution.

  • (a) Unshifted: A(k)=QR, A(k+1)=RQ; then RQ=Q∗QRQ=Q∗A(k)Q. Shifted: A(k)−μI=QR, A(k+1)=RQ+μI; then RQ+μI=Q∗(A(k)−μI)Q+μQ∗Q=Q∗A(k)Q.

  • (b) It says Ak=UkTk with Uk=Q(1)⋯Q(k) unitary and Tk=R(k)⋯R(1) upper triangular, and that A(k+1)=Uk∗AUk. Comparing first columns, the first column of Uk is Ake1 normalized, which is the k-th power-method iterate started at e1.

  • (c) False. The rotation (0−110) is a fixed point of the unshifted iteration (Example (Two matrices the iteration cannot move)) and is not triangular; its two eigenvalues have the same modulus, which is exactly the hypothesis Theorem 24.5.3 needs.

  • (d) Because a QR step on a full matrix costs O(n3) flops, with the count genuinely growing like n3, while a step on a Hessenberg matrix costs about 6n2 (Proposition 24.5.4), and the pattern is preserved, so the saving is repeated at every step. The reduction itself is O(n3), paid once (Theorem 11.8.5).

  • (e) That every subdiagonal entry of Z is non-zero. It is used exactly once, to show that the first n−1 columns of Z−μI are independent: deleting the first row leaves a lower triangular matrix whose diagonal is that subdiagonal. Without it Z−μI could drop rank in an earlier column, and the zero row of R need not be the last.

B. Practice

Exercise (B1: One step by hand)

Let A=(2112). Compute the QR factorization of A in the sense of Theorem 11.8.1, then A(2)=RQ. Verify that A(2) is symmetric, has trace 4 and determinant 3, and that its off-diagonal entry is smaller than that of A. Hence estimate how many steps are needed to make the off-diagonal entry smaller than 10−3.

Solution. The columns are a1=(2,1) and a2=(1,2). Then r11=5, q1=15(2,1), r12=⟨a2,q1⟩=4/5, and w2=(1,2)−45(2,1)=35(−1,2),r22=35,q2=15(−1,2). So Q=15(2−112),R=15(5403), and A(2)=RQ=15(5403)(2−112)=15(14336). It is symmetric; its trace is 20/5=4=trA; its determinant is (84−9)/25=3=detA. The off-diagonal entry fell from 1 to 3/5.

The eigenvalues are 3 and 1, so Theorem 24.5.3 gives the asymptotic factor t=1/3 per step. To take 3/5 below 10−3 needs (1/3)m≤10−3/(3/5), that is m≥log⁡(600)/log⁡3≈5.8: about six further steps, so seven in all. (The first steps are a little slower than the asymptotic rate, so eight is a safer count.)

Exercise (B2: Fixed points)

Determine which of the following matrices are fixed points of the unshifted QR iteration, that is, satisfy A(2)=A(1). Justify your answer; for those that are not, name what changes.

  • (a) any upper triangular A with positive real diagonal entries;
  • (b) any unitary A;
  • (c) A=(0110);
  • (d) any normal A.

Solution.

  • (a) Yes. Then A=IA is a factorization with I unitary and A upper triangular with positive diagonal, hence the unique one (Theorem 11.8.1), and A(2)=AI=A.

  • (b) Yes. Then A=AI is a factorization with A unitary and I upper triangular with positive diagonal, hence the unique one, and A(2)=IA=A.

  • (c) Yes, by (b): the matrix is a permutation matrix, so its columns are orthonormal. This is worth noticing because its eigenvalues are 1 and −1, of equal modulus — another instance of the obstruction of Example (The unshifted algorithm on a rotation), and this one is symmetric, so unlike the rotation it is orthogonally similar to a diagonal matrix. The unshifted iteration simply will not find it.

  • (d) No. A normal matrix need not be fixed: A=(2112) is symmetric, hence normal, and Exercise (B1: One step by hand) computed A(2)=15(14336)≠A. What is preserved is normality, not the matrix: A(2)=Q∗AQ is unitarily similar to A, and normality is invariant under unitary similarity.

Exercise (B3: A shift that deflates)

Let Z=(1234). Take μ to be either eigenvalue of Z and carry out one shifted QR step. Verify the conclusion of Proposition 24.5.5. Hint: you need only the last row of R.

Solution. The characteristic polynomial is x2−5x−2, with roots μ±=(5±33)/2. Every 2×2 matrix is upper Hessenberg, and the single subdiagonal entry 3 is non-zero, so Proposition 24.5.5 applies with n=2. Take μ=μ+. Then Z−μI=(1−μ234−μ) is singular, of rank 1 since it is non-zero. Its first column has norm r=(1−μ)2+9≠0, so a QR factorization has q1=1r(1−μ,3) and r11=r≠0. Because the rank is 1, the second column of R is a multiple of e1, so r22=0 and the last row of R vanishes. Then the last row of RQ vanishes too, and Z′=RQ+μI has last row (0,μ). Its (1,1) entry is then trZ−μ=5−μ=μ−, since the trace is preserved. One step produced both eigenvalues exactly.

C. Going deeper

Exercise (C1: Hessenberg form is not enough by itself)
  • (a) Prove that if Z is upper Hessenberg with zm+1,m=0 for some 1≤m≤n−1, then spec(Z)=spec(Z11)∪spec(Z22), where Z11 is the leading m×m block and Z22 the trailing (n−m)×(n−m) block.
  • (b) Deduce that a QR implementation may, at every step, replace the problem by two smaller ones as soon as one subdiagonal entry vanishes.
  • (c) Give a 3×3 upper Hessenberg matrix with no zero subdiagonal entry for which the unshifted iteration never reduces any subdiagonal entry at all.

Solution.

  • (a) With zm+1,m=0 and Z upper Hessenberg, every entry zij with i>m≥j vanishes: for i>m+1 this is i>j+1, and for i=m+1 it is either j<m, again i>j+1, or j=m, the assumed entry. So Z is block upper triangular with diagonal blocks Z11 and Z22. By Theorem 8.1.1 and the determinant of a block triangular matrix (Theorem 7.8.4), pZ(x)=pZ11(x)pZ22(x), so the eigenvalues of Z are those of the two blocks together.

  • (b) The two blocks are again upper Hessenberg, and by (a) computing their spectra computes that of Z. Each step on a block of size m costs about 6m2 rather than 6n2 (Proposition 24.5.4), so splitting is a strict gain; and part (a) guarantees no eigenvalue is lost. This is deflation.

  • (c) Take the cyclic permutation matrix Z=(001100010), which is upper Hessenberg with subdiagonal entries 1,1, and is orthogonal. By Exercise (B2: Fixed points) (b) it is a fixed point of the unshifted iteration, so no subdiagonal entry ever moves. Its eigenvalues are the three cube roots of 1, all of modulus 1 — the obstruction of Theorem 24.5.3 in its purest form.

Exercise (C2: Hermitian iterates and the Rayleigh quotient)

Let A∈Mn(C) be Hermitian and let A(k) be its unshifted QR iterates.

  • (a) Prove that every A(k) is Hermitian with the same eigenvalues as A.
  • (b) Prove that ann(k)=RA(un(k)), where un(k) is the last column of Uk−1 and RA is the Rayleigh quotient of Definition 17.1.1.
  • (c) Hence explain, citing Theorem 20.6.1, why the Rayleigh shift μk=ann(k) is a certified eigenvalue estimate, and say what the certificate is.

Solution.

  • (a) By Theorem 24.5.2, A(k)=Uk−1∗AUk−1, with U0=I at k=1, so (A(k))∗=Uk−1∗A∗Uk−1=A(k), and unitary similarity preserves eigenvalues.

  • (b) Writing un=Uk−1en, which is a unit vector since Uk−1 is unitary, ann(k)=en∗A(k)en=en∗Uk−1∗AUk−1en=un∗Aun=RA(un), the last equality because RA(x)=x∗Ax/x∗x and un∗un=1.

  • (c) Put μ=ann(k) and r=Aun−μun. Then μ is real, A being Hermitian, and Theorem 20.6.1 says that A has an eigenvalue in [μ−‖r‖2,μ+‖r‖2]. The certificate is ‖r‖2, and it costs nothing extra: by the computation in (b), Uk−1∗r=A(k)en−μen is the last column of A(k) with its diagonal entry removed, so ‖r‖2 is the Euclidean norm of the entries of that column other than the diagonal one. If A was first reduced to Hessenberg form, so that every A(k) is Hermitian and upper Hessenberg, hence tridiagonal, that norm is the single entry |an−1,n(k)|. The algorithm is already watching that number.

Exercise (C3: Why the powers are the right object)

Let A∈Mn(C) be invertible, with unshifted QR iterates as in Definition 24.5.1.

  • (a) Prove that for 1≤j≤n, the subspace spanned by the first j columns of Uk equals Ak(span(e1,…,ej)).
  • (b) Deduce that if the first j columns of Uk converge to a basis of an A-invariant subspace W, then the entries of A(k+1) in rows j+1,…,n of columns 1,…,j tend to 0.

Hint for (b): write the entries as inner products of A applied to one column against another.

Solution.

  • (a) By Theorem 24.5.2, Ak=UkTk with Tk upper triangular and invertible (Quick check above), so Akei=UkTkei lies in span(Uke1,…,Ukei) for each i, since Tkei has zeros below row i. Hence Ak(span(e1,…,ej))⊆span(Uke1,…,Ukej). Both sides have dimension j: the left because Ak is invertible, the right because the columns of a unitary matrix are independent. One inclusion plus equal dimension gives equality.

  • (b) Write ui=Ukei. For p>j≥q, apq(k+1)=ep∗Uk∗AUkeq=up∗Auq=⟨Auq,up⟩. Suppose u1,…,uj converge to an orthonormal basis w1,…,wj of an A-invariant subspace W, let P be the orthogonal projection onto W (Definition 11.3.2) and put δk=maxq≤j‖uq−wq‖2, so δk→0. Since Awq∈W, we have (I−P)Awq=0 and hence ‖(I−P)Auq‖2=‖(I−P)A(uq−wq)‖2≤‖A‖2δk. Since ⟨up,uq⟩=0 for q≤j<p, we have |⟨up,wq⟩|=|⟨up,wq−uq⟩|≤δk by Cauchy–Schwarz (Theorem 11.1.5), so ‖Pup‖2≤jδk. Splitting up and using that P is self-adjoint, |⟨Auq,up⟩|=|⟨(I−P)Auq,up⟩+⟨Auq,Pup⟩|≤‖(I−P)Auq‖2+‖A‖2‖Pup‖2 ≤ (1+j)‖A‖2δk, by Cauchy–Schwarz again and ‖up‖2=‖uq‖2=1. The right-hand side tends to 0, so apq(k+1)→0. This is Theorem 24.5.3 for j=1, read as a statement about invariant subspaces rather than about eigenvectors, and it is the form in which the general convergence theorem quoted above is proved.

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.