How the Gram-Schmidt Process Works
The Gram-Schmidt process takes a set of linearly independent vectors, v1, v2, v3, and builds a new set of mutually perpendicular (orthogonal) vectors, u1, u2, u3, that span the exact same subspace. Each step removes the part of a vector that already points in the direction of the vectors found so far, leaving only the genuinely new direction. Dividing each orthogonal vector by its own length then produces an orthonormal basis, e1, e2, e3, where every vector has length 1 as well as being mutually perpendicular.
Formula and method
The building block is the vector projection of v onto u: proj_u(v) = (v·u / u·u) u, which is the component of v that lies along u. Gram-Schmidt applies this repeatedly: u1 = v1 (the first vector is kept as-is); u2 = v2 − proj_u1(v2) (subtract the part of v2 already covered by u1); u3 = v3 − proj_u1(v3) − proj_u2(v3) (subtract the parts covered by both u1 and u2). Each u_k is guaranteed to be orthogonal to every u_j computed before it, because the projection removes exactly the component shared with that direction. Normalizing gives e_k = u_k / ‖u_k‖, where ‖u_k‖ = √(u_k·u_k) is the Euclidean norm.
Common sources of error
- Dimension mismatch: every input vector must have the same number of components (all in R², all in R³, and so on) — mixing lengths makes the dot products undefined.
- Linearly dependent inputs: if a vector lies in the span of the earlier ones, its projections cancel it out entirely, leaving a zero vector — Gram-Schmidt cannot orthogonalize a dependent set.
- Rounding intermediate steps: truncating u1 or u2 before computing the next projection compounds error into u3 and the final orthonormal basis — carry full precision through each step.
Checking your result
Verify orthogonality by checking that the dot product of any two output vectors is zero (or extremely close to it, allowing for floating-point rounding): u1·u2 ≈ 0, u1·u3 ≈ 0, and u2·u3 ≈ 0. Verify the orthonormal vectors by confirming each has length 1: e_k·e_k ≈ 1. Also confirm the span is preserved — v1, v2, and v3 should each be expressible as a linear combination of u1, u2, and u3.
Applications
Gram-Schmidt orthogonalization underlies the QR decomposition used to solve least-squares problems and linear systems numerically. Orthonormal bases simplify projections in computer graphics (camera and lighting frames), signal processing (orthogonal basis functions), and quantum mechanics (orthonormal state vectors), because coordinates in an orthonormal basis can be computed with simple dot products instead of solving a linear system.