EEP311L Chapter 17 The QR Method
EEP311L Chapter 17 The QR Method
Numerical Methods
and Analysis LAB
Linear Algebra
CHAPTER 17: The QR Method*
The QR Method*
The Power Method and Inverse Power
Method each give us only one eigenvalue-
eigenvector pair. While both of these
methods can be modified to give more
eigenvalues and eigenvectors, there is a
better method for obtaining all the
eigenvalues called the QR method. This is
the basis of all modern eigenvalue
software, including Matlab.
The QR Method*
The QR method uses the fact that any
square matrix has a QR decomposition. That
is, for any A there are matrices Q and R
such the A = QR where Q has the property
Q −1 = Q ‘
and R is upper triangular. A matrix Q with the
property that its transpose equals its inverse is
called an orthogonal matrix, because its
column vectors are mutually orthogonal.
The QR Method*
The QR method consists of iterating
following steps:
Transform A into a tridiagonal matrix H.
Decompose H in QR.
Multiply Q and R together in reverse
order to form a new H.
The diagonal of H will converge to the
eigenvalues.
The QR Method*
The details of what makes this method converge are
beyond the scope of our discussion. However, we note
the following theory behind it for those with more
familiarity with linear algebra.
First the Hessian matrix H is obtained from A by a series of
similarity transformation, thus it has the same eigenvalues
as A.
Secondly, if we denote by H0, H1, H2, . . ., the sequence of
matrices produced by the iteration, then
Hi+1 = RiQi = Q −1 i QiRiQi = Q ‘ iHiQi .
Thus each Hi+1 is a related to Hi by an (orthogonal) similarity
transformation and so they have the same eigenvalues as
A.
The QR Method*
There is a built-in QR decomposition in
Matlab which is called with the
command: [Q R] = qr(A). Thus the
following program implements QR
method until it converges:
The QR Method*
function [E , steps ] = myqrmethod ( A )
% Computes all the eigenvalues of a matrix using the QR method .
% Input : A -- square matrix
% Outputs : E -- vector of eigenvalues
% steps -- the number of iterations it took
[ m n ] = size ( A );
if m ~= n
warning ( ’ The input matrix is not square . ’)
return
end
% Set up initial estimate
H = hess ( A );
E = diag ( H );
change = 1;
steps = 0;
% loop while estimate changes
The QR Method*
while change > 0
Eold = E ;
% apply QR method
[ Q R ] = qr( H );
H = R * Q ;
E = diag ( H );
% test change
change = norm ( E - Eold );
steps = steps +1;
end
end
As you can see the main steps of the program are very simple. The
really hard calculations are contained in the built-in commands
hess(A) and qr(H).
The QR Method*
Run this program and compare the results with Matlab’s
built in command:
>> format long
>> format compact
>> A = hilb (5)
>> [ Eqr , steps ] = myqrmethod ( A )
>> Eml = eig ( A )
>> diff = norm ( Eml - flipud ( Eqr ))