4.5.41 · D3 · HinglishLinear Algebra (Full)

Worked examplesLeast squares — normal equations, QR approach

2,933 words13 min read↑ Read in English

4.5.41 · D3 · Maths › Linear Algebra (Full) › Least squares — normal equations, QR approach

Shuru karne se pehle, vocabulary ki ek reminder taaki koi symbol anjaan na rahe:

Ek aur symbol jis par hum baad mein lean karenge:


Scenario matrix

Har least-squares question jo tum miloge woh in cells mein se ek (ya blend) hogi. Last column us example ka naam deta hai jo use clear karta hai.

# Case class Isme kya special hai Clear karta hai
C1 Overdetermined, full rank rows unknowns se zyada, columns independent — "textbook" case Ex 1
C2 Exactly determined / consistent already mein hai, residual Ex 2
C3 QR route same data par [[Condition Number condition number]] ko square karne se bachna
C4 Rank-deficient ( singular) dependent columns → infinitely many Ex 4
C5 Weighted / units word problem real-world regression, mixed scales Ex 5
C6 Degenerate limit: do coincident data points jab points merge hote hain toh kya hota hai Ex 6
C7 Projection-matrix viewpoint compute karo, check karo, ko fit + residual mein split karo Ex 7
C8 Exam twist: fit through a fixed point constrained model, ek column drop karo Ex 8

Hum inhe order mein karte hain. Cells C1, C2, C6, C7 ko ek figure milti hai kyunki geometry kaam kar rahi hai.


Example 1 — Overdetermined, full rank (cell C1)

Neeche ki figure mein chaar coral data points aur lavender best-fit line plot ki gayi hai jo hum abhi compute karne wale hain; mint verticals residuals hain — woh upar-neeche ki misses jo least squares jitni ho sake utni chhoti banata hai.

Figure — Least squares — normal equations, QR approach

Step 1 — aur banao. Yeh step kyun? Har row kehti hai "predict by ". Column one all-ones hai (intercept ); column two mein hain (slope ).

Step 2 — aur banao. Yeh step kyun? ki entries column dot products hain: , , . har column ko se dot karta hai.

Step 3 — system solve karo. Determinant . Cramer se: Yeh step kyun? invertible hai (full column rank), toh unique hai.

Best line: . Slope negative hai — forecast confirm hua. Figure mein lavender line wakai neechay tilt hai.

Verify: par predictions hain; residual . Orthogonality check karo: aur . ✓ (Dono VERIFY mein check kiye gaye hain.)


Example 2 — Consistent system, zero residual (cell C2)

Figure mein teen coral points lavender line par dead-on baithe hain, toh koi bhi mint residual sticks draw nahi hain — zero residual ki picture.

Figure — Least squares — normal equations, QR approach

Step 1 — setup karo. Yeh step kyun? Bilkul pehle jaisa, har row encode karti hai "predict by ": all-ones pehla column intercept carry karta hai, doosra column inputs slope ke liye carry karta hai. Sirf (measured -values) Ex 1 se badlate hain.

Step 2 — normal equations. , . Yeh step kyun? Hum ko par project karte hain residual ko dono columns ke perpendicular force karke; entries phir se column dot products hain (, , ) aur har column ko se dot karta hai.

Step 3 — solve karo. aur se: subtract karo → , phir . Yeh step kyun? Do do unknowns mein do linear equations; pehli ko doosri se subtract karne par cancel hota hai (dono ka coefficient hai), ek equation mein bacha rehta hai. ko pehle mein back-substitute karo nikalne ke liye — wohi elimination jo tum kisi bhi system par karte ho.

Line: — exact line, jaise forecast tha.

Verify: predictions , toh . Jab , projection hi hai aur least squares ordinary solve mein degenerate ho jaata hai. ✓


Example 3 — Same data QR se (cell C3)

Step 1 — orthonormalise karo. kyunki . Projection coefficient . Remove karo: . Normalise karo: . Yeh step kyun? Orthonormal columns projection ko simple dot products mein turn kar dete hain — koi matrix inverse nahi chahiye.

Step 2 — padho. Yeh step kyun? , , .

Step 3 — compute karo aur back-substitute karo. bottom-up solve karo: ; phir . Yeh step kyun? upper triangular hai toh last equation mein ek unknown hai — back-substitution fast hai aur condition number ko square nahi karta.

Verify: , Ex 2 se exactly match. ✓


Example 4 — Rank-deficient: infinitely many solutions (cell C4)

Step 1 — rank spot karo. se spanned ek single line hai; rank , nahi. Yeh step kyun? Agar columns do independent directions span nahi karte, toh hum do coordinates pin down nahi kar sakte.

Step 2 — normal equations. Singular — koi inverse nahi. . Yeh step kyun? Normal equations tab bhi sahi machinery hain jab columns dependent hon — hum inhe exactly usual tarah form karte hain (entries column dot products hain, har column ko se dot karta hai). Determinant compute karna humein pehle hi bata deta hai ki yeh invert nahi ho sakta, jo is case ka poora point hai.

Step 3 — SAARE solutions describe karo. System (doosri row bas yahi hai) deta hai . koi bhi real number ho aur set karo; phir , toh har jahan ek valid least-squares solution hai. Yeh step kyun? Ek equation, do unknowns → doosra unknown free hai, toh answers ki poori ek line, free parameter se indexed.

Step 4 — projection phir bhi unique hai. Kisi bhi aise ke liye, . Yeh step kyun? Ambiguous direction ke along alag-alag sab ke same point par map hote hain — ka projection. Pseudoinverse minimum-norm representative choose karta hai.

Verify: residual ; check . Minimum-norm choice minimize karta hai: derivative , deta hai . ✓


Example 5 — Word problem real units ke saath (cell C5)

Step 1 — one-column . Yeh step kyun? Model mein ek unknown hai aur yeh origin se pass karta hai, toh koi all-ones column nahi — bas values. Yeh origin se regression hai.

Step 2 — scalar normal equation. Ek column ke saath, aur scalars hain: Yeh step kyun? Dot product bade stretches ko zyada weight deta hai — unke paas zyada "leverage" hota hai.

Step 3 — solve karo. N/cm. Yeh step kyun? Sirf ek unknown ke saath normal equation ek single scalar equation mein collapse ho jaati hai; dono sides ko scalar se divide karne par isolate ho jaata hai — "invert " ka one-dimensional version.

Verify: units check — N/cm. ✓ Predicted forces data ko hug karte hain; residuals chhote hain. ✓ ( VERIFY mein checked hai.)


Example 6 — Degenerate limit: coincident data (cell C6)

Figure mein do clashing coral points par stacked hain ( aur ); butter dot wahan mark karta hai jahan lavender fit-line actually pass karti hai — right unke beech par, mint stick se dikhaya gaya vertical average.

Figure — Least squares — normal equations, QR approach

Step 1 — setup karo. Yeh step kyun? Do rows same share karti hain; design phir bhi full column rank hai (columns aur independent hain), toh ek unique line exist karta hai.

Step 2 — normal equations. , , .

Step 3 — interpret karo. Line . par yeh predict karta hai — exactly do clashing readings aur ka average, jaise forecast tha. Yeh step kyun? Jab kai rows same input share karti hain, least squares wahan sirf ek output choose kar sakta hai, aur distance-minimising choice unka mean hota hai.

Verify: predictions , residual ; , . ✓


Example 7 — Projection matrix, split karo (cell C7)

Figure ek 2D schematic hai: lavender line hai, coral arrow hai, mint arrow line par uski shadow hai, aur dashed slate segment residual hai — line se right angle par milta hai (marked), jo exactly woh orthogonality hai jo least squares enforce karta hai.

Figure — Least squares — normal equations, QR approach

Step 1 — definition se banao. Recall . Yahan single column hai, toh (ek scalar) hai, iska inverse hai, aur all-ones matrix hai. Substitute karne par, Yeh step kyun? Ek column ke saath, general formula collapse ho kar ban jaata hai — us line par orthogonal projection. ki har row hai, yaani "teen entries ka average lo" — exactly wohi jo par projecting karna chahiye.

Step 2 — idempotence check. kyunki already-constant vector ko average karna kuch nahi badalta, aur kyunki all-ones matrix symmetric hai. Yeh step kyun? Do baar project karna = ek baar; yeh do identities (, ) kisi bhi projection matrix ki defining fingerprints hain, confirm karte hain ki hum ne sahi banaya.

Step 3 — ko fit + residual mein split karo. Yeh step kyun? line mein hai (fit — yeh ka multiple hai), us par perpendicular hai (miss); do pieces milke bante hain, ise "explained" aur "leftover" mein split karte hain.

Verify: ✓; (Pythagoras). ✓


Example 8 — Exam twist: fit ek fixed point se force kiya gaya (cell C8)

Step 1 — model reduce karo. force karna intercept column remove kar deta hai, ek single column of -values chhodta hai: Yeh step kyun? "Origin se pass karo" ki hard constraint ek extra equation bolt karne ki baat nahi — yeh unknown ko delete karta hai, ko do columns se shrink karke ek mein laata hai. Kam unknowns, same least-squares machinery.

Step 2 — scalar solve. Ek column ke saath, aur , toh Yeh step kyun? Ex 5 wala wohi origin-regression scalar formula: ek unknown matlab normal equation ek single scalar equation hai, divide karke solve hoti hai.

Step 3 — interpret karo. Best origin line: , slope forecast band ke andar.

Verify: ; predictions , residual , check . ✓


Recall Main kis cell mein hoon? (decision flow)

Kya invertible hai? ::: Haan → unique (C1/C2/C5/C6/C8). Nahi → infinitely many, pseudoinverse use karo (C4). Kya already Col(A) mein hai? ::: Tab residual zero hai aur least squares ek ordinary exact solve mein reduce ho jaata hai (C2). Kya model ek fixed point se pass karna chahiye? ::: Corresponding column drop karo, re-solve karo (C8). Rounding / bade condition number se darr? ::: QR use karo: (C3).

Active Recall

Rank-deficient case mein fit unique kyun hoti hai jab nahi hota?
Saare solutions Col(A) ke same point par map hote hain — ka projection — sirf ke null space ke along alag hote hain.
Coincident-input dataset mein line wahan kaun sa predict karti hai?
Clashing -values ka average (distance-minimising single output).
Least squares mein "line through the origin" kaise enforce karte hain?
Intercept (all-ones) column drop karo, ek-column origin regression chhodta hai.
Residual zero kab hota hai?
Jab (consistent system); projection khud return karta hai.
Col(A) par projection matrix likho aur uski do defining properties batao.
, jahan aur .