QR Decomposition — Definition, Formula & Example
QR decomposition is a way to write a matrix as a product . The columns of are perpendicular unit vectors, and is upper triangular. You can think of it as the Gram-Schmidt process applied to the columns of , with the bookkeeping saved in .
Let be a real matrix with . A (reduced) QR decomposition is a factorization . Here is with orthonormal columns, so , and is an upper triangular matrix. Such a factorization always exists. If has full column rank, is invertible, and the factorization is unique once you require the diagonal entries of to be positive. In the full QR decomposition, is an orthogonal matrix and is an upper triangular matrix.
Key Formula
Where:
- = The matrix being factored, with columns
- = Matrix whose columns are orthonormal
- = Upper triangular matrix; entry records how much of is in column
- = The identity matrix
Worked Example
Problem: Find the QR decomposition of using Gram-Schmidt on its columns and .
Step 1: Normalize the first column. Its length becomes .
Step 2: Project onto to get . Then subtract that part to leave a vector perpendicular to .
Step 3: Normalize the leftover vector. Its length becomes .
Answer: and . Check: . Multiplying out gives back .
Why It Matters
In a numerical linear algebra or data science course, QR is the standard way to solve least-squares problems. You solve by back substitution instead of forming , which squares the condition number and loses accuracy. Repeated QR factorizations are also the core of the QR algorithm, which software uses to compute eigenvalues.
Common Mistakes
Mistake: Making the columns of Q perpendicular but forgetting to divide by their lengths.
Correction: The columns of must be orthonormal: each one has length 1. Without normalizing, is diagonal but not , and no longer equals unless you rescale . Store each length on the diagonal of .
