Exercises — LU decomposition (numerical)
4.8.19 · D4· Maths › Numerical Methods › LU decomposition (numerical)
Quick reminders jo tum har jagah reuse karoge (sab parent se):

Level 1 — Recognition
Exercise 1.1
In mein se kaun si matrix lower triangular hai, kaun si upper triangular hai, aur kaun si kuch bhi nahi? Triangular walon ke liye batao ki kya ye ek valid Doolittle ho sakti hai (diagonal par ones).
Recall Solution
- : diagonal ke upar entries hain → lower triangular. Diagonal hai → haan, ek valid Doolittle hai.
- : diagonal ke neeche entries hain → upper triangular. (Ye ek hai, nahi.)
- : below-diagonal entry hai, above-diagonal entry hai → lower triangular, lekin diagonal hai → ye Doolittle nahi hai (ye ek Crout-style hogi, dekho Crout Decomposition).
- : upar aur neeche dono jagah nonzero entries hain → na upper na lower.
Exercise 1.2
Kuch bhi multiply kiye bina, aur batao in ke liye:
Recall Solution
Ek triangular matrix ka determinant uski diagonal ka product hota hai (dekho Determinants). Toh Doolittle form mein hamesha hota hai, aur isliye hota hai.
Level 2 — Application
Exercise 2.1
Is matrix ka Doolittle aur nikalo:
Recall Solution
ki Row 1 ( ki top row hai): , . ka Column 1: . ki Row 2: . Check: ✓
Exercise 2.2
Exercise 2.1 ke use karke solve karo jahan hai.
Recall Solution
Forward solve (top-down, ek unknown per row): ; . Back solve (bottom-up): ; . Sanity check: ✓
Exercise 2.3
Is matrix ko factor karo:
Recall Solution
ki Row 1: . ka Column 1: , . ki Row 2: , . ka Column 2: . ki Row 3: . Check: (multiply karke confirm karo). ✓
Level 3 — Analysis
Exercise 3.1
Matrix invertible hai (). Dikhao ki plain Doolittle fail karta hai, phir ise Partial Pivoting se repair karo taaki mile.
Recall Solution
Failure: , toh — division by zero. Plain LU khatam ho jaata hai, even though perfectly invertible hai; problem sirf zero pivot ki hai, singularity ki nahi. Repair: rows swap karo taaki larger-magnitude entry () pivot par aa jaye. Ye swap permutation matrix hai (dekho Permutation Matrices) Ab par Doolittle karo: ; ; . solve karne ke liye tum solve karte, phir .
Exercise 3.2
Is matrix ke liye: partial pivoting ko se compare karta hai. Pivoted factorization perform karo aur verify karo ki hai.
Recall Solution
, toh rows swap karo: , . ; ; . Multiplier . ✓ Pivoting ke bina hota — pivoting ne multiplier ko chhota kar diya, jo rounding errors ko bounded rakhta hai (dekho Condition Number and Numerical Stability).
Exercise 3.3
Sirf LU factors use karke explain karo ki times a sign kyun hota hai, aur Exercise 2.3 ki matrix ke liye compute karo.
Recall Solution
(wahan koi swap nahi hua), toh . Doolittle form mein hota hai (ones ka product). Isliye . Agar row swaps use hue hote, toh har swap sign ek baar flip karta, jo factor deta. Exercise 2.3 ke liye: , aur koi swap nahi, toh .
Level 4 — Synthesis
Exercise 4.1
Tumhe kisi ke factors diye gaye hain (koi swap nahi) aur do right-hand sides ke liye solve karne ko kaha gaya hai, bina re-factoring ke:
Recall Solution
Yahi toh LU ka poora point hai: ek baar factor karo, kai baar solve karo (dekho Gaussian Elimination).
RHS 1. Forward : ; ; . Back : ; ; .
RHS 2. Forward: ; ; . Back: ; ; . Notice karo ki humne dono ke liye reuse kiye — koi elimination dobara nahi ki.
Exercise 4.2
Ek matrix ko factorization ke dauran pivot kiya gaya: ek row swap hua, jo is tarah record kiya gaya:
L=\begin{pmatrix}1&0&0\\ \tfrac12&1&0\\0&\tfrac13&1\end{pmatrix},\quad U=\begin{pmatrix}4&2&0\\0&3&1\\0&0&2\end{pmatrix}.$$ (a) $\det A$ compute karo. (b) $\mathbf{b}=(3,\,8,\,6)^\top$ ke saath $A\mathbf{x}=\mathbf{b}$ solve karo, $\mathbf{b}$ ko permute karna mat bhoolo. > [!recall]- Solution > **(a)** Ek swap → sign $(-1)^1=-1$. $\prod u_{ii}=4\cdot3\cdot2=24$. Toh $\det A=-24$. > **(b)** Humein $L\mathbf{y}=P\mathbf{b}$ solve karna hai (ye classic bhoolne wala step hai!). $P$ pehle do entries swap karta hai: $P\mathbf{b}=(8,\,3,\,6)^\top$. > Forward $L\mathbf{y}=P\mathbf{b}$: $y_1=8$; $\tfrac12\cdot8+y_2=3\Rightarrow y_2=3-4=-1$; $\tfrac13(-1)+y_3=6\Rightarrow y_3=6+\tfrac13=\tfrac{19}{3}$. > Back $U\mathbf{x}=\mathbf{y}$: $2x_3=\tfrac{19}{3}\Rightarrow x_3=\tfrac{19}{6}$; $3x_2+x_3=-1\Rightarrow 3x_2=-1-\tfrac{19}{6}=-\tfrac{25}{6}\Rightarrow x_2=-\tfrac{25}{18}$; $4x_1+2x_2=8\Rightarrow 4x_1=8-2(-\tfrac{25}{18})=8+\tfrac{25}{9}=\tfrac{97}{9}\Rightarrow x_1=\tfrac{97}{36}$. > $$\mathbf{x}=\Big(\tfrac{97}{36},\,-\tfrac{25}{18},\,\tfrac{19}{6}\Big)^\top.$$ > [!mistake] L4 trap — $L\mathbf{y}=P\mathbf{b}$ ki jagah $L\mathbf{y}=\mathbf{b}$ solve karna > $PA=LU$ store hone ke baad, students $L,U$ uthate hain aur **original** $\mathbf{b}$ feed kar dete hain. *Ye sahi kyun lagta hai:* tum "$A\mathbf{x}=\mathbf{b}$" solve kar rahe ho, toh $\mathbf{b}$ untouched lagta hai. *Sachai:* tumne jo equation actually factor ki hai woh $PA\mathbf{x}=P\mathbf{b}$ hai, yaani $LU\mathbf{x}=P\mathbf{b}$ hai. Fix: **forward substitution se pehle $\mathbf{b}$ ko usi $P$ se permute karo.** (Dekho [[Permutation Matrices]].) --- ## Level 5 — Mastery ### Exercise 5.1 Ek symmetric positive-definite matrix $$A=\begin{pmatrix}4&2\\2&5\end{pmatrix}$$ ka dono Doolittle $A=LU$ bhi hai aur Cholesky $A=GG^\top$ bhi. **Dono** compute karo aur dikhao ki $U$ ki diagonal $G$ ki diagonal ke squares ke barabar hai. > [!recall]- Solution > **Doolittle:** $u_{11}=4,\ u_{12}=2$; $\ell_{21}=2/4=\tfrac12$; $u_{22}=5-\tfrac12\cdot2=4$. > $$L=\begin{pmatrix}1&0\\ \tfrac12&1\end{pmatrix},\ U=\begin{pmatrix}4&2\\0&4\end{pmatrix}.$$ > **Cholesky** (dekho [[Cholesky Decomposition]]): $g_{11}=\sqrt{4}=2$; $g_{21}=a_{21}/g_{11}=2/2=1$; $g_{22}=\sqrt{a_{22}-g_{21}^2}=\sqrt{5-1}=2$. > $$G=\begin{pmatrix}2&0\\1&2\end{pmatrix},\quad GG^\top=\begin{pmatrix}4&2\\2&5\end{pmatrix}=A.\ ✓$$ > **Link:** $u_{11}=4=g_{11}^2$ aur $u_{22}=4=g_{22}^2$. Waqai Cholesky ek aisa LU hai jahan $U=D G^\top$ hai aur $D=\mathrm{diag}(g_{ii})$ hai, toh $u_{ii}=g_{ii}^2$ hota hai. Isliye Cholesky ko pivots (yahan $4,4$) ka **positive** rehna zaroori hai. ### Exercise 5.2 Parent ke Worked Example 1 wala wahi $A=\begin{pmatrix}2&3\\6&13\end{pmatrix}$ lo ($L=\begin{pmatrix}1&0\\3&1\end{pmatrix},U=\begin{pmatrix}2&3\\0&4\end{pmatrix}$). LU use karke $A^{-1}$ compute karo, $A\mathbf{x}=\mathbf{e}_1$ aur $A\mathbf{x}=\mathbf{e}_2$ (identity ke columns) solve karke. LU se $\det A$ bhi confirm karo. > [!recall]- Solution > $A^{-1}$ ka har column $A\mathbf{x}=\mathbf{e}_j$ solve karta hai — **same** $L,U$ reuse karo. > **Column 1, $\mathbf{e}_1=(1,0)$:** forward $y_1=1$, $3\cdot1+y_2=0\Rightarrow y_2=-3$; back $4x_2=-3\Rightarrow x_2=-\tfrac34$, $2x_1+3x_2=1\Rightarrow 2x_1=1+\tfrac94=\tfrac{13}{4}\Rightarrow x_1=\tfrac{13}{8}$. > **Column 2, $\mathbf{e}_2=(0,1)$:** forward $y_1=0$, $y_2=1$; back $4x_2=1\Rightarrow x_2=\tfrac14$, $2x_1+3x_2=0\Rightarrow 2x_1=-\tfrac34\Rightarrow x_1=-\tfrac38$. > $$A^{-1}=\begin{pmatrix}\tfrac{13}{8}&-\tfrac38\\[2pt]-\tfrac34&\tfrac14\end{pmatrix}.$$ > Formula se check karo: $\det A=\prod u_{ii}=2\cdot4=8$, aur $\frac{1}{\det A}\begin{pmatrix}13&-3\\-6&2\end{pmatrix}=\frac18\begin{pmatrix}13&-3\\-6&2\end{pmatrix}$ match karta hai. ✓ > **Moral:** inversion ke liye bhi tum **ek baar** factor karte ho aur $n$ baar back-substitute karte ho — har column ke liye elimination dobara mat karo. ### Exercise 5.3 Dikhao ki matrix $$A=\begin{pmatrix}1&2\\2&4\end{pmatrix}$$ ka **koi** LU decomposition nahi hai, pivoting ke saath bhi nahi, aur batao aisa kyun hai. > [!recall]- Solution > Doolittle try karo: $u_{11}=1,\ u_{12}=2$; $\ell_{21}=2/1=2$; $u_{22}=4-2\cdot2=0$. **Doosra** pivot $0$ hai, toh $\det A=1\cdot0=0$ — $A$ singular hai (row 2 $=2\times$ row 1). Pivoting se koi fark nahi padta: pehle column mein sabse bada entry $2$ hai (row 2), swap karo toh $\begin{pmatrix}2&4\\1&2\end{pmatrix}$ milti hai, phir $\ell_{21}=\tfrac12$, $u_{22}=2-\tfrac12\cdot4=0$ phir se milta hai. Zero pivot **structural** hai (rank deficiency), ordering accident nahi. Contrast karo Exercise 3.1 se, jahan swapping ne problem fix kar di kyunki woh $A$ non-singular tha. > [!mistake] L5 trap — non-positive-definite matrix par Cholesky trust karna > Kisi bhi symmetric matrix par Cholesky apply karna aur real $g_{ii}$ expect karna. *Ye sahi kyun lagta hai:* formula $g_{ii}=\sqrt{a_{ii}-\sum g_{ik}^2}$ *dikhai* universal lagta hai. *Sachai:* agar $A$ positive-definite nahi hai toh root ke andar ki quantity $\le0$ ho jaati hai aur $g_{ii}$ imaginary ya zero ho jaata hai — algorithm **purpose se fail** hota hai, jo actually ek sasta positive-definiteness test hai. Fix: general matrices ke liye [[Partial Pivoting]] ke saath plain LU use karo; Cholesky sirf symmetric positive-definite matrices ke liye reserve rakho. --- > [!recall] Wrap-up self-check (answers dhako) > - Q: $PA=LU$ mein, forward substitution ko tum kaun sa vector dete ho? ::: $P\mathbf{b}$, $\mathbf{b}$ nahi. > - Q: Ek row swap $\det A$ ka sign kyun flip karta hai? ::: Ek swap ek aisi permutation se multiplication hai jiska determinant $-1$ hota hai. > - Q: Cholesky ki diagonal LU ke pivots se kaise relate karti hai ek SPD matrix mein? ::: $u_{ii}=g_{ii}^2$. > - Q: Ek zero pivot aata hai — kya $A$ hamesha singular hoti hai? ::: Nahi; pehle pivoting try karo. Sirf structural (rank) zeros fatal hote hain. ### Connections - [[LU decomposition (numerical)]] — wo parent note jise ye page drill karta hai. - [[Gaussian Elimination]], [[Forward and Back Substitution]] — har solve ke peeche ke engines. - [[Partial Pivoting]], [[Permutation Matrices]] — zero/small pivots ka repair. - [[Determinants]], [[Cholesky Decomposition]], [[Crout Decomposition]], [[Condition Number and Numerical Stability]] — woh neighbouring ideas jinhe mastery problems touch karti hain.