Gram–Schmidt Orthogonalization

April 13, 2026

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 {v1,,vk}\{\mathbf{v}_1, \ldots, \mathbf{v}_k\}, the Gram–Schmidt process produces an orthogonal list {u1,,uk}\{\mathbf{u}_1, \ldots, \mathbf{u}_k\} spanning the same subspace. Dividing each ui\mathbf{u}_i by its length gives an orthonormal basis {q1,,qk}\{\mathbf{q}_1, \ldots, \mathbf{q}_k\}.

The formulas

u1=v1\mathbf{u}_1 = \mathbf{v}_1 uk=vki=1k1vkuiuiuiui\mathbf{u}_k = \mathbf{v}_k - \sum_{i=1}^{k-1} \dfrac{\mathbf{v}_k \cdot \mathbf{u}_i}{\mathbf{u}_i \cdot \mathbf{u}_i} \, \mathbf{u}_i

The formula subtracts the projection of vk\mathbf{v}_k onto every previously-computed ui\mathbf{u}_i. What's left is orthogonal to all of them.

Normalize: qi=ui/ui\mathbf{q}_i = \mathbf{u}_i / \|\mathbf{u}_i\|.

Step-by-step

v1=(1,1,0),v2=(1,0,1)\mathbf{v}_1 = (1, 1, 0), \quad \mathbf{v}_2 = (1, 0, 1).

Step 1 — u1=v1=(1,1,0)\mathbf{u}_1 = \mathbf{v}_1 = (1, 1, 0).

Length: u1=1+1+0=2\|\mathbf{u}_1\| = \sqrt{1 + 1 + 0} = \sqrt{2}.

Step 2 — Project v2\mathbf{v}_2 onto u1\mathbf{u}_1. v2u1=(1)(1)+(0)(1)+(1)(0)=1\mathbf{v}_2 \cdot \mathbf{u}_1 = (1)(1) + (0)(1) + (1)(0) = 1 u1u1=2\mathbf{u}_1 \cdot \mathbf{u}_1 = 2

Projection coefficient: 1/21/2.

Projection vector: 12(1,1,0)=(12,12,0)\dfrac{1}{2} (1, 1, 0) = (\tfrac{1}{2}, \tfrac{1}{2}, 0).

Step 3 — Subtract to get u2\mathbf{u}_2. u2=v2proj=(1,0,1)(12,12,0)=(12,12,1)\mathbf{u}_2 = \mathbf{v}_2 - \text{proj} = (1, 0, 1) - (\tfrac{1}{2}, \tfrac{1}{2}, 0) = (\tfrac{1}{2}, -\tfrac{1}{2}, 1)

Check orthogonality: u2u1=(12)(1)+(12)(1)+(1)(0)=1212+0=0\mathbf{u}_2 \cdot \mathbf{u}_1 = (\tfrac{1}{2})(1) + (-\tfrac{1}{2})(1) + (1)(0) = \tfrac{1}{2} - \tfrac{1}{2} + 0 = 0

Step 4 — Normalize. u2=14+14+1=32=62\|\mathbf{u}_2\| = \sqrt{\tfrac{1}{4} + \tfrac{1}{4} + 1} = \sqrt{\tfrac{3}{2}} = \dfrac{\sqrt{6}}{2}

q1=u1u1=12(1,1,0)=(22,22,0)\mathbf{q}_1 = \dfrac{\mathbf{u}_1}{\|\mathbf{u}_1\|} = \dfrac{1}{\sqrt{2}} (1, 1, 0) = \left(\tfrac{\sqrt{2}}{2}, \tfrac{\sqrt{2}}{2}, 0\right)

q2=u2u2=26(12,12,1)=(66,66,63)\mathbf{q}_2 = \dfrac{\mathbf{u}_2}{\|\mathbf{u}_2\|} = \dfrac{2}{\sqrt{6}} \left(\tfrac{1}{2}, -\tfrac{1}{2}, 1\right) = \left(\tfrac{\sqrt{6}}{6}, -\tfrac{\sqrt{6}}{6}, \tfrac{\sqrt{6}}{3}\right)

Verification

  • q12=1/2+1/2+0=1\|\mathbf{q}_1\|^2 = 1/2 + 1/2 + 0 = 1
  • q22=1/6+1/6+4/6=1\|\mathbf{q}_2\|^2 = 1/6 + 1/6 + 4/6 = 1
  • q1q2=12121212+0=0\mathbf{q}_1 \cdot \mathbf{q}_2 = \tfrac{\sqrt{12}}{12} - \tfrac{\sqrt{12}}{12} + 0 = 0

Why Gram–Schmidt matters

  • QR decomposition: any full-column-rank matrix AA factors as A=QRA = QR where QQ's columns are the Gram–Schmidt orthonormalization of AA's columns and RR 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 ui\mathbf{u}_i inside the projection formula. Normalize only at the end (or after each step if you also divide by qiqi=1\mathbf{q}_i \cdot \mathbf{q}_i = 1, which simplifies).
  • Using the original vi\mathbf{v}_i in later projections instead of the new ui\mathbf{u}_i. Classical Gram–Schmidt uses the u\mathbf{u}'s; that's essential.
  • Applying to linearly dependent vectors. If a vk\mathbf{v}_k is a combination of earlier vectors, you'll get uk=0\mathbf{u}_k = \mathbf{0} (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

1.00
1.00
0.00
1.00
0.00
1.00
Your turn

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.

Sign Up Free to Try It30 free visualizations every day
Gram–Schmidt Orthogonalization | MathSpin