In numerical linear algebra, the QR algorithm or QR iteration is an eigenvalue algorithm: that is, a procedure to calculate the eigenvalues and eigenvectors of a matrix. The QR algorithm was developed in the late 1950s by John G. F. Francis and by Vera N. Kublanovskaya, working independently.J.G.F. Francis, "The QR Transformation, I", The Computer Journal, 4(3), pages 265–271 (1961, received October 1959). doi:10.1093/comjnl/4.3.265Vera N. Kublanovskaya, "On some algorithms for the solution of the complete eigenvalue problem," USSR Computational Mathematics and Mathematical Physics, vol. 1, no. 3, pages 637–657 (1963, received Feb 1961). Also published in: Zhurnal Vychislitel'noi Matematiki i Matematicheskoi Fiziki, vol.1, no. 4, pages 555–570 (1961). doi:10.1016/0041-5553(63)90168-X The basic idea is to perform a QR decomposition, writing the matrix as a product of an orthogonal matrix and an upper triangular matrix, multiply the factors in the reverse order, and iterate.

Practical QR algorithm Formally, let be a real matrix of which we want to compute the eigenvalues, and let . At the -th step (starting with ), we compute the QR decomposition where is an orthogonal matrix (i.e., ) and is an upper triangular matrix. We then form . Note that

so all the are similar and hence they have the same eigenvalues. The algorithm is numerically stable because it proceeds by orthogonal similarity transforms.

Under certain conditions, the matrices Ak converge to a triangular matrix, the Schur form of A. The eigenvalues of a triangular matrix are listed on the diagonal, and the eigenvalue problem is solved. In testing for convergence it is impractical to require exact zeros, but the Gershgorin circle theorem provides a bound on the error.

If the matrices converge, then the eigenvalues along the diagonal will appear according to their geometric multiplicity. To guarantee convergence, must be a symmetric matrix, and for all non zero eigenvalues there must not be a corresponding eigenvalue . Due to the fact that a single QR iteration has a cost of and the convergence is linear, the standard QR algorithm is extremely expensive to compute, especially considering it is not guaranteed to converge.

Using Hessenberg form In the above crude form the iterations are relatively expensive. This can be mitigated by first bringing the matrix to upper Hessenberg form (which costs arithmetic operations using a technique based on Householder reduction), with a finite sequence of orthogonal similarity transforms, somewhat like a two-sided QR decomposition. (For QR decomposition, the Householder reflectors are multiplied only on the left, but for the Hessenberg case they are multiplied on both left and right.) Determining the QR decomposition of an upper Hessenberg matrix costs arithmetic operations. Moreover, because the Hessenberg form is already nearly upper-triangular (it has just one nonzero entry below each diagonal), using it as a starting point reduces the number of steps required for convergence of the QR algorithm.

If the original matrix is symmetric, then the upper Hessenberg matrix is also symmetric and thus tridiagonal, and so are all the . In this case reaching Hessenberg form costs arithmetic operations using a technique based on Householder reduction. Determining the QR decomposition of a symmetric tridiagonal matrix costs operations.

Iteration phase If a Hessenberg matrix has element for some , i.e., if one of the elements just below the diagonal is in fact zero, then it decomposes into blocks whose eigenproblems may be solved separately; an eigenvalue is either an eigenvalue of the submatrix of the first rows and columns, or an eigenvalue of the submatrix of remaining rows and columns. The purpose of the QR iteration step is to shrink one of these elements so that effectively a small block along the diagonal is split off from the bulk of the matrix. In the case of a real eigenvalue that is usually the block in the lower right corner (in which case element holds that eigenvalue), whereas in the case of a pair of conjugate complex eigenvalues it is the block in the lower right corner.

The rate of convergence depends on the separation between eigenvalues, so a practical algorithm will use shifts, either explicit or implicit, to increase separation and accelerate convergence. A typical symmetric QR algorithm isolates each eigenvalue (then reduces the size of the matrix) with only one or two iterations, making it efficient as well as robust.

Single iteration with explicit shift The steps of a QR iteration with explicit shift on a real Hessenberg matrix are: Pick a shift and subtract it from all diagonal elements, producing the matrix . A basic strategy is to use , but there are more refined strategies that would further accelerate convergence. The idea is that should be close to an eigenvalue, since making this shift will accelerate convergence to that eigenvalue. Perform a sequence of Givens rotations on , where acts on rows and , and is chosen to zero out position of . This produces the upper triangular matrix . The orthogonal factor would be , but it is neither necessary nor efficient to produce that explicitly. Now multiply by the Givens matrices , , ..., on the right, where instead acts on columns and . This produces the matrix , which is again on Hessenberg form. Finally undo the shift by adding to all diagonal entries. The result is . Since commutes with , we have that . The purpose of the shift is to change which Givens rotations are chosen.

In more detail, the structure of one of these matrices are

where the in the upper left corner is an identity matrix, and the two scalars and are determined by what rotation angle is appropriate for zeroing out position . It is not necessary to exhibit ; the factors and can be determined directly from elements in the matrix should act on. Nor is it necessary to produce the whole matrix; multiplication (from the left) by only affects rows and , so it is easier to just update those two rows in place. Likewise, for the Step 3 multiplication by from the right, it is sufficient to remember , , and .

If using the simple strategy, then at the beginning of Step 2 we have a matrix

where the denotes “could be whatever”. The first Givens rotation zeroes out the position of this, producing

Each new rotation zeroes out another subdiagonal element, thus increasing the number of known zeroes until we are at

The final rotation has chosen so that . If , as is typically the case when we approach convergence, then and . Making this rotation produces

which is our upper triangular matrix. But now we reach Step 3, and need to start rotating data between columns. The first rotation acts on columns and , producing

The expected pattern is that each rotation moves some nonzero value from the diagonal out to the subdiagonal, returning the matrix to Hessenberg form. This ends at

Algebraically the form is unchanged, but numerically the element in position has gotten a lot closer to zero: there used to be a factor gap between it and the diagonal element above, but now the gap is more like a factor , and another iteration would make it factor ; we have quadratic convergence. Practically that means iterations per eigenvalue suffice for convergence, and thus overall we can complete in QR steps, each of which does a mere arithmetic operations (or as little as operations, in the case that is symmetric).

Visualization

The basic QR algorithm can be visualized in the case where A is a positive-definite symmetric matrix. In that case, A can be depicted as an ellipse in 2 dimensions or an ellipsoid in higher dimensions. The relationship between the input to the algorithm and a single iteration can then be depicted as in Figure 1 (click to see an animation). Note that the LR algorithm is depicted alongside the QR algorithm.

A single iteration causes the ellipse to tilt or "fall" towards the x-axis. In the event where the large semi-axis of the ellipse is parallel to the x-axis, one iteration of QR does nothing. Another situation where the algorithm "does nothing" is when the large semi-axis is parallel to the y-axis instead of the x-axis. In that event, the ellipse can be thought of as balancing precariously without being able to fall in either direction. In both situations, the matrix is diagonal. A situation where an iteration of the algorithm "does nothing" is called a fixed point. The strategy employed by the algorithm is iteration towards a fixed-point. Observe that one fixed point is stable while the other is unstable. If the ellipse were tilted away from the unstable fixed point by a very small amount, one iteration of QR would cause the ellipse to tilt away from the fixed point instead of towards. Eventually though, the algorithm would converge to a different fixed point, but it would take a long time.

Finding eigenvalues versus finding eigenvectors

It's worth pointing out that finding even a single eigenvector of a symmetric matrix is not computable (in exact real arithmetic according to the definitions in computable analysis). This difficulty exists whenever the multiplicities of a matrix's eigenvalues are not knowable. On the other hand, the same problem does not exist for finding eigenvalues. The eigenvalues of a matrix are always computable.

We will now discuss how these difficulties manifest in the basic QR algorithm. This is illustrated in Figure 2. Recall that the ellipses represent positive-definite symmetric matrices. As the two eigenvalues of the input matrix approach each other, the input ellipse changes into a circle. A circle corresponds to a multiple of the identity matrix. A near-circle corresponds to a near-multiple of the identity matrix whose eigenvalues are nearly equal to the diagonal entries of the matrix. Therefore, the problem of approximately finding the eigenvalues is shown to be easy in that case. But notice what happens to the semi-axes of the ellipses. An iteration of QR (or LR) tilts the semi-axes less and less as the input ellipse gets closer to being a circle. The eigenvectors can only be known when the semi-axes are parallel to the x-axis and y-axis. The number of iterations needed to achieve near-parallelism increases without bound as the input ellipse becomes more circular.

While it may be impossible to compute the eigendecomposition of an arbitrary symmetric matrix, it is always possible to perturb the matrix by an arbitrarily small amount and compute the eigendecomposition of the resulting matrix. In the case when the matrix is depicted as a near-circle, the matrix can be replaced with one whose depiction is a perfect circle. In that case, the matrix is a multiple of the identity matrix, and its eigendecomposition is immediate. Be aware though that the resulting eigenbasis can be quite far from the original eigenbasis.

Speeding up: Shifting and deflation The slowdown when the ellipse gets more circular has a converse: It turns out that when the ellipse gets more stretched - and less circular - then the rotation of the ellipse becomes faster. Such a stretch can be induced when the matrix which the ellipse represents gets replaced with where is approximately the smallest eigenvalue of . In this case, the ratio of the two semi-axes of the ellipse approaches . In higher dimensions, shifting like this makes the length of the smallest semi-axis of an ellipsoid small relative to the other semi-axes, which speeds up convergence to the smallest eigenvalue, but does not speed up convergence to the other eigenvalues. This becomes useless when the smallest eigenvalue is fully determined, so the matrix must then be deflated, which simply means removing its last row and column.