QR
Factorization
Learn how to decompose any matrix into the product of an orthogonal matrix \(Q\) and an upper triangular matrix \(R\) using the Gram-Schmidt process.
What Is QR Factorization?
QR factorization expresses a matrix \(A\) as the product of two special matrices:
$$ A = QR $$
Why Does QR Matter?
QR factorization is one of the most important decompositions in applied mathematics. It powers algorithms you encounter everywhere:
Orthogonality Refresher
The Gram-Schmidt Process
Gram-Schmidt converts a set of linearly independent vectors into an orthonormal set. It is the engine behind QR factorization.
Gram-Schmidt Formulas
$$ \mathbf{u}_1 = \mathbf{a}_1, \qquad \mathbf{e}_1 = \frac{\mathbf{u}_1}{\|\mathbf{u}_1\|} $$
$$ \mathbf{u}_k = \mathbf{a}_k - \sum_{j=1}^{k-1} \text{proj}_{\mathbf{e}_j}(\mathbf{a}_k) $$
$$ \text{proj}_{\mathbf{e}_j}(\mathbf{a}_k) = (\mathbf{e}_j \cdot \mathbf{a}_k)\,\mathbf{e}_j $$
Visualizing Projection Removal
Building \(Q\) and \(R\)
Once Gram-Schmidt is complete, assemble the matrices:
Columns are the orthonormal vectors.
QR vs LU vs SVD
| QR | LU | SVD | |
|---|---|---|---|
| Form | \(A = QR\) | \(A = LU\) | \(A = U\Sigma V^T\) |
| Factors | Orthogonal + upper tri | Lower tri + upper tri | Two orthogonal + diagonal |
| Best for | Least squares, eigenvalues | Solving \(Ax = b\) | Rank, pseudoinverse |
| Stability | High | Moderate | Highest |
| Matrix shape | Any \(m \times n\) | Square | Any \(m \times n\) |
How to Compute QR
Example 1: Setup
Find the QR factorization of:
$$ A = \begin{bmatrix} 1 & 1 \\ 1 & 0 \\ 0 & 1 \end{bmatrix} $$
Example 1: Gram-Schmidt
Example 1: Result
$$ Q = \begin{bmatrix} \frac{1}{\sqrt{2}} & \frac{1}{\sqrt{6}} \\[6pt] \frac{1}{\sqrt{2}} & \frac{-1}{\sqrt{6}} \\[6pt] 0 & \frac{2}{\sqrt{6}} \end{bmatrix}, \qquad R = \begin{bmatrix} \sqrt{2} & \frac{1}{\sqrt{2}} \\[6pt] 0 & \frac{\sqrt{6}}{2} \end{bmatrix} $$
Example 2: \(3 \times 3\) Matrix
Find the QR factorization of:
$$ A = \begin{bmatrix} 1 & 1 & 0 \\ 1 & 0 & 1 \\ 0 & 1 & 1 \end{bmatrix} $$
Example 2: Final Matrices
$$ Q = \begin{bmatrix} \frac{1}{\sqrt{2}} & \frac{1}{\sqrt{6}} & \frac{-2}{3} \\[6pt] \frac{1}{\sqrt{2}} & \frac{-1}{\sqrt{6}} & \frac{2}{3} \\[6pt] 0 & \frac{2}{\sqrt{6}} & \frac{1}{3} \end{bmatrix} $$
$$ R = \begin{bmatrix} \sqrt{2} & \frac{1}{\sqrt{2}} & \frac{1}{\sqrt{2}} \\[6pt] 0 & \frac{\sqrt{6}}{2} & \frac{1}{\sqrt{6}} \\[6pt] 0 & 0 & \frac{2}{3} \end{bmatrix} $$
Common Mistakes
Question 1 of 5
In the factorization \(A = QR\), what property must Q satisfy?
Question 2 of 5
During Gram-Schmidt, to orthogonalize \(\mathbf{a}_2\), we compute \(\mathbf{u}_2 = \mathbf{a}_2 - \text{proj}_{\mathbf{e}_1}(\mathbf{a}_2)\). What does subtracting the projection achieve?
Question 3 of 5
If \(A\) is a \(4 \times 3\) matrix with linearly independent columns, what are the dimensions of \(Q\) and \(R\)?
Question 4 of 5
Given \(\mathbf{a}_1 = \begin{bmatrix}3\\4\end{bmatrix}\), what is the first orthonormal vector \(\mathbf{e}_1\) in Gram-Schmidt?
Question 5 of 5
Which entry of \(R\) stores the value \(\mathbf{e}_1 \cdot \mathbf{a}_2\)?