Worked examples — Gram-Schmidt orthogonalization — algorithm
4.5.35 · D3· Maths › Linear Algebra (Full) › Gram-Schmidt orthogonalization — algorithm
Aapne parent note mein ye machine dekhi hai. Yahan hum ise har tarah ke input ke saath stress-test karenge — messy angles, degenerate (dependent) vectors, weird inner products, ek real word problem, aur ek exam twist. Har example aapko scenario table ka ek "cell" cover karta hai.
Shuru karne se pehle, ek reminder plain words mein taaki kuch bhi assume na ho.
Scenario matrix
Gram–Schmidt ek formula jaisa lagta hai, lekin behaviour bilkul badal jaata hai depending on kya feed kiya. Yahan har case class hai jo occur ho sakti hai — hum har single row neeche cover karenge.
| # | Cell / scenario | Kya special hai | Example |
|---|---|---|---|
| C1 | Do clean 2-D vectors, positive overlap | shadow along point karta hai | Ex 1 |
| C2 | Negative overlap () | shadow opposite point karta hai; ka sign flip hota hai | Ex 2 |
| C3 | Already orthogonal input | overlap , algorithm kuch nahi karta | Ex 3 |
| C4 | Full 3-D, do subtractions | dono earlier clear karne padenge | Ex 4 |
| C5 | Degenerate — dependent vector | residual , normalize nahi kar sakte | Ex 5 |
| C6 | Order matters — same set, swapped | different 's, same subspace | Ex 6 |
| C7 | Non-standard inner product (weighted) | change kar deta hai ki "perpendicular" ka kya matlab hai | Ex 7 |
| C8 | Word problem — measurements decorrelate karna | Gram–Schmidt as "common trend remove karo" | Ex 8 |
| C9 | Exam twist — QR decomposition ka read off karo | coefficients HI answer hain | Ex 9 |
Ex 1 — Cell C1: positive overlap in
Forecast (pehle guess karo!): thoda sa ke saath lean karta hai (dono up-right point karte hain), toh leftover up-and-slightly-left point karna chahiye. Aage padhne se pehle picture banane ki koshish karo.

-
. Ye step kyun? Pehle vector ke pehle koi cheez nahi hoti jiske perpendicular hona ho, isliye hum ise untouched rakhte hain — ye humara pehla clean axis define karta hai.
-
Overlap compute karo. , aur . Ye step kyun? Ye do numbers scalar banate hain — "kitne copies of , ke shadow ke andar fit hoti hain".
-
Shadow subtract karo. Ye step kyun? matlab shadow (figure mein red arrow) ke same direction mein point karta hai; ise remove karna ko perpendicular leftover (pink arrow) par wapas le jaata hai.
-
Normalize karo. , (already unit!).
Recall Verify karo
✅ perpendicular. aur ✅ orthonormal.
Ex 2 — Cell C2: negative overlap (opposite lean)
Forecast: up aur left ki taraf point karta hai, toh ye ke against lean karta hai. Expect karo ki scalar negative aayega — shadow backward point karega.

-
. Kyun? Pehla vector, as-is rakha; ye positive- axis hai.
-
Overlap: ; . Toh . Ye step kyun? Negative koi error nahi hai — matlab bas ye hai ki shadow direction mein point karta hai, bilkul ke leftward lean se match karta hai.
-
Subtract karo: . Kyun? Ek backward shadow remove karna (negative subtract karna) residual ko -axis par push kar deta hai — visibly -axis ke perpendicular.
-
Normalize karo: , toh , .
Recall Verify karo
✅. Output literally standard basis hai — sense banta hai, koi bhi 2 independent 2-D vectors comb hokar ek rotated pair of axes ban jaate hain, aur yahan wo ke saath align karte hain.
Ex 3 — Cell C3: input already orthogonal hai
Forecast: ye already right angles par hain, toh Gram–Schmidt ko sirf lengths change karne chahiye.
- .
- Overlap: , toh . Ye step kyun matter karta hai: jab overlap zero ho, shadow zero vector hota hai — subtract karne ke liye kuch bhi nahi. Ye degenerate-in-a-good-way case hai: comb seedha pass ho jaata hai.
- . Unchanged.
- Normalize karo: , .
Recall Verify karo
already pehle se tha ✅. Gram–Schmidt orthogonal input par idempotent hai — ek achha sanity check ki algorithm kabhi "over-combs" nahi karta.
Ex 4 — Cell C4: full , do subtractions
Forecast: ko do shadows clean karne padenge — ek par, ek par. Koi ek miss kiya toh perpendicularity proof collapse ho jaayega.

-
. Kyun? Base direction.
-
: , . Coefficient . Ye step kyun? Ek earlier clean vector ⇒ ek shadow remove.
-
ko DONO removals chahiye. Compute karo:
- , ⇒ coeff .
- , ⇒ coeff . Ye step kyun? Do already-orthogonal vectors hain, toh do shadows jaane chahiye — mnemonic hai "Subtract the Shadows of the Settled."
-
Coordinate-by-coordinate simplify karo:
Recall Verify karo
✅ ✅ Dono zero ⇒ saare earlier vectors ke perpendicular hai, jaise induction ne promise kiya tha.
Ex 5 — Cell C5: degenerate (dependent) input → zero vector
Forecast: bilkul exactly ke along hai, toh shadow remove karne ke baad kuch nahi bachega — residual hona chahiye, aur normalization mein zero se divide karna padega.
- .
- Overlap: , , toh .
- Subtract karo: . Ye step kyun? Poora vector shadow hi tha. Kuch bhi perpendicular nahi nikla.
Recall Verify karo
ka norm hai, jo dependence confirm karta hai. Koi bhi dependent input offending step par zero residual deta hai.
Ex 6 — Cell C6: order matters (inputs swap karo)
Forecast: hume Ex 1 se different 's milne chahiye, phir bhi wo same plane span karein ( yahan) aur orthonormal rahein. Gram–Schmidt inputs ki ordering par depend karta hai.
- . (Ex 1 mein ye ke neighbourhood mein tha — ab ye lead karta hai.)
- Overlap: , , .
- Subtract karo: . Ye step kyun? Pehle vector ne axis fix ki; doosra iske against comb hota hai.
- Normalize karo: , .
Recall Verify karo
✅ aur ✅.
Ex 7 — Cell C7: ek weighted inner product
Forecast: "perpendicular" ab weighted balance matlab hai, visual right angles nahi. Numbers change honge, lekin exact same formula chalegi — isliye parent note ne abstractly likha tha, kabhi "dot" nahi.
- .
- Weighted overlap: ; . Toh . Ye step kyun? Hum weighted inner product ko exact same mein plug karte hain — koi nayi machinery nahi chahiye.
- Subtract karo: .
Recall Verify karo
Weighted product se check karo: ✅. Note: ordinary dot product ke under bhi yahan — lekin generally weighted-orthogonal vectors paper par perpendicular nahi dikhne chahiye. Orthogonality us inner product se define hoti hai jo aapne choose ki.
Ex 8 — Cell C8: word problem (trends decorrelate karna)
Forecast: B mein clearly "flat baseline" ka ek chunk hai. B ka shadow A par subtract karne se ek pure rising residual bachna chahiye jo average zero hoga.
- — baseline direction. Kyun? Baseline ko hum "settled" reference maante hain.
- Overlap: ; ; . Ye step kyun? kehta hai B mein exactly ek poori copy baseline ki hai.
- Residual: . Kyun? Ye B hai baseline remove karke — pure day-to-day change.
Recall Verify karo
✅ baseline se independent. Interpretation check: residual sum to zero karta hai ⇒ ye koi average level carry nahi karta, sirf rising trend. Bilkul wahi jo "common baseline remove karo" ka matlab hona chahiye. (Ye Least squares regression ka seed idea hai: jo model aapke paas already hai uska projection subtract karo.)
Ex 9 — Cell C9: exam twist — QR decomposition se read off karo
Forecast: har entry sirf ek inner product hai jo aapne already compute kiya tha — koi nayi kaam nahi, yahi toh poora trick hai.
- . (Ye hai.)
- .
- . (Ye Ex 1 se hai.)
- — hamesha, kyunki ka koi component nahi ( baad mein aaya tha).
Recall Verify karo
Reconstruct karo: pehla column ✅. Doosra column ✅. Toh exactly.
Connections
- Orthogonal projection — har example mein use hone wala shadow
- Inner product spaces — Ex 7 inner product change karta hai aur machine phir bhi chalti hai
- Linear independence — Ex 5 dikhata hai dependence zero vector ke roop mein surface hoti hai
- Orthonormal basis — Ex 1, 2, 6 ka output
- QR decomposition — Ex 9 projections se seedha read karta hai
- Least squares — Ex 8 "jo already model hai usse remove karo" ka seed hai
- Gram-Schmidt orthogonalization — algorithm — parent jise ye deep-dive expand karta hai