Prerequisite · Linear Algebra

Orthogonality and Projection

18 min read
By the end of this reading you will be able to:
  • Compute the orthogonal projection of a vector onto a line and verify that the residual is perpendicular to the line
  • Apply Gram-Schmidt orthogonalisation to produce an orthonormal basis from an arbitrary spanning set
  • Build the projection matrix P = QQ^T for a subspace and verify it is idempotent and symmetric
  • Derive the least-squares solution via the normal equations A^T A x = A^T b and interpret the residual geometrically
  • Interpret the hat matrix H = A(A^T A)^{-1} A^T as an orthogonal projector and explain what it means for fitted values and residuals

Orthogonality

Two vectors u⃗,v⃗∈Rn\vec{u}, \vec{v} \in \mathbb{R}^n are orthogonal if their dot product is zero:

u⃗⊥v⃗  ⟺  u⃗⋅v⃗=∑i=1nuivi=0\vec{u} \perp \vec{v} \iff \vec{u} \cdot \vec{v} = \sum_{i=1}^n u_i v_i = 0

The norm (length) of a vector is ∥v⃗∥=v⃗⋅v⃗\|\vec{v}\| = \sqrt{\vec{v} \cdot \vec{v}}. A unit vector has ∥v^∥=1\|\hat{v}\| = 1; any nonzero vector can be normalized: v^=v⃗/∥v⃗∥\hat{v} = \vec{v}/\|\vec{v}\|.

A set {q⃗1,…,q⃗k}\{\vec{q}_1, \ldots, \vec{q}_k\} is orthonormal if q⃗i⋅q⃗j=δij\vec{q}_i \cdot \vec{q}_j = \delta_{ij} (1 if i=ji=j, 0 otherwise). Orthonormal sets are automatically linearly independent.

Orthogonal Projection onto a Line

Given a line through the origin spanned by v⃗\vec{v}, the orthogonal projection of u⃗\vec{u} onto this line is the point on the line closest to u⃗\vec{u}:

projv⃗(u⃗)=u⃗⋅v⃗v⃗⋅v⃗ v⃗\text{proj}_{\vec{v}}(\vec{u}) = \frac{\vec{u} \cdot \vec{v}}{\vec{v} \cdot \vec{v}}\,\vec{v}

The scalar u⃗⋅v⃗∥v⃗∥2\frac{\vec{u} \cdot \vec{v}}{\|\vec{v}\|^2} is the signed component of u⃗\vec{u} along v⃗\vec{v}. The error (residual) u⃗−projv⃗(u⃗)\vec{u} - \text{proj}_{\vec{v}}(\vec{u}) is orthogonal to v⃗\vec{v} — this is the defining geometric property of orthogonal projection.

As a matrix: for a unit vector v^\hat{v}, the projection is v^(v^′u⃗)=(v^v^′)u⃗\hat{v}(\hat{v}'\vec{u}) = (\hat{v}\hat{v}')\vec{u}. The matrix P=v^v^′P = \hat{v}\hat{v}' is the rank-1 projection matrix onto the line. It satisfies P2=PP^2 = P (idempotent) and P=P′P = P' (symmetric).

Gram-Schmidt Orthogonalization

Gram-Schmidt converts any basis {v⃗1,…,v⃗n}\{\vec{v}_1, \ldots, \vec{v}_n\} into an orthonormal basis {q⃗1,…,q⃗n}\{\vec{q}_1, \ldots, \vec{q}_n\} spanning the same space:

Step 1: u⃗1=v⃗1\vec{u}_1 = \vec{v}_1, then q⃗1=u⃗1/∥u⃗1∥\vec{q}_1 = \vec{u}_1/\|\vec{u}_1\|

Step kk (for k=2,3,…,nk = 2, 3, \ldots, n): subtract the projections onto all previous q⃗i\vec{q}_i:

u⃗k=v⃗k−∑i=1k−1(v⃗k⋅q⃗i) q⃗i,q⃗k=u⃗k/∥u⃗k∥\vec{u}_k = \vec{v}_k - \sum_{i=1}^{k-1} (\vec{v}_k \cdot \vec{q}_i)\,\vec{q}_i, \qquad \vec{q}_k = \vec{u}_k / \|\vec{u}_k\|

Each u⃗k\vec{u}_k is the component of v⃗k\vec{v}_k orthogonal to the subspace spanned by v⃗1,…,v⃗k−1\vec{v}_1, \ldots, \vec{v}_{k-1}.

QR decomposition: Gram-Schmidt applied to the columns of AA produces A=QRA = QR where QQ has orthonormal columns and RR is upper triangular. This is used in least-squares solvers and eigenvalue algorithms.

Projection into a Subspace

Let WW be a subspace of Rn\mathbb{R}^n with orthonormal basis {q⃗1,…,q⃗k}\{\vec{q}_1, \ldots, \vec{q}_k\}. The orthogonal projection of u⃗\vec{u} onto WW is:

projW(u⃗)=∑i=1k(u⃗⋅q⃗i) q⃗i=QQ′u⃗\text{proj}_W(\vec{u}) = \sum_{i=1}^k (\vec{u} \cdot \vec{q}_i)\,\vec{q}_i = QQ'\vec{u}

where Q=[q⃗1∣⋯∣q⃗k]Q = [\vec{q}_1 \mid \cdots \mid \vec{q}_k]. The projection matrix PW=QQ′P_W = QQ' satisfies:

  • PW2=PWP_W^2 = P_W (projecting twice does nothing)
  • PW′=PWP_W' = P_W (it is symmetric)
  • rank(PW)=k=dim⁡(W)\text{rank}(P_W) = k = \dim(W)

The complement u⃗−PWu⃗\vec{u} - P_W \vec{u} is orthogonal to every vector in WW.

Least Squares: The Geometry

When the system Ax⃗=b⃗A\vec{x} = \vec{b} has no solution (as happens in overdetermined systems with more equations than unknowns), the best we can do is find x^\hat{x} minimizing ∥Ax^−b⃗∥2\|A\hat{x} - \vec{b}\|^2.

Geometrically: Ax^A\hat{x} is the projection of b⃗\vec{b} onto the column space of AA. The residual b⃗−Ax^\vec{b} - A\hat{x} must be orthogonal to all columns of AA:

A′(b⃗−Ax^)=0⃗  ⟹  A′Ax^=A′b⃗A'(\vec{b} - A\hat{x}) = \vec{0} \implies A'A\hat{x} = A'\vec{b}

These are the normal equations. When AA has full column rank, A′AA'A is invertible and the unique least-squares solution is:

x^=(A′A)−1A′b⃗\hat{x} = (A'A)^{-1}A'\vec{b}

The matrix P=A(A′A)−1A′P = A(A'A)^{-1}A' is the projection matrix onto the column space of AA — the hat matrix familiar from regression. This is the linear algebra foundation of ordinary least squares, and by extension of any optimization problem whose solution is a projection.

References
Hefferon 2020 — Linear Algebra, Ch. Three §VI: Projection, Gram-Schmidt