QR decomposition (for square matrices) [dark version]
Based on The Bright Side of Mathematics's video on YouTube. If you like this content, support the original creators by watching, liking and subscribing to their content.
QR decomposition factors a square matrix A as A = Q R, with Q having orthonormal columns and R upper triangular.
Briefing
QR decomposition for square, invertible matrices breaks a matrix A into A = Q R, where Q has orthonormal (real) or orthonormal/unitary (complex) columns and R is upper triangular. The key payoff is structural: once Q’s columns are built as an orthonormal basis, R’s entries become the coefficients that express the original columns of A as linear combinations of that basis. This turns a matrix factorization into a step-by-step geometry problem—normalizing vectors and subtracting orthogonal projections.
The construction starts by taking A’s columns A1, A2, A3, … and converting them into orthonormal vectors q1, q2, q3, … . First, q1 is just A1 normalized: q1 = A1 / ||A1||. For q2, simply normalizing A2 won’t make it orthogonal to q1, so the method subtracts the projection of A2 onto q1. In inner-product terms, the component of A2 along q1 is (⟨A2, q1⟩) q1, so the orthogonal remainder is A2⊥ = A2 − (⟨A2, q1⟩) q1. Normalizing that remainder yields q2 = A2⊥ / ||A2⊥||.
R is filled in alongside these steps, using the same coefficients that appear during projection. The first column of R contains the coefficients expressing A1 as a combination of q1, q2, q3, … . Because A1 aligns with q1 by construction, the top entry becomes ||A1|| and the entries below it are zero, matching the upper-triangular requirement. For the second column, the coefficient in front of q1 is ⟨A2, q1⟩ (stored directly into the (1,2) position of R), and the diagonal entry becomes ||A2⊥|| (the norm of the orthogonal remainder), while the (3,2) and lower entries stay zero since q3 and beyond haven’t been introduced yet.
The same pattern repeats for q3: compute A3⊥ by subtracting projections onto both q1 and q2. Geometrically, q1 and q2 span a plane; projecting A3 onto that plane and subtracting leaves the component orthogonal to the plane. The coefficients from those projections populate the upper-right entries of R, and the norm ||A3⊥|| becomes the diagonal entry. After normalizing A3⊥ to form q3, the factorization A = Q R is complete.
A concrete 2×2 numerical example illustrates the mechanics. With A = [[1, 3],[1, −1]], the first column gives q1 = (1/√2)[1, 1]^T and the first diagonal entry of R becomes ||A1|| = √2. The second column requires subtracting its projection onto q1, producing an orthogonal remainder whose norm becomes the (2,2) entry of R. The resulting Q has columns q1 and q2, and multiplying Q R reproduces A, confirming the decomposition. The method is essentially the Gram–Schmidt process in matrix form: orthonormalizing columns yields Q, while the projection coefficients assemble R.
Cornell Notes
QR decomposition factors a square matrix A into A = Q R, where Q has orthonormal columns (orthogonal in real space, unitary in complex space) and R is upper triangular. The columns of Q are built by taking A’s columns and applying Gram–Schmidt: normalize the first column to get q1, then form q2 by subtracting the projection of A2 onto q1, and so on. Each projection coefficient used to remove components from A_k is placed directly into R, while the norm of the orthogonal remainder becomes the diagonal entry. This matters because it turns matrix factorization into a predictable sequence of inner products, vector subtractions, and normalizations, with R’s upper-triangular structure emerging automatically.
How does one construct q1 from A, and why does it make R’s first column simple?
Why can’t q2 be obtained by normalizing A2 directly?
What exactly goes into R when computing q2?
How is q3 formed, and how do its projection coefficients populate R?
In the 2×2 example A = [[1, 3],[1, −1]], what are q1 and the first R entry?
Review Questions
- Given q1 and A2, write the formula for A2⊥ and identify which scalar becomes R(1,2).
- Why does R become upper triangular automatically during Gram–Schmidt-based QR construction?
- For A3, which two inner products must be computed to form A3⊥, and where do they land in R?
Key Points
- 1
QR decomposition factors a square matrix A as A = Q R, with Q having orthonormal columns and R upper triangular.
- 2
Q’s columns are constructed by normalizing the first column of A and then repeatedly subtracting orthogonal projections (Gram–Schmidt).
- 3
For each k, the orthogonal remainder A_k⊥ is formed by subtracting projections onto all previously computed q_i vectors.
- 4
The inner-product coefficients used in the projection steps become the corresponding entries of R above the diagonal.
- 5
Each diagonal entry of R equals the norm of the orthogonal remainder used to normalize the next q_k.
- 6
Once Q and R are built this way, multiplying Q R reproduces A exactly, including in numerical examples.
- 7
The method extends from real orthogonal matrices to complex unitary matrices by using the appropriate inner product and conjugate-transpose relationship.