SECTION 1
Historical Context & Motivation
Prerequisites
Imagine you have a big pile of tangled wires and you need to sort them into neat, organized bundles. That is basically what QR factorization does to a matrix. It takes a complicated matrix and splits it into two simpler matrices — one with perfectly perpendicular columns (called Q) and one that is upper-triangular (called R). This idea grew out of a long history of mathematicians trying to solve systems of equations and understand geometry in higher dimensions.
1883 • Gram–Schmidt Process Formalized
1907 • Schmidt's Contribution
1958 • Householder Reflections
1961 • Givens Rotations Popularized
Modern Era • Everyday Computing
The central question QR factorization answers is: How can we rewrite any matrix as a product of an orthogonal matrix and a triangular matrix? Solving this unlocks faster equation solving, better data fitting, and a clearer understanding of the geometry hidden inside matrices.
SECTION 2
Core Principles & Definitions
Before diving into the mechanics of QR factorization, you need a handful of foundational ideas. Each one builds on the last, so take them in order. If you are comfortable with basic matrix multiplication and the idea of vectors as arrows in space, you are ready to go.
Orthogonal Vectors
Orthonormal Vectors
Orthogonal Matrix (Q)
Upper-Triangular Matrix (R)
The Factorization A = QR
KEY TAKEAWAY
SECTION 3
Visual Explanation
The diagram below shows the big picture of QR factorization in two dimensions. On the left you see two original column vectors of matrix A. In the middle, the Gram–Schmidt process converts them into orthonormal vectors (the columns of Q). On the right, the upper-triangular matrix R holds the coefficients that relate Q back to A.
Notice how the original vectors a₁ and a₂ in the left panel are tilted at an awkward angle relative to each other. After the Gram–Schmidt process, the vectors q₁ and q₂ in the center panel meet at a perfect 90° angle and each has a length of exactly 1. The small square symbol at the corner confirms the right angle. The matrix R on the right is the "recipe" that tells you how to combine the q-vectors to recover the original a-vectors.
SECTION 4
Mathematical Framework
Now let's put the visual ideas into precise formulas. The Gram–Schmidt process is the standard algorithm for computing Q and R. We start with the columns of A and systematically build orthonormal vectors one at a time.
QR FACTORIZATION
A is the original m × n matrix, Q is an m × n matrix with orthonormal columns, and R is an n × n upper-triangular matrix.
GRAM–SCHMIDT STEP 1: FIRST ORTHONORMAL VECTOR
Take the first column a₁ of A. Divide it by its length (‖u₁‖) to get a unit vector q₁. The symbol ‖ ‖ means "magnitude" or "length" of the vector, computed using the Pythagorean theorem.
GRAM–SCHMIDT STEP 2: SUBTRACT PROJECTIONS
From the second column a₂, subtract the piece that points along q₁. The dot product (a₂ · q₁) measures how much a₂ overlaps with q₁ — it is the sum of the products of matching components. What remains, u₂, is perpendicular to q₁. Normalize it to get q₂.
BUILDING THE R MATRIX
The entries of R come from the dot products and lengths computed during the Gram–Schmidt process. The diagonal entries are the lengths of the u-vectors, and the off-diagonal entries are the dot products of the a-columns with the q-vectors.
Why does this work?
SECTION 5
Detailed Breakdown: The Gram–Schmidt Process
The diagram below walks through the Gram–Schmidt process step by step for a 2-column matrix. Follow the arrows from left to right to see how each stage transforms the vectors.
For a matrix with more than two columns, you repeat the pattern. For the third column a₃, you subtract projections along both q₁ and q₂ before normalizing. For the fourth column, you subtract projections along q₁, q₂, and q₃, and so on. Each new column "looks at" all the orthonormal vectors found so far and removes any overlap with them.
| Column of A | Projections to Subtract | Result Before Normalizing |
|---|---|---|
| a₁ (first) | None | u₁ = a₁ |
| a₂ (second) | (a₂ · q₁)q₁ | u₂ = a₂ − (a₂ · q₁)q₁ |
| a₃ (third) | (a₃ · q₁)q₁ and (a₃ · q₂)q₂ | u₃ = a₃ − (a₃ · q₁)q₁ − (a₃ · q₂)q₂ |
Pattern for Gram–Schmidt: each column subtracts more projections
SECTION 6
Worked Example
Let's find the QR factorization of a concrete 2 × 2 matrix. We will use the Gram–Schmidt process on:
GIVEN MATRIX
We treat each column as a vector: a₁ = (1, 1) and a₂ = (2, 0).
QR Factorization of a 2×2 Matrix
- 1
Step 1 — Find the length of a₁
Compute ‖a₁‖ = √(1² + 1²) = √2 ≈ 1.414. This length will become the entry r₁₁ in the R matrix.‖a₁‖ = √2 - 2
Step 2 — Normalize a₁ to get q₁
Divide a₁ by its length: q₁ = a₁ / ‖a₁‖ = (1/√2, 1/√2) ≈ (0.707, 0.707). This is the first column of Q.q₁ = (1/√2, 1/√2) - 3
Step 3 — Compute the projection of a₂ onto q₁
The dot product a₂ · q₁ = (2)(1/√2) + (0)(1/√2) = 2/√2 = √2. This value becomes the off-diagonal entry r₁₂.a₂ · q₁ = √2 - 4
Step 4 — Subtract the projection to get u₂
u₂ = a₂ − (a₂ · q₁)q₁ = (2, 0) − √2 × (1/√2, 1/√2) = (2, 0) − (1, 1) = (1, −1). This vector is perpendicular to q₁, which you can verify: u₂ · q₁ = (1)(1/√2) + (−1)(1/√2) = 0. ✓u₂ = (1, −1) - 5
Step 5 — Normalize u₂ to get q₂
‖u₂‖ = √(1² + (−1)²) = √2. So q₂ = u₂ / ‖u₂‖ = (1/√2, −1/√2). This is the second column of Q, and r₂₂ = √2.q₂ = (1/√2, −1/√2) - 6
Step 6 — Assemble Q and R
Q = [ 1/√2 1/√2 ] and R = [ √2 √2 ]. You can verify: Q × R = [ (1/√2)(√2)+(1/√2)(0) (1/√2)(√2)+(1/√2)(√2) ] = [1 2] in the first row, and similarly the second row gives [1 0]. That matches A! ✓Q = [1/√2 1/√2; 1/√2 −1/√2], R = [√2 √2; 0 √2]
SECTION 7
Strengths, Limitations & Comparisons
QR factorization is powerful, but like every tool in mathematics, it has strengths and weaknesses. Understanding these helps you know when QR is the right choice and when another method might be better.
| Feature | Strengths ✓ | Limitations ✗ |
|---|---|---|
| Accuracy on a computer | Much more accurate than LU factorization for many matrices. Rounding errors (small mistakes computers make with decimals) stay small. | Classical Gram–Schmidt can lose accuracy for nearly parallel vectors. Modified Gram–Schmidt or Householder reflections fix this. |
| Speed | Efficient for finding best-fit solutions to overdetermined systems (more equations than unknowns). | Slower than LU factorization for simple square systems of equations. |
| Applicability | Works on any matrix whose columns are independent (no column is a combination of the others) — it does not need to be square. | If columns are dependent (one column is a combination of others), the process breaks down (you get a zero vector during normalization). |
| Geometric insight | Q preserves lengths and angles — multiplying by Q is like rotating or reflecting without stretching, so the geometry of your data is not distorted. | The factorization is not unique unless we require the diagonal entries of R to be positive. |
Strengths and limitations of QR factorization
KEY TAKEAWAY
SECTION 8
Connection to Advanced Theory
QR factorization is not just a stand-alone technique — it connects to some of the most important ideas in advanced linear algebra and data science. Here is how it fits into the bigger picture. These topics go beyond this lesson and are typically studied in a later course on numerical linear algebra or applied matrix methods, but it is useful to know where QR factorization leads.
| QR Factorization (this lesson) | Advanced Topic | How They Connect |
|---|---|---|
| A = QR | Least-Squares Regression | To find the best-fit line through data, you need to solve a system with more equations than unknowns. With QR, this simplifies to solving Rx = Qᵀb, a triangular system solved by back substitution — very fast and accurate. |
| Q has orthonormal columns | QR Algorithm for Eigenvalues | An eigenvalue of a matrix A is a special number λ where A stretches a vector by exactly the factor λ. By repeatedly computing A = QR and then forming A' = RQ, the matrix converges to a form that reveals these special stretching factors. This is how computers find eigenvalues in practice. |
| Gram–Schmidt orthogonalization | Singular Value Decomposition (SVD) | SVD is a more powerful factorization that splits any matrix into three parts: UΣVᵀ. It is used in image compression and data analysis. QR factorization often serves as a building block in the algorithms that compute SVD. |
| R is upper-triangular | Back Substitution | Because R is triangular, solving Rx = c starts at the bottom row and works up. Each variable is found one at a time — very fast and clean. |
How QR factorization connects to advanced topics
As you continue studying linear algebra, you will encounter eigenvalues (special scaling factors of a matrix), singular value decomposition (a more powerful three-part matrix factorization used in image compression and data analysis), and principal component analysis (a technique for finding the most important patterns in large datasets). All of these rely on the same core idea: breaking a matrix into simpler parts. Mastering QR factorization gives you a strong foundation for all of them.
SECTION 9
Practice Problems
Question 1: CONCEPTUAL
Show answer
Question 2: BASIC CALCULATION
Show answer
Question 3: INTERMEDIATE
Show answer
Question 4: APPLIED
Show answer
Question 5: CRITICAL THINKING
Show answer
SUMMARY
Summary
Summary
QR factorization decomposes any matrix A whose columns are independent into the product of an orthogonal matrix Q and an upper-triangular matrix R. The columns of Q are orthonormal — perpendicular and unit-length — and are built using the Gram–Schmidt process, which subtracts projections one column at a time to create independent directions.
The R matrix stores the dot products and vector lengths computed along the way, and its triangular shape makes back substitution simple and fast. QR factorization is widely used in least-squares problems, algorithms that find eigenvalues (special scaling factors of a matrix), and modern computing applications from search engines to machine learning. As you progress further in linear algebra, you will encounter QR factorization again alongside more powerful decompositions like the singular value decomposition (SVD), making it a foundational tool worth mastering now.