Skip to content

Gram-Schmidt and QR

Turn independent columns into orthonormal ones with Gram-Schmidt, record the steps as A = QR with R upper triangular, and use orthogonal matrices (QᵀQ = I) that preserve lengths.

It opens on

Two columns (6, 8) and (−1, 7) point in awkward directions; can we replace them by two perpendicular unit vectors that span exactly the same plane, and what do we write down so nothing is lost?

Why it matters

Orthonormal columns make projection and least squares simple and numerically safe; QR is how software solves them, and Gram-Schmidt is the construction behind it.

Good to know first

  • Projection onto a line: p = (q·a) q for a unit vector q
  • Projection onto a subspace: the error is orthogonal to the subspace
  • Orthogonal vectors and subspaces: orthonormal vectors have qᵢ·qⱼ = 0 and qᵢ·qᵢ = 1

Step by step

  1. Gram-Schmidt on two vectors

    Produce q₁ and q₂ from a₁ = (6, 8) and a₂ = (−1, 7) by normalizing and then subtracting a shadow.

    Take q₁ along a₁: |a₁| = 10, so q₁ = a₁/|a₁| = (6/10, 8/10) = (3/5, 4/5).

    A common mix-up

    Subtract a₁ itself from a₂ to remove the common direction.

    In fact: a₂ − a₁ = (−7, −1) has dot product −50 with a₁; only the shadow 5q₁ = (3, 4) leaves e orthogonal.

  2. A = QR for a 3 × 2 matrix

    Run Gram-Schmidt on the columns of A = [[2, 1], [2, 4], [1, −1]] and read off A = QR with R = [[3, 3], [0, 3]].

    |a₁| = √(4 + 4 + 1) = 3, so r₁₁ = 3 and q₁ = (2/3, 2/3, 1/3).

    A common mix-up

    Q must be square to have orthonormal columns.

    In fact: Q here is 3 × 2 and still has QᵀQ = I; QQᵀ is a 3 × 3 projection, not I.

  3. Orthogonal matrices keep lengths

    Show that QᵀQ = I gives |Qx| = |x|, recognise a rotation and a reflection, and see why QR is numerically safe.

    For Q = (1/5)[[3, −4], [4, 3]], the columns (3/5, 4/5) and (−4/5, 3/5) have 9/25 + 16/25 = 1 and dot product −12/25 + 12/25 = 0, so QᵀQ = I.

    A common mix-up

    Any matrix with perpendicular columns is orthogonal.

    In fact: The columns must also have length 1; [[3, −4], [4, 3]] has perpendicular columns of length 5, so its QᵀQ is 25I.

Try it

Apply Gram-Schmidt to a₁ = (1, 1) and a₂ = (1, 0).Answer

q₁ = (1, 1)/√2 and q₂ = (1, −1)/√2

Hint: The shadow is (1/2)(1, 1), so e = (1/2, −1/2)

Find the QR factorization of A = [[3, 7], [4, 1]].Answer

Q = (1/5)[[3, 4], [4, −3]] and R = [[5, 5], [0, 5]]

Hint: q₁ = (3/5, 4/5), r₁₂ = q₁·(7, 1) = 5, e = (4, −3)

Show that (Qx)·(Qy) = x·y for an orthogonal Q.Answer

(Qx)ᵀ(Qy) = xᵀQᵀQy = xᵀy

Hint: Use QᵀQ = I

Check q₁·q₂: what is it, and what does it tell you?Answer

−12/25 + 12/25 = 0, so q₁ ⟂ q₂ and the pair is orthonormal.

What is R, and why are the entries below the diagonal zero?Answer

R = [[3, 3], [0, 3]]; a₁ is built from q₁ alone, so q₂·a₁ = 0.

Gram-Schmidt and QR

30 minutes every month. No card.