4.5.35Linear Algebra (Full)

Gram-Schmidt orthogonalization — algorithm

1,572 words7 min readdifficulty · medium6 backlinks

What it does


Deriving the algorithm from scratch (HOW + WHY)

The whole machine rests on ONE tool: projection of a vector onto another vector.

Step 1 — Project vv onto uu. We want a scalar cc such that cucu is the shadow of vv along uu, and the leftover r=vcur = v - cu is orthogonal to uu. Impose orthogonality: vcu,  u=0    v,ucu,u=0    c=v,uu,u.\langle v - cu,\; u\rangle = 0 \implies \langle v,u\rangle - c\langle u,u\rangle = 0 \implies c = \frac{\langle v,u\rangle}{\langle u,u\rangle}.

Step 2 — Build the orthogonal set one vector at a time.

  • u1=v1u_1 = v_1 (first vector is already "clean"; nothing to remove yet).
  • For each new vkv_k, subtract its overlap with every already-built u1,,uk1u_1,\dots,u_{k-1}:

Why subtract from all previous uju_j? Each uju_j is already mutually orthogonal, so removing the overlap with each one independently leaves uku_k perpendicular to all of them simultaneously. Let's prove the key claim.

Figure — Gram-Schmidt orthogonalization — algorithm

Worked Example 1 (in R2\mathbb{R}^2)

Orthonormalize v1=(3,1),  v2=(2,2)v_1=(3,1),\; v_2=(2,2).

Step A: u1=v1=(3,1)u_1 = v_1 = (3,1). Why? First vector is taken as-is.

Step B: v2,u1=23+21=8\langle v_2,u_1\rangle = 2\cdot3 + 2\cdot1 = 8, and u1,u1=9+1=10\langle u_1,u_1\rangle = 9+1 = 10. u2=(2,2)810(3,1)=(2,2)(2.4,0.8)=(0.4,1.2).u_2 = (2,2) - \frac{8}{10}(3,1) = (2,2) - (2.4,\,0.8) = (-0.4,\,1.2). Why? We removed the part of v2v_2 leaning along u1u_1.

Check: u1,u2=3(0.4)+1(1.2)=1.2+1.2=0.\langle u_1,u_2\rangle = 3(-0.4)+1(1.2) = -1.2+1.2 = 0.

Step C — normalize: u1=10\lVert u_1\rVert=\sqrt{10}, u2=0.16+1.44=1.6\lVert u_2\rVert=\sqrt{0.16+1.44}=\sqrt{1.6}. e1=110(3,1),e2=11.6(0.4,1.2).e_1 = \tfrac{1}{\sqrt{10}}(3,1),\qquad e_2 = \tfrac{1}{\sqrt{1.6}}(-0.4,1.2).


Worked Example 2 (in R3\mathbb{R}^3)

Orthogonalize v1=(1,1,0),  v2=(1,0,1),  v3=(0,1,1)v_1=(1,1,0),\; v_2=(1,0,1),\; v_3=(0,1,1).

  • u1=(1,1,0)u_1=(1,1,0).
  • v2,u1=1\langle v_2,u_1\rangle = 1, u1,u1=2\langle u_1,u_1\rangle=2: u2=(1,0,1)12(1,1,0)=(12,12,1).u_2=(1,0,1)-\tfrac12(1,1,0)=(\tfrac12,-\tfrac12,1).
  • For u3u_3 subtract overlaps with both u1u_1 and u2u_2. v3,u1=1, u1,u1=2\langle v_3,u_1\rangle = 1,\ \langle u_1,u_1\rangle=2. v3,u2=012+1=12, u2,u2=14+14+1=32\langle v_3,u_2\rangle = 0-\tfrac12+1=\tfrac12,\ \langle u_2,u_2\rangle=\tfrac14+\tfrac14+1=\tfrac32. u3=(0,1,1)12(1,1,0)1/23/2(12,12,1)=(0,1,1)(12,12,0)(16,16,13).u_3=(0,1,1)-\tfrac12(1,1,0)-\tfrac{1/2}{3/2}(\tfrac12,-\tfrac12,1)=(0,1,1)-(\tfrac12,\tfrac12,0)-(\tfrac16,-\tfrac16,\tfrac13). u3=(23,23,23).u_3=(-\tfrac23,\tfrac23,\tfrac23). Why this step? Two subtractions because there are two earlier orthogonal vectors to clear. Check: u3,u1=23+23+0=0\langle u_3,u_1\rangle = -\tfrac23+\tfrac23+0=0, u3,u2=1313+23=0\langle u_3,u_2\rangle=-\tfrac13-\tfrac13+\tfrac23=0. ✅

Common mistakes


Recall Feynman: explain to a 12-year-old

Imagine your friends each cast a shadow on a wall. You want everyone to stand in directions where their shadows don't overlap at all. Take the first friend as the reference. For the next friend, look at how much they overlap the first one's direction, and slide them sideways until that overlap is zero. For each new friend, remove the overlap with everyone already placed. After that, all friends point in totally separate (right-angle) directions, and you can shrink each to the same height (unit length). That's Gram–Schmidt: remove the overlap, keep the leftover.


Flashcards

What single operation is the building block of Gram–Schmidt?
Projection of a vector onto another: proju(v)=v,uu,uu\operatorname{proj}_u(v)=\frac{\langle v,u\rangle}{\langle u,u\rangle}u.
Why does subtracting the projection make the residual orthogonal?
We choose the scalar c=v,uu,uc=\frac{\langle v,u\rangle}{\langle u,u\rangle} exactly so vcu,u=0\langle v-cu,u\rangle=0.
State the Gram–Schmidt recursion.
uk=vkj<kvk,ujuj,ujuju_k=v_k-\sum_{j<k}\frac{\langle v_k,u_j\rangle}{\langle u_j,u_j\rangle}u_j.
Why subtract from the uju_j and not the vjv_j?
Only the uju_j are already mutually orthogonal, so cross terms vanish; using vjv_j leaves nonzero overlaps.
What does it mean if some uk=0u_k=0 during the process?
vkv_k was linearly dependent on earlier vectors; the input set was not independent.
How do you get an orthonormal set from the orthogonal one?
Divide each uku_k by its norm: ek=uk/uke_k=u_k/\lVert u_k\rVert.
If you use already-normalized eje_j, how does the recursion simplify?
uk=vkj<kvk,ejeju_k=v_k-\sum_{j<k}\langle v_k,e_j\rangle e_j (denominators become 1).
What matrix factorization is Gram–Schmidt equivalent to?
A=QRA=QR, with QQ's columns the orthonormal eke_k and RR upper-triangular holding the projection coefficients.

Connections

Concept Map

messy directions

produces

normalize

core tool of

forces scalar c

start of

subtract overlaps

remove overlap keep leftover

same subspace as

proof by induction

used in

Independent vectors vi

Gram-Schmidt algorithm

Orthogonal set ui

Orthonormal set ei

Projection proj_u v

Orthogonality condition

u1 equals v1

Recursion uk

uk perpendicular to all uj

QR decomposition Q

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Dekho, Gram–Schmidt ka core idea bilkul simple hai: tumhare paas kuch independent vectors hain jo tedhe-medhe directions mein point kar rahe hain, aur tum chahte ho ki unko aise vectors mein convert kar do jo aapas mein perpendicular (90 degree) ho, lekin same space ko span karein. Iska fayda yeh hai ki perpendicular directions mein coordinates independent ho jaate hain, projections aasan ho jaate hain, aur QR decomposition jaisa kaam clean nikalta hai.

Pura algorithm ek hi tool pe khada hai — projection. Agar tumhare paas ek saaf direction uu hai aur ek messy vector vv hai, to vv ka jo hissa uu ke along jhukta hai woh hai proju(v)=v,uu,uu\operatorname{proj}_u(v)=\frac{\langle v,u\rangle}{\langle u,u\rangle}u. Ab agar tum yeh shadow subtract kar do, jo bachta hai woh automatically uu ke perpendicular hota hai. Yeh scalar cc koi guess nahi hai — humne use force kiya vcu,u=0\langle v-cu,u\rangle=0 se, isliye answer guaranteed perpendicular aata hai.

Ab algorithm: pehla vector u1=v1u_1=v_1 as-it-is. Har naye vkv_k se uske saare pehle ban chuke clean vectors u1,,uk1u_1,\dots,u_{k-1} ke shadows subtract kar do. Ek bahut common galti — students vjv_j pe project karte hain, but karna uju_j pe hai, kyunki sirf uju_j aapas mein orthogonal hain, isliye cross terms zero ho jaate hain aur proof chalta hai. End mein har vector ko uski length se divide karke unit (orthonormal) bana lo. Agar koi uku_k zero aa jaye, matlab tumhare input vectors independent the hi nahi.

Go deeper — visual, from zero

Test yourself — Linear Algebra (Full)

Connections