34. Gram–Schmidt

Given a linearly independent set {𝑣1,𝑣2,,𝑣𝑘}, the Gram–Schmidt process produces an orthonormal set {𝑞1,𝑞2,,𝑞𝑘} that spans the same subspace.

It “straightens out” the basis: removes the parallel components between successive vectors so they become mutually orthogonal, then normalizes each.

34.1. The algorithm

Process the input vectors one at a time. For each new vector, subtract off its projection onto the orthonormal vectors already built, then normalize.

For 𝑗=1,2,,𝑘:

𝑢𝑗=𝑣𝑗𝑖=1𝑗1(𝑣𝑗𝑞𝑖)𝑞𝑖(subtract projections off the already-orthonormal vectors)𝑞𝑗=𝑢𝑗𝑢𝑗(normalize)

The first step is just normalization: 𝑞1=𝑣1𝑣1.

Example

𝑣1=[110], 𝑣2=[011] in 3.

Step 1: 𝑞1=𝑣1𝑣1=12[110].

Step 2: project 𝑣2 onto 𝑞1 and subtract:

𝑣2𝑞1=12𝑢2=𝑣212𝑞1=[011]12[110]=[12121]

Normalize: 𝑢2=14+14+1=32.

𝑞2=23[12121]=16[112]

Verify: 𝑞1𝑞2=0 and 𝑞1=𝑞2=1.

34.2. Why it works

After subtracting the projections, 𝑢𝑗 is orthogonal to every previously-built 𝑞𝑖. Inductively, after step 𝑗, the set {𝑞1,,𝑞𝑗} is orthonormal and spans the same subspace as {𝑣1,,𝑣𝑗}.

34.3. Numerical instability

Classical Gram–Schmidt (the version above) is unstable in floating point — small rounding errors compound, and the computed 𝑞𝑗’s drift away from being truly orthogonal.

Better alternatives:

For pencil-and-paper or symbolic use, classical Gram–Schmidt is fine. For numerical libraries, Householder is standard.

34.4. Connection to QR

The Gram–Schmidt process is exactly the construction behind the QR decomposition: the orthonormal vectors form 𝑄, and the projection coefficients form 𝑅.

34.5. See also