Skip to content

Chapter 53. QR Factorization

QR factorization writes a matrix as a product

A=QR, A = QR,

where QQ has orthonormal columns and RR is upper triangular. It is the matrix form of Gram-Schmidt orthogonalization. The columns of QQ give an orthonormal basis for the column space of AA, while RR records the coefficients needed to reconstruct the original columns. Standard references define QR decomposition as a factorization of a matrix into an orthogonal or orthonormal factor and an upper triangular factor.

QR factorization is important because it replaces a possibly awkward basis by an orthonormal basis. This improves geometric clarity and numerical stability. It is used for least squares, eigenvalue algorithms, rank estimation, and many stable matrix computations.

53.1 The Factorization

Let

ARm×n,mn. A\in\mathbb{R}^{m\times n}, \qquad m\ge n.

Assume the columns of AA are linearly independent. A reduced QR factorization of AA is

A=QR, A=QR,

where

QRm×n,RRn×n. Q\in\mathbb{R}^{m\times n}, \qquad R\in\mathbb{R}^{n\times n}.

The columns of QQ are orthonormal:

QTQ=In. Q^TQ=I_n.

The matrix RR is upper triangular:

R=[r11r12r1n0r22r2n00rnn]. R= \begin{bmatrix} r_{11} & r_{12} & \cdots & r_{1n}\\ 0 & r_{22} & \cdots & r_{2n}\\ \vdots & \vdots & \ddots & \vdots\\ 0 & 0 & \cdots & r_{nn} \end{bmatrix}.

When the diagonal entries of RR are chosen positive, the reduced QR factorization is unique for a full-column-rank matrix.

53.2 Full and Reduced QR

There are two common forms.

The reduced QR factorization is

A=Q1R1, A=Q_1R_1,

where

Q1Rm×n,R1Rn×n. Q_1\in\mathbb{R}^{m\times n}, \qquad R_1\in\mathbb{R}^{n\times n}.

The columns of Q1Q_1 form an orthonormal basis for Col(A)\operatorname{Col}(A).

The full QR factorization is

A=QR, A=QR,

where

QRm×m Q\in\mathbb{R}^{m\times m}

is orthogonal and

RRm×n R\in\mathbb{R}^{m\times n}

has the block form

R=[R10]. R= \begin{bmatrix} R_1\\ 0 \end{bmatrix}.

Thus

A=[Q1Q2][R10]=Q1R1. A = \begin{bmatrix} Q_1 & Q_2 \end{bmatrix} \begin{bmatrix} R_1\\ 0 \end{bmatrix} = Q_1R_1.

The reduced factorization is usually enough for least squares and column-space computations. The full factorization is useful when a complete orthonormal basis of Rm\mathbb{R}^m is needed.

53.3 Column Interpretation

Write the columns of AA as

A=[a1a2an]. A= \begin{bmatrix} | & | & & |\\ a_1 & a_2 & \cdots & a_n\\ | & | & & | \end{bmatrix}.

Write the columns of QQ as

Q=[q1q2qn]. Q= \begin{bmatrix} | & | & & |\\ q_1 & q_2 & \cdots & q_n\\ | & | & & | \end{bmatrix}.

The equation

A=QR A=QR

means that each column aja_j is a linear combination of the first jj columns of QQ:

aj=r1jq1+r2jq2++rjjqj. a_j = r_{1j}q_1+r_{2j}q_2+\cdots+r_{jj}q_j.

There are no terms involving qj+1,,qnq_{j+1},\ldots,q_n because RR is upper triangular.

Thus RR records how the original columns of AA are expressed in the orthonormal basis q1,,qnq_1,\ldots,q_n.

53.4 Relation to Gram-Schmidt

QR factorization is obtained by applying Gram-Schmidt to the columns of AA.

Let

a1,,an a_1,\ldots,a_n

be the columns of AA. Gram-Schmidt produces orthonormal vectors

q1,,qn. q_1,\ldots,q_n.

For each jj, the vector aja_j lies in

span(q1,,qj). \operatorname{span}(q_1,\ldots,q_j).

Therefore

aj=r1jq1++rjjqj. a_j = r_{1j}q_1+\cdots+r_{jj}q_j.

The coefficient

rij r_{ij}

is given by

rij=qiTaj r_{ij}=q_i^Ta_j

for iji\le j. The diagonal coefficient is

rjj=uj2, r_{jj}=\|u_j\|_2,

where uju_j is the orthogonal residual produced by Gram-Schmidt at step jj.

Putting these column equations together gives

A=QR. A=QR.

53.5 Computing RR from QQ

If

A=QR A=QR

and

QTQ=I, Q^TQ=I,

then multiplying on the left by QTQ^T gives

QTA=QTQR. Q^TA=Q^TQR.

Since

QTQ=I, Q^TQ=I,

we obtain

R=QTA. R=Q^TA.

Thus, once QQ is known, RR is obtained by taking inner products between the columns of QQ and the columns of AA.

Entrywise,

rij=qiTaj. r_{ij}=q_i^Ta_j.

For a proper QR factorization, these entries vanish below the diagonal:

rij=0when i>j. r_{ij}=0 \qquad \text{when } i>j.

This expresses the same orthogonality created by Gram-Schmidt.

53.6 Example

Let

A=[1110]. A= \begin{bmatrix} 1 & 1\\ 1 & 0 \end{bmatrix}.

The columns are

a1=[11],a2=[10]. a_1= \begin{bmatrix} 1\\ 1 \end{bmatrix}, \qquad a_2= \begin{bmatrix} 1\\ 0 \end{bmatrix}.

First,

r11=a12=2, r_{11}=\|a_1\|_2=\sqrt{2},

so

q1=a1r11=12[11]. q_1= \frac{a_1}{r_{11}} = \frac{1}{\sqrt{2}} \begin{bmatrix} 1\\ 1 \end{bmatrix}.

Next,

r12=q1Ta2=12. r_{12}=q_1^Ta_2 = \frac{1}{\sqrt{2}}.

Remove the component of a2a_2 in the q1q_1 direction:

u2=a2r12q1. u_2=a_2-r_{12}q_1.

Thus

u2=[10]12[11]=[1/21/2]. u_2= \begin{bmatrix} 1\\ 0 \end{bmatrix} - \frac{1}{2} \begin{bmatrix} 1\\ 1 \end{bmatrix} = \begin{bmatrix} 1/2\\ -1/2 \end{bmatrix}.

Then

r22=u22=12, r_{22}=\|u_2\|_2 = \frac{1}{\sqrt{2}},

and

q2=u2r22=12[11]. q_2= \frac{u_2}{r_{22}} = \frac{1}{\sqrt{2}} \begin{bmatrix} 1\\ -1 \end{bmatrix}.

Therefore

Q=12[1111], Q= \frac{1}{\sqrt{2}} \begin{bmatrix} 1 & 1\\ 1 & -1 \end{bmatrix},

and

R=[21/201/2]. R= \begin{bmatrix} \sqrt{2} & 1/\sqrt{2}\\ 0 & 1/\sqrt{2} \end{bmatrix}.

Indeed,

QR=12[1111][21/201/2]=[1110]. QR = \frac{1}{\sqrt{2}} \begin{bmatrix} 1 & 1\\ 1 & -1 \end{bmatrix} \begin{bmatrix} \sqrt{2} & 1/\sqrt{2}\\ 0 & 1/\sqrt{2} \end{bmatrix} = \begin{bmatrix} 1 & 1\\ 1 & 0 \end{bmatrix}.

53.7 QR and Least Squares

QR factorization gives a stable way to solve least squares problems.

Consider

minxAxb2. \min_x \|Ax-b\|_2.

Assume

A=QR, A=QR,

where QQ has orthonormal columns and RR is invertible upper triangular.

Then

Ax=QRx. Ax=QRx.

The least squares solution satisfies

Rx^=QTb. R\hat{x}=Q^Tb.

Thus

x^=R1QTb. \hat{x}=R^{-1}Q^Tb.

In computation, one solves

Rx^=QTb R\hat{x}=Q^Tb

by back substitution. One does not form R1R^{-1} explicitly.

This method avoids solving the normal equations

ATAx^=ATb. A^TA\hat{x}=A^Tb.

That matters because forming ATAA^TA squares the condition number in the Euclidean norm, while QR methods avoid this condition-number-squaring effect.

53.8 Projection Using QR

If A=QRA=QR and AA has full column rank, then

Col(A)=Col(Q). \operatorname{Col}(A)=\operatorname{Col}(Q).

The orthogonal projection of bb onto Col(A)\operatorname{Col}(A) is therefore

p=QQTb. p=QQ^Tb.

The residual is

r=bp=bQQTb. r=b-p=b-QQ^Tb.

The least squares fitted vector is

Ax^=p. A\hat{x}=p.

Because QQ has orthonormal columns, this projection formula is simpler than

p=A(ATA)1ATb. p=A(A^TA)^{-1}A^Tb.

QR factorization replaces the original column basis by an orthonormal basis, making projection direct.

53.9 Solving Square Linear Systems

If ARn×nA\in\mathbb{R}^{n\times n} is nonsingular and

A=QR, A=QR,

then the system

Ax=b Ax=b

becomes

QRx=b. QRx=b.

Multiply by QTQ^T:

Rx=QTb. Rx=Q^Tb.

Since RR is upper triangular, xx is found by back substitution.

This gives an alternative to Gaussian elimination. QR is often more expensive than LU factorization for square systems, but it has better orthogonality properties and is useful when stability is important.

53.10 Classical Gram-Schmidt QR

Classical Gram-Schmidt computes QQ and RR by projecting each column of AA onto all previously computed qiq_i.

For j=1,,nj=1,\ldots,n, set

uj=aj. u_j=a_j.

For i=1,,j1i=1,\ldots,j-1, compute

rij=qiTaj. r_{ij}=q_i^Ta_j.

Then subtract

uj=aji=1j1rijqi. u_j = a_j-\sum_{i=1}^{j-1}r_{ij}q_i.

Finally,

rjj=uj2,qj=ujrjj. r_{jj}=\|u_j\|_2, \qquad q_j=\frac{u_j}{r_{jj}}.

This method is conceptually simple. In exact arithmetic it produces a valid QR factorization. In floating point arithmetic it can lose orthogonality when the columns of AA are nearly linearly dependent.

53.11 Modified Gram-Schmidt QR

Modified Gram-Schmidt improves numerical behavior by subtracting projections from the current residual rather than from the original column.

For each column aja_j, begin with

u=aj. u=a_j.

For i=1,,j1i=1,\ldots,j-1, compute

rij=qiTu, r_{ij}=q_i^Tu,

then update

uurijqi. u \leftarrow u-r_{ij}q_i.

After all previous directions have been removed,

rjj=u2,qj=urjj. r_{jj}=\|u\|_2, \qquad q_j=\frac{u}{r_{jj}}.

Classical and modified Gram-Schmidt are equivalent in exact arithmetic. In finite precision arithmetic, modified Gram-Schmidt usually preserves orthogonality better.

53.12 Householder QR

Householder QR uses orthogonal reflections to zero out subdiagonal entries of a matrix.

A Householder reflector has the form

H=I2vvT, H=I-2vv^T,

where

v2=1. \|v\|_2=1.

It is orthogonal:

HTH=I. H^TH=I.

It is also symmetric:

HT=H. H^T=H.

By choosing vv appropriately, a Householder reflector transforms a vector into a multiple of a coordinate vector. Applied successively to columns of AA, these reflectors produce an upper triangular matrix RR. The product of the reflectors gives the orthogonal factor QQ. Householder transformations are a standard stable method for computing QR factorization.

53.13 Givens QR

Givens rotations compute QR factorization by zeroing individual subdiagonal entries.

A Givens rotation acts on two coordinates at a time. In the plane of those two coordinates, it has the form

[cssc], \begin{bmatrix} c & s\\ -s & c \end{bmatrix},

where

c2+s2=1. c^2+s^2=1.

By choosing cc and ss correctly, one can eliminate a chosen entry while preserving the Euclidean norm.

Givens rotations are especially useful for sparse matrices and for problems where entries are introduced or removed incrementally. They can zero selected entries without applying a dense transformation to the whole matrix. QR factorization can be computed by a sequence of Givens rotations.

53.14 Comparison of QR Methods

MethodMain ideaStrengthWeakness
Classical Gram-SchmidtSubtract projections from original columnsSimple theoryCan lose orthogonality
Modified Gram-SchmidtSubtract projections from current residualsBetter numerical behaviorStill less stable than Householder
Householder reflectionsZero whole column tails by reflectionsStable dense QRLess convenient for selective updates
Givens rotationsZero one entry at a timeGood for sparse and incremental problemsMore rotations for dense matrices

All methods produce the same mathematical kind of factorization. Their differences matter in floating point arithmetic and large-scale computation.

53.15 Rank-Deficient Matrices

If the columns of AA are linearly dependent, then the reduced QR factorization with invertible RR does not exist.

Gram-Schmidt will produce a zero residual at some step:

rjj=0. r_{jj}=0.

This means the current column adds no new direction beyond the previous columns.

For rank-deficient matrices, one may use QR factorization with column pivoting:

AP=QR, AP=QR,

where PP is a permutation matrix. Pivoting reorders the columns so that the more independent columns appear earlier.

This form is useful for detecting numerical rank and constructing rank-revealing factorizations. QR methods can be used for numerical rank estimation at lower cost than a full singular value decomposition in some settings.

53.16 Positive Diagonal Convention

The signs of the columns of QQ are not fixed by orthonormality alone.

If

A=QR, A=QR,

then changing the sign of a column qjq_j and the sign of the corresponding row of RR gives another valid factorization.

To remove this ambiguity, one often requires

rjj>0 r_{jj}>0

for all jj. Under full column rank, this convention gives uniqueness for the reduced QR factorization.

53.17 Complex QR Factorization

For a complex matrix

ACm×n, A\in\mathbb{C}^{m\times n},

QR factorization has the form

A=QR, A=QR,

where QQ has orthonormal columns in the complex inner product and RR is upper triangular.

The orthonormality condition becomes

QQ=I, Q^*Q=I,

where QQ^* is the conjugate transpose.

The coefficients are

rij=qiaj. r_{ij}=q_i^*a_j.

If QQ is square, it is unitary:

QQ=QQ=I. Q^*Q=QQ^*=I.

Complex QR appears in spectral theory, signal processing, quantum mechanics, and numerical algorithms for complex matrices.

53.18 QR and Orthogonal Changes of Coordinates

The equation

A=QR A=QR

can be rewritten as

QTA=R. Q^TA=R.

Thus QTQ^T applies an orthogonal change of coordinates to the columns of AA, turning the matrix into upper triangular form.

Because QQ is orthogonal, this change of coordinates preserves lengths and angles:

QTx2=x2. \|Q^Tx\|_2=\|x\|_2.

This explains the numerical value of QR. It transforms the problem while preserving Euclidean geometry.

53.19 QR Algorithm Preview

QR factorization is also the basis of the QR algorithm for eigenvalues.

Given a square matrix A0A_0, one forms

Ak=QkRk, A_k=Q_kR_k,

then reverses the factors:

Ak+1=RkQk. A_{k+1}=R_kQ_k.

Under suitable hypotheses and with shifts, this iteration reveals eigenvalue information. The QR algorithm is one of the central methods for computing eigenvalues of dense matrices. QR decomposition is widely used both for least squares and as the basis of the QR eigenvalue algorithm.

53.20 Summary

QR factorization writes a matrix as

A=QR. A=QR.

The matrix QQ has orthonormal columns:

QTQ=I. Q^TQ=I.

The matrix RR is upper triangular.

The columns of QQ form an orthonormal basis for the column space of AA. The matrix RR records the coordinates of the original columns of AA in that basis.

QR factorization is the matrix form of Gram-Schmidt. It gives stable methods for least squares, projections, and linear systems. It can be computed by Gram-Schmidt, Householder reflections, or Givens rotations. Its central advantage is that it uses orthogonal transformations, which preserve Euclidean geometry and avoid the conditioning problems caused by forming ATAA^TA.