Foundations to Frontier
Tests
A. Mathematical Foundations › A2 Linear Algebra › Advanced linear algebra

Inner Product Spaces, Orthogonal Projections and Gram–Schmidt

The dot product generalizes to functions, random variables and signals. Once you can measure angles, the best approximation in a subspace is always an orthogonal projection. This one idea underlies least squares, Fourier series, PCA and the Kalman filter.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Shadows

Hold a stick in the sunlight at noon. Its shadow on the floor is the part of the stick that points along the floor. The shadow is the closest you can get to the stick while staying flat on the floor. That’s an orthogonal projection.

Perpendicular helpers

Directions that are perpendicular to each other (like east, north and up) are wonderful helpers. Each one measures its own part of a vector, and none of them interfere with the others. Turning a messy set of directions into perpendicular ones, one at a time, is called Gram–Schmidt.

Adding and scaling vectors
1.50uuvu+v
u + v = (4, 4) · 1.50u = (4.50, 1.50) · ‖u‖ = 3.16
Why engineers care

A spacecraft gets position readings from several noisy sensors. The best possible guess of where it really is turns out to be a “shadow” too: a projection of the truth onto what the sensors can see. That is the heart of the Kalman filter, which helped steer Apollo to the Moon.

📝 Quick check (Level 0)
0/3 answered
  1. 1. Perpendicular arrows have a dot product of…
  2. 2. The shadow of the arrow (3, 4) on the floor (x-axis) has length…
  3. 3. How many mutually perpendicular directions fit in a room?

Level 1: Beginner

★★☆☆☆ Basic⏱ 15 minSecondary-school mathematics: arithmetic and elementary algebra.

Inner products beyond the dot product

An inner product is any rule ⟨u,v⟩\langle\mathbf u,\mathbf v\rangle that behaves like the dot product. It gives you lengths ∥v∥=⟨v,v⟩\lVert\mathbf v\rVert = \sqrt{\langle\mathbf v,\mathbf v\rangle} and angles. Examples:

Space Inner product
Rn\mathbb R^n u⊤v=∑uivi\mathbf u^\top\mathbf v = \sum u_iv_i
weighted Rn\mathbb R^n u⊤Wv=∑wiuivi\mathbf u^\top W\mathbf v = \sum w_iu_iv_i with wi>0w_i>0 (more trust in some coordinates)
functions on [a,b][a,b] ∫abf(x)g(x) dx\int_a^b f(x)g(x)\,dx
random variables E[XY]\mathbb E[XY] (for zero-mean ones, this is the covariance)

Example. On [−1,1][-1,1], ⟨1,x⟩=∫−11x dx=0\langle1,x\rangle = \int_{-1}^1x\,dx = 0. The constant function and xx are orthogonal!

Projection onto a line

proj⁡ab=⟨a,b⟩⟨a,a⟩ a\operatorname{proj}_{\mathbf a}\mathbf b = \frac{\langle\mathbf a,\mathbf b\rangle}{\langle\mathbf a,\mathbf a\rangle}\,\mathbf a

For b=(2,3)\mathbf b = (2,3) and a=(1,1)\mathbf a = (1,1), the coefficient is 5/2=2.55/2 = 2.5, so the projection is (2.5,2.5)(2.5, 2.5). The leftover (−0.5,0.5)(-0.5, 0.5) is perpendicular to a\mathbf a.

📝 Quick check (Level 1)
0/3 answered
  1. 1. ⟨(1,2,3), (4,−5,6)⟩ = ?
  2. 2. Are (1, 1) and (1, −1) orthogonal?
  3. 3. On [−1, 1], ⟨1, x⟩ = ∫x dx = ?

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 45 minUndergraduate students and practising engineers.

Projection onto a subspace

The projection p\mathbf p of b\mathbf b onto a subspace SS is characterized by one condition: the residual is orthogonal to SS.

⟨b−p, s⟩=0  for all s∈S\langle\mathbf b - \mathbf p,\ \mathbf s\rangle = 0\ \text{ for all } \mathbf s\in S
  • With an orthonormal basis q1,…,qk\mathbf q_1,\dots,\mathbf q_k: p=∑k⟨b,qk⟩qk\mathbf p = \sum_k\langle\mathbf b,\mathbf q_k\rangle\mathbf q_k, and P=QQ⊤P = QQ^\top.
  • With any basis (the columns of AA): P=A(A⊤A)−1A⊤P = A(A^\top A)^{-1}A^\top. These are the normal equations of A2.3-7.
  • With a general inner product, solve the Gram system Gc=rG\mathbf c = \mathbf r with Gij=⟨ai,aj⟩G_{ij} = \langle\mathbf a_i,\mathbf a_j\rangle and ri=⟨ai,b⟩r_i = \langle\mathbf a_i,\mathbf b\rangle.

Projection matrices satisfy P2=PP^2 = P (projecting twice changes nothing) and P⊤=PP^\top = P.

Gram–Schmidt

Turn independent vectors v1,…,vk\mathbf v_1,\dots,\mathbf v_k into orthonormal q1,…,qk\mathbf q_1,\dots,\mathbf q_k with the same span. Subtract from each new vector its projections onto the earlier q\mathbf q’s, then normalize:

wj=vj−∑i<j⟨vj,qi⟩qi,qj=wj/∥wj∥\mathbf w_j = \mathbf v_j - \sum_{i<j}\langle\mathbf v_j,\mathbf q_i\rangle\mathbf q_i, \qquad \mathbf q_j = \mathbf w_j/\lVert\mathbf w_j\rVert

Worked example. For v1=(3,4)\mathbf v_1 = (3,4) and v2=(1,0)\mathbf v_2 = (1,0):

  1. q1=(0.6,0.8)\mathbf q_1 = (0.6, 0.8).
  2. w2=(1,0)−0.6 (0.6,0.8)=(0.64,−0.48)\mathbf w_2 = (1,0) - 0.6\,(0.6,0.8) = (0.64,-0.48), which has norm 0.8.
  3. So q2=(0.8,−0.6)\mathbf q_2 = (0.8,-0.6).

The coefficients form an upper-triangular RR, so Gram–Schmidt is the QR factorization (A2.3-4).

🐍 Exercise 1: Gram–Schmidt
Orthonormalize the columns of V one at a time (modified Gram–Schmidt). Check QᵀQ = I, V = QR and that R is upper triangular.

Function spaces: the same picture

Functions are vectors too. Apply Gram–Schmidt to 1,x,x2,…1, x, x^2, \dots on [−1,1][-1,1] and you get the Legendre polynomials. Use sin⁡kx\sin kx and cos⁡kx\cos kx instead and the projection coefficients are the Fourier coefficients. A truncated Fourier series is the best approximation, in the integral-squared-error sense, by a trigonometric polynomial.

Projecting a function onto an orthonormal basis
target:basis:
solid = target f, dashed orange = projection Σ⟨f, qₖ⟩qₖ · error ‖f − p‖ = 1.02e-1 · energy captured Σcₖ² / ‖f‖² = 98.44%
Bars are the coefficients cₖ = ⟨f, qₖ⟩ (green +, blue −). Adding a basis function never increases the error (Bessel). Smooth eˣ converges very fast; the step converges slowly and overshoots near the jump (Gibbs).
📝 Quick check (Level 2)
0/3 answered
  1. 1. The residual b − p of an orthogonal projection is…
  2. 2. Projecting (1, 1, 1) onto the xy-plane gives…
  3. 3. A projection matrix satisfies…

Level 3: Advanced

★★★★☆ Advanced⏱ 45 minGraduate level, with full derivations and proofs.

Cauchy–Schwarz

Theorem (Cauchy–Schwarz)

In any inner product space, ∣⟨u,v⟩∣≤∥u∥ ∥v∥\lvert\langle\mathbf u,\mathbf v\rangle\rvert\le\lVert\mathbf u\rVert\,\lVert\mathbf v\rVert. Equality holds exactly when u\mathbf u and v\mathbf v are parallel.

Proof. If v=0\mathbf v = 0, there is nothing to prove. Otherwise, let p\mathbf p be the projection of u\mathbf u onto v\mathbf v. The residual u−p\mathbf u - \mathbf p is orthogonal to p\mathbf p, so Pythagoras gives ∥u∥2=∥p∥2+∥u−p∥2≥∥p∥2=⟨u,v⟩2/∥v∥2\lVert\mathbf u\rVert^2 = \lVert\mathbf p\rVert^2 + \lVert\mathbf u - \mathbf p\rVert^2\ge\lVert\mathbf p\rVert^2 = \langle\mathbf u,\mathbf v\rangle^2/\lVert\mathbf v\rVert^2. ∎ This is what makes angles cos⁡θ=⟨u,v⟩/(∥u∥∥v∥)\cos\theta = \langle\mathbf u,\mathbf v\rangle/(\lVert\mathbf u\rVert\lVert\mathbf v\rVert) well defined in every inner product space.

The projection is the best approximation

Theorem (best approximation)

If b−p⊥S\mathbf b - \mathbf p\perp S with p∈S\mathbf p\in S, then ∥b−s∥>∥b−p∥\lVert\mathbf b - \mathbf s\rVert > \lVert\mathbf b - \mathbf p\rVert for every other s∈S\mathbf s\in S.

Proof. b−s=(b−p)+(p−s)\mathbf b - \mathbf s = (\mathbf b - \mathbf p) + (\mathbf p - \mathbf s), where the second part lies in SS, so it is orthogonal to the first. By Pythagoras, ∥b−s∥2=∥b−p∥2+∥p−s∥2\lVert\mathbf b - \mathbf s\rVert^2 = \lVert\mathbf b - \mathbf p\rVert^2 + \lVert\mathbf p - \mathbf s\rVert^2. ∎

Bessel, Parseval and Hilbert spaces

For an orthonormal set {qk}\{\mathbf q_k\}, the captured energy never exceeds the total (Bessel):

∑k∣⟨f,qk⟩∣2≤∥f∥2\sum_k\lvert\langle\mathbf f,\mathbf q_k\rangle\rvert^2\le\lVert\mathbf f\rVert^2

Equality for every f\mathbf f (Parseval) means the set is a complete orthonormal basis. In infinite dimensions, you also need completeness of the space (every Cauchy sequence converges) for projections to exist. A complete inner product space is a Hilbert space, such as L2[a,b]L^2[a,b]. Hilbert spaces are the setting for Fourier analysis, quantum mechanics and kernel methods (RKHS, B3).

Classical vs modified Gram–Schmidt

In exact arithmetic, the two orderings are identical. In floating point:

  • Classical GS computes every coefficient from the original vj\mathbf v_j. It loses orthogonality like κ2ε\kappa^2\varepsilon and can fail completely on nearly dependent columns.
  • Modified GS subtracts one projection at a time from the updated vector, and its error grows only like κε\kappa\varepsilon.
  • Householder QR is better still (A2.3-4). Practice Code 3 measures the difference.
Exercise 3.1: Show that every projection matrix has eigenvalues 0 or 1

If Px=λxP\mathbf x = \lambda\mathbf x, then λx=Px=P2x=λ2x\lambda\mathbf x = P\mathbf x = P^2\mathbf x = \lambda^2\mathbf x, so λ2=λ\lambda^2 = \lambda. Consequently, the trace of PP equals its rank, which is the dimension of the subspace.

📝 Quick check (Level 3)
0/3 answered
  1. 1. ‖u‖ = 3 and ‖v‖ = 4. The largest possible ⟨u, v⟩?
  2. 2. Which Gram–Schmidt variant is more stable in floating point?
  3. 3. trace of a projection onto a 2-D subspace of ℝ⁵?

Level 4: Expert

★★★★★ Expert⏱ 35 minResearchers: original papers and open problems.

Estimation is projection

Treat zero-mean random variables as vectors with ⟨X,Y⟩=E[XY]\langle X,Y\rangle = \mathbb E[XY]. The best linear estimate of a hidden state xx from measurements y1,…,ymy_1,\dots,y_m (minimum mean-square error) is the projection of xx onto their span. Its error is uncorrelated with every measurement: the orthogonality principle. This is the core of the Wiener filter and of the Kalman filter’s update step (Kalman, 1960). Fusing two sensors with noise variances σ12\sigma_1^2 and σ22\sigma_2^2 gives weights proportional to 1/σi21/\sigma_i^2, and a fused variance (1/σ12+1/σ22)−1(1/\sigma_1^2 + 1/\sigma_2^2)^{-1} smaller than either sensor’s alone. Practice Code 5 checks this by simulation.

Orthogonal bases in science and engineering

  • Spectral methods: Legendre and Chebyshev expansions solve PDEs and trajectory-optimization problems to near machine precision (pseudospectral optimal control; Ross and Karpenko, 2012). This includes the methods used to plan the zero-propellant maneuvers of the International Space Station.
  • Orthogonal polynomial features make polynomial regression well-conditioned (A2.3-8).
  • Kernel methods do projections in a reproducing-kernel Hilbert space, where ⟨ϕ(x),ϕ(y)⟩=k(x,y)\langle\phi(x),\phi(y)\rangle = k(x,y) (B3).
  • Krylov methods (A2.4-7) run Gram–Schmidt on b,Ab,A2b,…\mathbf b, A\mathbf b, A^2\mathbf b, \dots. Arnoldi and Lanczos are Gram–Schmidt with structure.
  • Orthogonality in deep learning: orthogonal initialization preserves signal norms through depth (Saxe et al., 2014), and orthogonality constraints stabilize recurrent networks.
🐍 Exercise 2 (research): Legendre polynomials from Gram–Schmidt
With ⟨f, g⟩ = ∫₋₁¹ f g dx (trapezoid rule), orthonormalize 1, x, x², … and project eˣ. Check orthonormality, that q₂ ∝ (3x² − 1)/2, and that the error falls with the degree.

References

  1. E. Schmidt (1907). “Zur Theorie der linearen und nichtlinearen Integralgleichungen.” Mathematische Annalen, 63.
  2. R. E. Kalman (1960). “A new approach to linear filtering and prediction problems.” Journal of Basic Engineering, 82.
  3. Å. Björck (1967). “Solving linear least squares problems by Gram–Schmidt orthogonalization.” BIT, 7.
  4. D. Luenberger (1969). Optimization by Vector Space Methods. Wiley. (Projection theorem and estimation.)
  5. L. N. Trefethen (2013). Approximation Theory and Approximation Practice. SIAM.
  6. A. Saxe, J. McClelland, S. Ganguli (2014). “Exact solutions to the nonlinear dynamics of learning in deep linear neural networks.” ICLR.
  7. I. M. Ross, M. Karpenko (2012). “A review of pseudospectral optimal control: From theory to flight.” Annual Reviews in Control, 36.
  8. G. Strang (2016). Introduction to Linear Algebra, 5th ed. Chapter 4.