Get AI summaries of any video or article — Sign up free
QR decomposition (for square matrices) [dark version] thumbnail

QR decomposition (for square matrices) [dark version]

4 min read

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.

TL;DR

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?

Let A’s columns be A1, A2, … . The first orthonormal vector is q1 = A1 / ||A1||. Since A1 is exactly ||A1|| times q1, expressing A1 as a linear combination of Q’s columns uses only q1. That forces the first column of R to have ||A1|| in the (1,1) position and zeros below, matching the upper-triangular form.

Why can’t q2 be obtained by normalizing A2 directly?

Normalizing A2 gives a unit vector, but it does not guarantee orthogonality to q1. The method requires q2 ⟂ q1, so it subtracts the projection of A2 onto q1: A2⊥ = A2 − (⟨A2, q1⟩) q1. Only after removing the component along q1 does normalization produce q2 = A2⊥ / ||A2⊥||.

What exactly goes into R when computing q2?

The same scalar used in the projection becomes an off-diagonal entry of R. Specifically, ⟨A2, q1⟩ is the coefficient multiplying q1 in the expression for A2, so it is stored in R’s (1,2) position. The diagonal entry R(2,2) becomes ||A2⊥||, the norm of the orthogonal remainder used to normalize q2. Entries below remain zero because q3 and later basis vectors haven’t been introduced yet.

How is q3 formed, and how do its projection coefficients populate R?

q3 comes from removing components of A3 along both q1 and q2: A3⊥ = A3 − (⟨A3, q1⟩) q1 − (⟨A3, q2⟩) q2. The scalars ⟨A3, q1⟩ and ⟨A3, q2⟩ become the upper-right entries of R in the corresponding column, while the diagonal entry R(3,3) is ||A3⊥||. Then q3 = A3⊥ / ||A3⊥||.

In the 2×2 example A = [[1, 3],[1, −1]], what are q1 and the first R entry?

A1 = [1, 1]^T, so ||A1|| = √(1^2+1^2) = √2. Thus q1 = A1/||A1|| = (1/√2)[1, 1]^T. The first diagonal entry of R is R(1,1) = √2, and the rest of the first column below it is zero, reflecting upper-triangular structure.

Review Questions

  1. Given q1 and A2, write the formula for A2⊥ and identify which scalar becomes R(1,2).
  2. Why does R become upper triangular automatically during Gram–Schmidt-based QR construction?
  3. For A3, which two inner products must be computed to form A3⊥, and where do they land in R?

Key Points

  1. 1

    QR decomposition factors a square matrix A as A = Q R, with Q having orthonormal columns and R upper triangular.

  2. 2

    Q’s columns are constructed by normalizing the first column of A and then repeatedly subtracting orthogonal projections (Gram–Schmidt).

  3. 3

    For each k, the orthogonal remainder A_k⊥ is formed by subtracting projections onto all previously computed q_i vectors.

  4. 4

    The inner-product coefficients used in the projection steps become the corresponding entries of R above the diagonal.

  5. 5

    Each diagonal entry of R equals the norm of the orthogonal remainder used to normalize the next q_k.

  6. 6

    Once Q and R are built this way, multiplying Q R reproduces A exactly, including in numerical examples.

  7. 7

    The method extends from real orthogonal matrices to complex unitary matrices by using the appropriate inner product and conjugate-transpose relationship.

Highlights

R’s upper-triangular shape comes from the fact that each A_k is expressed using only q1 through qk, with later q’s not yet introduced.
q2 is obtained by removing the projection of A2 onto q1: A2⊥ = A2 − (⟨A2, q1⟩) q1, then normalizing.
For q3, the orthogonal remainder subtracts projections onto both q1 and q2, leaving the component orthogonal to their span.
In the 2×2 example with A = [[1, 3],[1, −1]], q1 = (1/√2)[1, 1]^T and R(1,1) = √2, setting the pattern for the rest of the factorization.

Topics