The
QR decomposition (or factorization)
is an algorithm that converts a given matrix into a product
of an orthogonal matrix
and a right
or upper triangular matrix
with
. In the
following we consider two methods for the QR decomposition.
We first construct a Householder matrix based on the
first column vector
of
, by which
will
be converted into a vector with its last
elements equal to
zero:
| (64) |
| (65) |
| (66) |
| (67) |
| (68) |
| (69) |
| (70) |
To find the complexity of this algorithm, we note that the Householder
transformation of a column vector is , which is needed for all
columns of a submatrix in each of the iterations. Therefore the total
complexity is
. However, if
is a Hessenberg matrix
(or more specially a tridiagonal matrix), then the Householder
transformation of each column vector is constant
(for the only
subdiagonal component), and the complexity becomes
.
Note that this method cannot convert into a diagonal matrix,
by performing Householder transformations on the rows (from the right)
as well as on the columns (from the left), similar to the
tridiagonalization of a symmetric matrix previously considered. This
is because while post-multiplying a Householder matrix to convert a row,
the column already converted by pre-multiplying a Householder matrix will
be changed again.
The QR decomposition of can also be obtained by converting
the
column vectors in
,
assumed to be independent, into a set of
orthonormal vectors
, which form the columns of the
orthogonal matrix
.
We first find
as the normalized
version of the first column of
, and then find each of the
remaining orthogonal vector
(
), with all
previous
already normalized:
| (71) |
| (72) |
| (73) |
| (74) |
The complexity for computing and
is
, and
the total complexity of this algorithm is
.
The QR decomposition finds many applications, such as solving a linear
system
:
| (75) |
| (76) |
More importantly, the QR decomposition is the essential part of the QR algorithm for solving the eigenvalue problem of a general matrix, to be considered in the following section.
The Matlab code listed below carries out the QR decomposition by both the Householder transformation and the Gram-Schmidt method:
function [Q A]=QR_Householder(A) % QR decomposition by Householder transformation
[m n]=size(A);
Q=eye(m);
for i=1:n-1 % for all n columns of A
e=zeros(n+1-i,1);
e(1)=1;
a=A(i:n,i); % first column of lower-right block of A
u=a-norm(a)*e;
v=u/norm(u);
P=eye(n);
P(i:n,i:n)=P(i:n,i:n)-2*v*v'; % Householder matrix
A=P*A;
Q=Q*P;
end
end
function [Q R]=QR_GramSchmidt(A) % QR decomposition by Gram-Schmidt method
[m n]=size(A);
Q=zeros(m,n);
R=zeros(n);
R(1,1)=norm(A(:,1));
Q(:,1)=A(:,1)/R(1,1);
for j=2:n
Q(:,j)=A(:,j);
for i=1:j-1
Q(:,j)=Q(:,j)-A(:,j)'*Q(:,i)*Q(:,i);
R(i,j)=A(:,j)'*Q(:,i);
end
R(j,j)=norm(Q(:,j));
Q(:,j)=Q(:,j)/norm(Q(:,j));
end
end