Tutorials › Linear Algebra › Uniqueness And Sign Choices In QR Factorization

Least Squares and QR Factorization · Tutorial 704 of 1000

Uniqueness And Sign Choices In QR Factorization

Learn why positive diagonal entries fix the signs in a reduced QR factorization, and how diagonal sign changes produce every alternative.

Intermediate 10 min read

What You'll Learn

  • State the dimensions and defining conditions of a reduced QR factorization.
  • Prove uniqueness when the upper-triangular factor has positive diagonal entries.
  • Describe how diagonal sign matrices change the columns of Q and rows of R.
  • Prove that all reduced QR factorizations of a full-column-rank matrix differ only by these sign choices.
  • Verify the product and orthonormal-column conditions in exact examples.
  • Identify the common error of changing Q without making the matching change to R.

What Makes a QR Factorization Unique?

A full-column-rank matrix has a reduced QR factorization in which the columns of \(\mathbf{Q}\) are orthonormal and \(\mathbf{R}\) is upper triangular. The product \(\mathbf{Q}\mathbf{R}\) reconstructs the original matrix. But these conditions alone do not specify the signs of the columns of \(\mathbf{Q}\): reversing a column of \(\mathbf{Q}\) and making a matching change to a row of \(\mathbf{R}\) leaves the product unchanged. Requiring positive diagonal entries in \(\mathbf{R}\) removes that ambiguity. We will prove both the resulting uniqueness and the precise form of the remaining sign choices when positivity is not required.

Throughout, matrices and vectors are real. Let \(\mathbf{A}\in\mathbb{R}^{m\times n}\), where \(m\ge n\). Full column rank means that the columns of \(\mathbf{A}\) are linearly independent. A matrix \(\mathbf{Q}\in\mathbb{R}^{m\times n}\) has orthonormal columns when \(\mathbf{Q}^{\top}\mathbf{Q}=\mathbf{I}_n\). An \(n\times n\) matrix is upper triangular when its entries below the main diagonal are zero.

Definition: A reduced QR factorization of \(\mathbf{A}\in\mathbb{R}^{m\times n}\) is a factorization \(\mathbf{A}=\mathbf{Q}\mathbf{R}\), where \(\mathbf{Q}\in\mathbb{R}^{m\times n}\) has orthonormal columns and \(\mathbf{R}\in\mathbb{R}^{n\times n}\) is upper triangular. A reduced QR factorization has positive diagonal if \(r_{ii}>0\) for \(i=1,\dots,n\).

For a full-column-rank matrix, the diagonal entries of an upper-triangular factor in a reduced QR factorization cannot be zero. Indeed, if \(\mathbf{R}\mathbf{x}=\mathbf{0}\), then \(\mathbf{A}\mathbf{x}=\mathbf{Q}\mathbf{R}\mathbf{x}=\mathbf{0}\). Independence of the columns of \(\mathbf{A}\) forces \(\mathbf{x}=\mathbf{0}\), so the square matrix \(\mathbf{R}\) is invertible. An invertible upper-triangular matrix has nonzero diagonal entries: solving \(\mathbf{R}\mathbf{x}=\mathbf{y}\) from the last row upward would otherwise fail to determine a unique solution at a zero diagonal entry. We will use that such a matrix has an upper-triangular inverse, whose diagonal entries are the reciprocals of those of \(\mathbf{R}\).

Why Positive Diagonal Entries Give Uniqueness

The key observation is that the difference between two candidate factorizations must act on the orthonormal columns by an upper-triangular matrix. Orthonormality then forces that matrix to be a diagonal sign matrix. Positive diagonal entries leave only the identity sign choice.

Lemma: If an upper-triangular matrix \(\mathbf{U}\in\mathbb{R}^{n\times n}\) satisfies \(\mathbf{U}^{\top}\mathbf{U}=\mathbf{I}_n\), then \(\mathbf{U}\) is diagonal and each diagonal entry is \(1\) or \(-1\). If, in addition, every diagonal entry of \(\mathbf{U}\) is positive, then \(\mathbf{U}=\mathbf{I}_n\).

Proof. We prove the claim by induction on \(n\). For \(n=1\), the equation \(u_{11}^2=1\) gives \(u_{11}=1\) or \(u_{11}=-1\), and positivity selects \(u_{11}=1\). Now suppose \(n>1\). The first column of \(\mathbf{U}\) has no nonzero entries below its first entry because \(\mathbf{U}\) is upper triangular. Its squared length is \(1\), since \(\mathbf{U}^{\top}\mathbf{U}=\mathbf{I}_n\). Therefore \(u_{11}^2=1\). For each \(j>1\), the inner product of columns 1 and \(j\) is zero, so \(u_{11}u_{1j}=0\). Since \(u_{11}\ne0\), this gives \(u_{1j}=0\). Thus the first row and first column have no off-diagonal entries. The submatrix formed from rows and columns 2 through \(n\) is upper triangular and also has orthonormal columns, as follows from the corresponding entries of \(\mathbf{U}^{\top}\mathbf{U}=\mathbf{I}_n\). The induction hypothesis shows that this submatrix is diagonal with entries \(1\) or \(-1\). Hence \(\mathbf{U}\) has the claimed form. If all its diagonal entries are positive, they are all \(1\), so \(\mathbf{U}=\mathbf{I}_n\). \(\square\)

Theorem (Uniqueness of positive-diagonal reduced QR): Let \(\mathbf{A}\in\mathbb{R}^{m\times n}\) have full column rank. If \(\mathbf{A}=\mathbf{Q}_1\mathbf{R}_1=\mathbf{Q}_2\mathbf{R}_2\) are reduced QR factorizations and both \(\mathbf{R}_1\) and \(\mathbf{R}_2\) have positive diagonal entries, then \(\mathbf{Q}_1=\mathbf{Q}_2\) and \(\mathbf{R}_1=\mathbf{R}_2\).

Proof. Both triangular matrices are invertible because their diagonal entries are positive. Define \(\mathbf{U}=\mathbf{Q}_2^{\top}\mathbf{Q}_1\). Multiplying the equality \(\mathbf{Q}_1\mathbf{R}_1=\mathbf{Q}_2\mathbf{R}_2\) on the left by \(\mathbf{Q}_2^{\top}\), and using \(\mathbf{Q}_2^{\top}\mathbf{Q}_2=\mathbf{I}_n\), gives \(\mathbf{U}\mathbf{R}_1=\mathbf{R}_2\). Therefore \(\mathbf{U}=\mathbf{R}_2\mathbf{R}_1^{-1}\), which is upper triangular. Also, \[ \mathbf{Q}_1=\mathbf{A}\mathbf{R}_1^{-1} =\mathbf{Q}_2\mathbf{R}_2\mathbf{R}_1^{-1} =\mathbf{Q}_2\mathbf{U}. \] Using the orthonormal columns of \(\mathbf{Q}_1\) and \(\mathbf{Q}_2\), we obtain \[ \mathbf{I}_n=\mathbf{Q}_1^{\top}\mathbf{Q}_1 =\mathbf{U}^{\top}\mathbf{Q}_2^{\top}\mathbf{Q}_2\mathbf{U} =\mathbf{U}^{\top}\mathbf{U}. \] The diagonal entries of \(\mathbf{U}=\mathbf{R}_2\mathbf{R}_1^{-1}\) are \(r_{2,ii}/r_{1,ii}>0\). The lemma gives \(\mathbf{U}=\mathbf{I}_n\). Thus \(\mathbf{Q}_1=\mathbf{Q}_2\), and the original equality then gives \(\mathbf{R}_1=\mathbf{R}_2\). \(\square\)

How Column-Sign Changes Preserve the Product

A diagonal sign matrix is a diagonal matrix \(\mathbf{D}\in\mathbb{R}^{n\times n}\) whose diagonal entries are each \(1\) or \(-1\). It satisfies \(\mathbf{D}^2=\mathbf{I}_n\). Starting from \(\mathbf{A}=\mathbf{Q}\mathbf{R}\), set \(\mathbf{Q}'=\mathbf{Q}\mathbf{D}\) and \(\mathbf{R}'=\mathbf{D}\mathbf{R}\). Multiplication by \(\mathbf{D}\) reverses the selected columns of \(\mathbf{Q}\); multiplying \(\mathbf{R}\) on the left by \(\mathbf{D}\) makes the matching sign changes to its rows.

Theorem (Sign choices in reduced QR): Let \(\mathbf{A}\in\mathbb{R}^{m\times n}\) have full column rank. If \(\mathbf{A}=\mathbf{Q}_1\mathbf{R}_1=\mathbf{Q}_2\mathbf{R}_2\) are reduced QR factorizations, with no sign condition on the diagonals, then there is a diagonal sign matrix \(\mathbf{D}\) such that \(\mathbf{Q}_1=\mathbf{Q}_2\mathbf{D}\) and \(\mathbf{R}_2=\mathbf{D}\mathbf{R}_1\). Conversely, for every diagonal sign matrix \(\mathbf{D}\), \(\mathbf{Q}\mathbf{D}\) and \(\mathbf{D}\mathbf{R}\) give a reduced QR factorization of the same matrix \(\mathbf{A}=\mathbf{Q}\mathbf{R}\).

Proof. For the first assertion, both \(\mathbf{R}_1\) and \(\mathbf{R}_2\) are invertible because \(\mathbf{A}\) has full column rank. Set \(\mathbf{U}=\mathbf{Q}_2^{\top}\mathbf{Q}_1\). As in the previous proof, \(\mathbf{R}_2=\mathbf{U}\mathbf{R}_1\), so \(\mathbf{U}=\mathbf{R}_2\mathbf{R}_1^{-1}\) is upper triangular, and \(\mathbf{Q}_1=\mathbf{Q}_2\mathbf{U}\). Orthonormality gives \(\mathbf{U}^{\top}\mathbf{U}=\mathbf{I}_n\). By the lemma, \(\mathbf{U}\) is diagonal with entries \(1\) or \(-1\); call it \(\mathbf{D}\). The equations become \(\mathbf{Q}_1=\mathbf{Q}_2\mathbf{D}\) and \(\mathbf{R}_2=\mathbf{D}\mathbf{R}_1\). Conversely, \((\mathbf{Q}\mathbf{D})^{\top}(\mathbf{Q}\mathbf{D})=\mathbf{D}\mathbf{I}_n\mathbf{D}=\mathbf{I}_n\), and \(\mathbf{D}\mathbf{R}\) is upper triangular. Their product is \(\mathbf{Q}\mathbf{D}\mathbf{D}\mathbf{R}=\mathbf{Q}\mathbf{R}=\mathbf{A}\). Thus they meet every condition of a reduced QR factorization. \(\square\)

The theorem also counts the possibilities: there are \(2^n\) diagonal sign matrices, one for each choice of signs on \(n\) diagonal entries. Exactly one of these choices makes every diagonal entry of the triangular factor positive. The theorem does not claim that a rank-deficient matrix has the same uniqueness property; its full-column-rank hypothesis is essential to the invertibility used in the proof.

Worked Examples

Worked Example: Construct and Verify a Positive-Diagonal Factorization

Consider the full-column-rank matrix \(\mathbf{A}=\begin{bmatrix}1&1\\1&0\\0&1\end{bmatrix}\). Its columns are \(\mathbf{a}_1=(1,1,0)^{\top}\) and \(\mathbf{a}_2=(1,0,1)^{\top}\). Using Gram–Schmidt, the first column has length \(\sqrt{1^2+1^2+0^2}=\sqrt{2}\), so \(\mathbf{q}_1=(1,1,0)^{\top}/\sqrt{2}\). The first diagonal entry is \(r_{11}=\sqrt{2}>0\). The off-diagonal entry is \(r_{12}=\mathbf{q}_1^{\top}\mathbf{a}_2=(1+0+0)/\sqrt{2}=1/\sqrt{2}\).

Subtract the projection of \(\mathbf{a}_2\) onto \(\mathbf{q}_1\): \(\mathbf{u}_2=\mathbf{a}_2-r_{12}\mathbf{q}_1=(1,0,1)^{\top}-(1/2,1/2,0)^{\top}=(1/2,-1/2,1)^{\top}\). Its squared length is \(1/4+1/4+1=3/2\), so its length is \(\sqrt{6}/2\). Thus \(\mathbf{q}_2=(1,-1,2)^{\top}/\sqrt{6}\) and \(r_{22}=\sqrt{6}/2>0\). The resulting factors are

$$ \mathbf{Q}= \begin{bmatrix} 1/\sqrt{2}&1/\sqrt{6}\\ 1/\sqrt{2}&-1/\sqrt{6}\\ 0&2/\sqrt{6} \end{bmatrix}, \qquad \mathbf{R}= \begin{bmatrix} \sqrt{2}&1/\sqrt{2}\\ 0&\sqrt{6}/2 \end{bmatrix}. $$

To check the columns of \(\mathbf{Q}\), their squared lengths are \(1/2+1/2=1\) and \(1/6+1/6+4/6=1\), while their inner product is \(1/\sqrt{12}-1/\sqrt{12}+0=0\). To check the product, the first column of \(\mathbf{Q}\mathbf{R}\) is \(\sqrt{2}\mathbf{q}_1=(1,1,0)^{\top}\). The second is \((1/\sqrt{2})\mathbf{q}_1+(\sqrt{6}/2)\mathbf{q}_2=(1/2,1/2,0)^{\top}+(1/2,-1/2,1)^{\top}=(1,0,1)^{\top}\). Therefore \(\mathbf{Q}\mathbf{R}=\mathbf{A}\), with positive diagonal entries as required.

Worked Example: Reverse One Column Sign Correctly

Use the factors from the preceding example and choose \(\mathbf{D}=\begin{bmatrix}-1&0\\0&1\end{bmatrix}\). The new factors are \(\mathbf{Q}'=\mathbf{Q}\mathbf{D}\), which reverses the first column of \(\mathbf{Q}\), and \(\mathbf{R}'=\mathbf{D}\mathbf{R}\), which reverses the first row of \(\mathbf{R}\):

$$ \mathbf{Q}'= \begin{bmatrix} -1/\sqrt{2}&1/\sqrt{6}\\ -1/\sqrt{2}&-1/\sqrt{6}\\ 0&2/\sqrt{6} \end{bmatrix}, \qquad \mathbf{R}'= \begin{bmatrix} -\sqrt{2}&-1/\sqrt{2}\\ 0&\sqrt{6}/2 \end{bmatrix}. $$

The first column of \(\mathbf{Q}'\) still has squared length \(1/2+1/2=1\), the second still has squared length \(1\), and their inner product is \(-1/\sqrt{12}+1/\sqrt{12}=0\). For the product, its first column is \((-\sqrt{2})(-\mathbf{q}_1)=(1,1,0)^{\top}\). Its second column is \((-\!1/\sqrt{2})(-\mathbf{q}_1)+(\sqrt{6}/2)\mathbf{q}_2=(1/2,1/2,0)^{\top}+(1/2,-1/2,1)^{\top}=(1,0,1)^{\top}\). Hence \(\mathbf{Q}'\mathbf{R}'=\mathbf{A}\), although the first diagonal entry of \(\mathbf{R}'\) is negative.

Worked Example: Enumerate the Sign Choices for the Identity Matrix

For \(\mathbf{A}=\mathbf{I}_2\), one reduced QR factorization is \(\mathbf{Q}=\mathbf{I}_2\), \(\mathbf{R}=\mathbf{I}_2\). The four diagonal sign matrices give the following four pairs:

$$ \begin{bmatrix}1&0\\0&1\end{bmatrix} \begin{bmatrix}1&0\\0&1\end{bmatrix} =\begin{bmatrix}1&0\\0&1\end{bmatrix}, \qquad \begin{bmatrix}-1&0\\0&1\end{bmatrix} \begin{bmatrix}-1&0\\0&1\end{bmatrix} =\begin{bmatrix}1&0\\0&1\end{bmatrix}. $$
$$ \begin{bmatrix}1&0\\0&-1\end{bmatrix} \begin{bmatrix}1&0\\0&-1\end{bmatrix} =\begin{bmatrix}1&0\\0&1\end{bmatrix}, \qquad \begin{bmatrix}-1&0\\0&-1\end{bmatrix} \begin{bmatrix}-1&0\\0&-1\end{bmatrix} =\begin{bmatrix}1&0\\0&1\end{bmatrix}. $$

In each pair the first factor is \(\mathbf{Q}'=\mathbf{D}\) and the second is \(\mathbf{R}'=\mathbf{D}\). Each \(\mathbf{Q}'\) has orthonormal columns because its diagonal entries have squares equal to \(1\); each \(\mathbf{R}'\) is upper triangular; and each product is \(\mathbf{I}_2\), as the displayed multiplications verify. The sign-choice theorem proves these are all the reduced QR factorizations. Only the first pair has positive diagonal entries in \(\mathbf{R}'\).

Common Mistake: Changing Only One Factor

A sign change must be made in both factors. For the first example, reversing the first column of \(\mathbf{Q}\) but leaving \(\mathbf{R}\) unchanged gives a first product column of \((-\sqrt{2})(\mathbf{q}_1)=(-1,-1,0)^{\top}\), rather than the original \((1,1,0)^{\top}\). The product is no longer \(\mathbf{A}\). The correction is to reverse the corresponding row of \(\mathbf{R}\) as well: \(\mathbf{Q}'=\mathbf{Q}\mathbf{D}\) and \(\mathbf{R}'=\mathbf{D}\mathbf{R}\). Since \(\mathbf{D}^2=\mathbf{I}_n\), the two sign changes cancel in the product.

A second potential confusion is to treat “upper triangular with orthonormal columns” as if it automatically meant the identity. The lemma shows the precise conclusion: the matrix must be diagonal with entries \(1\) or \(-1\). Positivity is the extra condition that forces every sign to be \(1\). Without that condition, there are genuine alternative factorizations.

Check Your Understanding

Use the definitions and the sign-choice result to answer each question.

  1. What are the dimensions of \(\mathbf{Q}\) and \(\mathbf{R}\) in a reduced QR factorization of a full-column-rank matrix \(\mathbf{A}\in\mathbb{R}^{5\times 3}\)?
  2. Why is \(\mathbf{R}\) invertible when \(\mathbf{A}=\mathbf{Q}\mathbf{R}\) and \(\mathbf{A}\) has full column rank?
  3. For \(\mathbf{D}=\begin{bmatrix}1&0\\0&-1\end{bmatrix}\), describe which column of \(\mathbf{Q}\) and which row of \(\mathbf{R}\) change sign in \(\mathbf{Q}\mathbf{D}\) and \(\mathbf{D}\mathbf{R}\).
  4. Explain which part of the uniqueness proof uses the positivity of the diagonal entries.
  5. For a full-column-rank matrix with three columns, how many diagonal sign matrices are possible, and why?

Test yourself: Linear Algebra final exam practice

Ready to check what you know? Work a full-length practice final, then open the complete worked solutions.

Want all 1,114 practice problems?

This tutorial covers one topic. Calc Pass covers the full Calculus AB & BC curriculum (the core of Calculus I and II): full review, every practice question, and step-by-step solutions to each one.

QR code to download the Calc Pass app

Get the Calc Pass App

Scan to download and practice on the go, with instant scoring.

Calc Pass Volume 1: 1,114 Practice Questions book cover

Vol. 1: 1,114 Questions

The complete practice question bank, organized by AB & BC topic.

View on Amazon
Calc Pass Volume 2: Solutions Manual book cover

Vol. 2: Solutions Manual

Fully worked solutions to every question in Volume 1.

View on Amazon