Gram–Schmidt and QR Factorization

Construct an orthonormal basis and use triangular equations to recover coordinates.

Builds on Dot Products and Orthogonal Projection

The bigger question: What is the closest answer when an exact fit is impossible?

On this page

Remove directions already represented

Gram–Schmidt turns an independent list a1,…,ana_1,\ldots,a_n into orthonormal vectors spanning the same successive subspaces. First set q1=a1/∥a1∥q_1=a_1/\|a_1\|. At step jj, remove projections onto earlier directions:

vj=aj−∑i<j(qiTaj)qi,v_j=a_j-\sum_{i<j}(q_i^Ta_j)q_i, qj=vj/∥vj∥.q_j=v_j/\|v_j\|.

If the input columns are dependent, a residual becomes zero and cannot be normalized. This reveals redundancy rather than a new basis direction.

Visual guide

VISUAL GUIDERemove the part already explained
Starting from a₁ = (1, 1) and a₂ = (2, 0), project a₂ onto a₁ to get (1, 1). Subtracting leaves (1, −1), perpendicular to a₁. Normalizing these two directions produces an orthonormal basis for QR.-0.5-1.50.25-0.62510.251.751.132.52xy
  • Projection direction
Starting from a₁ = (1, 1) and a₂ = (2, 0), project a₂ onto a₁ to get (1, 1). Subtracting leaves (1, −1), perpendicular to a₁. Normalizing these two directions produces an orthonormal basis for QR.

Worked example: two columns

Let a1=(1,1,0)Ta_1=(1,1,0)^T and a2=(1,0,1)Ta_2=(1,0,1)^T. Then q1=(1,1,0)T/2q_1=(1,1,0)^T/\sqrt2 and q1Ta2=1/2q_1^Ta_2=1/\sqrt2. Subtracting gives v2=(1/2,−1/2,1)Tv_2=(1/2,-1/2,1)^T, with norm 3/2\sqrt{3/2}. Hence q2=(1,−1,2)T/6q_2=(1,-1,2)^T/\sqrt6.

Check q1Tq2=0q_1^Tq_2=0 and both norms equal one. These checks catch arithmetic mistakes before using the basis in later calculations.

PAUSE & THINKA quick check, not a grade

Try it yourself.

Choose an answer and explain your reasoning to yourself. Use a hint if you get stuck.

In a thin QR factorization with independent columns, what does QᵀQ equal?

Hint 1 · Find a starting point

The columns of Q are orthonormal.

Hint 2 · Take the next step

Their pairwise dot products are 1 with themselves and 0 with each other.

Show the reasoning

Answer: The identity matrix

Those dot products form the identity matrix, enabling the triangular system R x=Qᵀb.

Before moving on: what would make one of the other answers wrong? Saying why is part of understanding.

Worked example: read the factorization

Stack the orthonormal vectors as columns of QQ. The coefficients used above give

A=QR,A=QR, R=(21/203/2).R=\begin{pmatrix}\sqrt2&1/\sqrt2\\0&\sqrt{3/2}\end{pmatrix}.

The matrix QQ has size 3×23\times2 and satisfies QTQ=I2Q^TQ=I_2. But QQTQQ^T is a projection onto the two-dimensional column space, not the 3×33\times3 identity. This distinction matters for rectangular matrices.

For full column rank, a least-squares solution satisfies Rx^=QTbR\hat x=Q^Tb. Solve this triangular system instead of explicitly inverting RR. In numerical libraries, Householder QR is generally preferred to classical Gram–Schmidt because it better preserves orthogonality under rounding; modified Gram–Schmidt also improves on the classical algorithm.

Practice

  1. Apply Gram–Schmidt to (1,0)T,(1,1)T(1,0)^T,(1,1)^T.
  2. What occurs for (1,0)T,(2,0)T(1,0)^T,(2,0)^T?
  3. If QQ has three orthonormal columns in R5\mathbb R^5, what are the shapes of QTQQ^TQ and QQTQQ^T?
Show worked solutions
  1. q1=(1,0)Tq_1=(1,0)^T, residual (0,1)T(0,1)^T, so q2=(0,1)Tq_2=(0,1)^T.
  2. The second residual is zero, revealing dependent inputs.
  3. QTQQ^TQ is the 3×33\times3 identity; QQTQQ^T is a 5×55\times5 projection of rank three.
MAKE IT YOURS

Pause before the next idea.

Can you explain how the visualization connects to this lesson’s goal? If a step still feels uncertain, put this lesson on your review list and try the check again another day.

Optional marks, not a grade. Saved in this browser only. Open notebook →