Skip to content

The Gram-Schmidt process, step by step

6 min read

Short answer

Gram-Schmidt converts independent vectors v1,v2,…\mathbf v_1,\mathbf v_2,\dots into orthogonal vectors u1,u2,…\mathbf u_1,\mathbf u_2,\dots spanning the same space. Keep u1=v1\mathbf u_1=\mathbf v_1; for each next vector, subtract its projections onto the earlier u\mathbf u's: uk=vk−∑j<kvk⋅ujuj⋅ujuj\mathbf u_k=\mathbf v_k-\sum_{j<k}\dfrac{\mathbf v_k\cdot\mathbf u_j}{\mathbf u_j\cdot\mathbf u_j}\mathbf u_j. Divide each by its length for an orthonormal set.

Diagramu1 = v1v2u2
Subtract from v2 its shadow on u1; what remains (u2) is perpendicular to u1. Repeat for each new vector.

The recipe

  1. u1=v1\mathbf u_1=\mathbf v_1.
  2. u2=v2−proj⁡u1v2\mathbf u_2=\mathbf v_2-\operatorname{proj}_{\mathbf u_1}\mathbf v_2.
  3. u3=v3−proj⁡u1v3−proj⁡u2v3\mathbf u_3=\mathbf v_3-\operatorname{proj}_{\mathbf u_1}\mathbf v_3-\operatorname{proj}_{\mathbf u_2}\mathbf v_3, and so on.
  4. Optional: qk=uk/∣uk∣\mathbf q_k=\mathbf u_k/|\mathbf u_k|.

Each step removes the part of vk\mathbf v_k that already lies in the span of the earlier vectors, leaving only the new direction.

Why it is useful

The process produces the QR factorization A=QRA=QR, with orthonormal columns in QQ and RR upper triangular. Orthonormal columns make least squares and projections much simpler. If uk\mathbf u_k comes out as 0\mathbf 0, the original vectors were dependent.

Worked example

Apply Gram-Schmidt to v1=(1,1,0)\mathbf v_1=(1,1,0) and v2=(1,0,1)\mathbf v_2=(1,0,1) and normalize.

u1=(1,1,0)\mathbf u_1=(1,1,0). Then v2⋅u1=1\mathbf v_2\cdot\mathbf u_1=1 and u1⋅u1=2\mathbf u_1\cdot\mathbf u_1=2, so u2=(1,0,1)−12(1,1,0)=(12,−12,1).\mathbf u_2=(1,0,1)-\tfrac12(1,1,0)=\left(\tfrac12,-\tfrac12,1\right). Check: u1⋅u2=12−12=0\mathbf u_1\cdot\mathbf u_2=\tfrac12-\tfrac12=0. ✓

Lengths: ∣u1∣=2|\mathbf u_1|=\sqrt2 and ∣u2∣=14+14+1=32|\mathbf u_2|=\sqrt{\tfrac14+\tfrac14+1}=\sqrt{\tfrac32}. So q1=12(1,1,0)\mathbf q_1=\tfrac1{\sqrt2}(1,1,0) and q2=16(1,−1,2)\mathbf q_2=\tfrac1{\sqrt6}(1,-1,2).

Try it yourself

Orthogonalize v1=(3,4)\mathbf v_1=(3,4) and v2=(1,0)\mathbf v_2=(1,0).

Show the answer

u1=(3,4)\mathbf u_1=(3,4). v2⋅u1=3\mathbf v_2\cdot\mathbf u_1=3 and u1⋅u1=25\mathbf u_1\cdot\mathbf u_1=25, so u2=(1,0)−325(3,4)=(1625,−1225)\mathbf u_2=(1,0)-\tfrac3{25}(3,4)=\left(\tfrac{16}{25},-\tfrac{12}{25}\right). Check: 3⋅1625−4⋅1225=03\cdot\tfrac{16}{25}-4\cdot\tfrac{12}{25}=0.

Keep going with practice

Gram-Schmidt builds on projections and orthogonality in Vidi's Linear Algebra & Probability course.