Step 1 — make the first axis.
We need a unit vector pointing along a1:
u1=a1,q1=∥u1∥u1.Why?q1 is our first orthonormal direction; everything else will be measured against it.
Step 2 — remove what's already explained.
For a2, subtract its shadow (projection) onto q1:
u2=a2−(q1⊤a2)q1,q2=∥u2∥u2.Why? The leftover u2 is the part of a2perpendicular to q1, so q2⊥q1.
Step k — subtract all previous shadows.uk=ak−∑i<k(qi⊤ak)qi,qk=∥uk∥uk.
Step — read off R. Invert each relation to express the original ak in terms of the qi:
ak=rkk∥uk∥qk+∑i<krik(qi⊤ak)qi.
So the coefficient of qi in ak is
rik=qi⊤ak(i<k),rkk=∥uk∥,rik=0(i>k).
Stacking ak=∑irikqi over all k is exactly the matrix equation A=QR. ∎
Why QR helps.∥Ax−b∥2=∥QRx−b∥2. Since Q preserves length, multiply inside by Q⊤ (extend to full Q): the minimizer satisfies
Rx=Q⊤b.Why?A=QR⇒A⊤Ax=A⊤b⇒R⊤Q⊤QRx=R⊤Q⊤b⇒R⊤Rx=R⊤Q⊤b. Cancel invertible R⊤: Rx=Q⊤b. No squaring of A → numerically stable.
Why is R upper triangular? → because ak uses only q1…qk.
What's the least-squares shortcut? → Rx=Q⊤b.
What property does Q guarantee? → Q⊤Q=I (length/angle preserving).
What makes QR unique? → rkk>0.
Recall Feynman: explain to a 12-year-old
Imagine you have three slightly crooked arrows drawn on paper. You want to describe them using a clean set of perpendicular arrows (like the corner of a room: up, right, forward). First you keep arrow 1, just shrink it to length 1 — that's your first clean direction. For arrow 2, you erase the part that points the same way as arrow 1, and whatever's left points in a brand-new perpendicular direction — clean it up to length 1. Repeat. The clean perpendicular arrows are the columns of Q. The "how much of each clean arrow I used" instructions form R. Multiply them back and you rebuild the original crooked arrows: A=QR.
Dekho, QR decomposition ka matlab simple hai: tumhare paas matrix A hai jiske columns thode "tedhe" (skewed) hain, aur tum unhe do clean hisson me todh dete ho — A=QR. Yaha Q ke columns orthonormal hote hain (yaani perpendicular aur length exactly 1), aur R upper-triangular hota hai. Soch lo ki Q ek "clean perpendicular axes" ka set hai (jaise room ka corner), aur R wo recipe hai jo batata hai ki original tedhe columns ko in clean axes se kaise banao.
Ye banta kaise hai? Bas Gram–Schmidt process se. Pehla column le lo, normalize karke q1 banao. Doosre column me se uska wo part hata do jo q1 ke direction me already point kar raha hai (uski "shadow" / projection), bacha hua part automatically perpendicular hoga — usko normalize karke q2. Aise hi aage badhte jao. Jo projection coefficients (qi⊤ak) nikalte ho, wahi R ke entries ban jaate hain. Aur kyunki har ak sirf pehle waale q's se banta hai, isliye R apne aap upper-triangular ho jaata hai — yahi key insight hai.
Iska sabse bada faayda least squares me hai. Jab Ax=b ka exact solution nahi milta, tab normal equation A⊤Ax=A⊤b use karte hain — lekin A⊤A banane se numbers bigad jaate hain (condition number square ho jaata hai). QR me direct Rx=Q⊤b solve karo back-substitution se — fast aur stable. Exam aur real computation, dono me ye trick gold hai.
Do common galtiyan yaad rakhna: thin QR me Q square nahi hota, sirf Q⊤Q=I hota hai (poora QQ⊤=I nahi). Aur QR unique tabhi hota hai jab R ke diagonal positive ho. Bas itna dhyaan rakho, baaki concept solid hai.