Gram–Schmidt Orthogonalization
Problem
Orthogonalize the set {[1,1,0], [1,0,1]} using the Gram–Schmidt process, then normalize to get an orthonormal basis.
Explanation
What Gram–Schmidt does
Given a list of linearly independent vectors , the Gram–Schmidt process produces an orthogonal list spanning the same subspace. Dividing each by its length gives an orthonormal basis .
The formulas
The formula subtracts the projection of onto every previously-computed . What's left is orthogonal to all of them.
Normalize: .
Step-by-step
.
Step 1 — .
Length: .
Step 2 — Project onto .
Projection coefficient: .
Projection vector: .
Step 3 — Subtract to get .
Check orthogonality: ✓
Step 4 — Normalize.
Verification
- ✓
- ✓
- ✓
Why Gram–Schmidt matters
- QR decomposition: any full-column-rank matrix factors as where 's columns are the Gram–Schmidt orthonormalization of 's columns and is upper triangular.
- Least squares: QR makes least-squares problems numerically stable.
- Orthonormal bases: critical for projections, coordinate changes, and Fourier-like expansions.
- Numerical linear algebra: modified Gram–Schmidt (a slight variation) is used inside many iterative solvers.
Geometric picture
Each step builds the next vector by removing any component of the new vector that's already covered by earlier ones. You end up with vectors that span the same subspace but form a set of perpendicular "axes" — the natural coordinate system for that subspace.
The modified Gram–Schmidt (stability note)
The formulas above are "classical" Gram–Schmidt. In finite-precision arithmetic, it can lose orthogonality fast. The modified Gram–Schmidt subtracts projections one at a time during each step, which is more numerically stable and what most libraries actually implement.
Common mistakes
- Normalizing before subtracting projections. You need the unnormalized inside the projection formula. Normalize only at the end (or after each step if you also divide by , which simplifies).
- Using the original in later projections instead of the new . Classical Gram–Schmidt uses the 's; that's essential.
- Applying to linearly dependent vectors. If a is a combination of earlier vectors, you'll get (the projection covers everything).
Try it in the visualization
Two input vectors are drawn in 3D. The first stays put; the second shrinks down to its component orthogonal to the first as the projection is subtracted. Both are then normalized to unit length, ending with perpendicular blue arrows of equal length.
Interactive Visualization
Parameters
Got your own math or physics problem?
Turn any problem into an interactive visualization like this one — powered by AI, generated in seconds. Free to try, no credit card required.