4.8.19Numerical Methods

LU decomposition (numerical)

1,641 words7 min readdifficulty · medium

WHAT is LU decomposition?

WHY two triangular matrices? Because triangular systems are trivial to solve:

  • Ly=bL\mathbf{y}=\mathbf{b} → solve top-to-bottom (forward substitution).
  • Ux=yU\mathbf{x}=\mathbf{y} → solve bottom-to-top (back substitution).

So Ax=bA\mathbf{x}=\mathbf{b} becomes LUx=bLU\mathbf{x}=\mathbf{b}, set Ux=yU\mathbf{x}=\mathbf{y}, solve the two easy pieces.


HOW do we derive it? (Doolittle, from scratch)

Take a general 3×33\times3 to see the machinery. Write LL with unit diagonal and UU general:

A=(a11a12a13a21a22a23a31a32a33)=(100211031321)L(u11u12u130u22u2300u33)UA=\begin{pmatrix}a_{11}&a_{12}&a_{13}\\a_{21}&a_{22}&a_{23}\\a_{31}&a_{32}&a_{33}\end{pmatrix} =\underbrace{\begin{pmatrix}1&0&0\\ \ell_{21}&1&0\\ \ell_{31}&\ell_{32}&1\end{pmatrix}}_{L} \underbrace{\begin{pmatrix}u_{11}&u_{12}&u_{13}\\0&u_{22}&u_{23}\\0&0&u_{33}\end{pmatrix}}_{U}

Multiply LULU and match entries with AA. The trick: go row by row of UU, then column by column of LL, because each new equation introduces exactly one new unknown.

Row 1 of UU (first row of LL is (1,0,0)(1,0,0)): u11=a11,u12=a12,u13=a13.u_{11}=a_{11},\quad u_{12}=a_{12},\quad u_{13}=a_{13}.

Column 1 of LL (the second/third entries come from row·col): a21=21u1121=a21/u11a_{21}=\ell_{21}u_{11}\Rightarrow \ell_{21}=a_{21}/u_{11}, and 31=a31/u11\ell_{31}=a_{31}/u_{11}.

Row 2 of UU: a22=21u12+u22u22=a2221u12a_{22}=\ell_{21}u_{12}+u_{22}\Rightarrow u_{22}=a_{22}-\ell_{21}u_{12}, a23=21u13+u23u23=a2321u13a_{23}=\ell_{21}u_{13}+u_{23}\Rightarrow u_{23}=a_{23}-\ell_{21}u_{13}.

Column 2 of LL: a32=31u12+32u2232=a3231u12u22a_{32}=\ell_{31}u_{12}+\ell_{32}u_{22}\Rightarrow \ell_{32}=\dfrac{a_{32}-\ell_{31}u_{12}}{u_{22}}.

Row 3 of UU: a33=31u13+32u23+u33u33=a3331u1332u23a_{33}=\ell_{31}u_{13}+\ell_{32}u_{23}+u_{33}\Rightarrow u_{33}=a_{33}-\ell_{31}u_{13}-\ell_{32}u_{23}.

Generalizing the pattern gives the Doolittle formulas:


WHY is this just Gaussian elimination in disguise?

Each elimination step "rowi_i \leftarrow rowimik_i - m_{ik}\cdotrowk_k" is multiplication by an elementary matrix EikE_{ik}. After full elimination U=EnE1AU = E_{n}\cdots E_1 A, so A=(EnE1)1U=LUA=(E_n\cdots E_1)^{-1}U = LU. The multipliers mikm_{ik} that we discarded in plain elimination are precisely the entries ik\ell_{ik} that LU keeps.

Figure — LU decomposition (numerical)

Worked Example 1 — factor and solve

Solve Ax=bA\mathbf{x}=\mathbf{b} with A=(23613),b=(535).A=\begin{pmatrix}2&3\\6&13\end{pmatrix},\quad \mathbf{b}=\begin{pmatrix}5\\35\end{pmatrix}.

Step 1: u11=2, u12=3u_{11}=2,\ u_{12}=3. Why? Row 1 of LL is (1,0)(1,0), so top row of UU = top row of AA.

Step 2: 21=a21/u11=6/2=3\ell_{21}=a_{21}/u_{11}=6/2=3. Why? Multiplier to kill the (2,1)(2,1) entry.

Step 3: u22=a2221u12=1333=4u_{22}=a_{22}-\ell_{21}u_{12}=13-3\cdot3=4. Why? Subtract what column-1 elimination contributed.

So L=(1031),U=(2304).L=\begin{pmatrix}1&0\\3&1\end{pmatrix},\quad U=\begin{pmatrix}2&3\\0&4\end{pmatrix}. Check: LU=(23613)=A.LU=\begin{pmatrix}2&3\\6&13\end{pmatrix}=A.

Forward solve Ly=bL\mathbf{y}=\mathbf{b}: y1=5y_1=5; 3y1+y2=35y2=3515=203y_1+y_2=35\Rightarrow y_2=35-15=20. Why top-first? LL is lower triangular, first eq has one unknown.

Back solve Ux=yU\mathbf{x}=\mathbf{y}: 4x2=20x2=54x_2=20\Rightarrow x_2=5; 2x1+3x2=52x1=515=10x1=52x_1+3x_2=5\Rightarrow 2x_1=5-15=-10\Rightarrow x_1=-5. Why bottom-first? UU is upper triangular.

x=(5, 5)\boxed{\mathbf{x}=(-5,\ 5)^\top}


Worked Example 2 — why pivoting is needed

Try to factor A=(0111).A=\begin{pmatrix}0&1\\1&1\end{pmatrix}. u11=a11=0u_{11}=a_{11}=0, then 21=a21/u11=1/0\ell_{21}=a_{21}/u_{11}=1/0blows up! Why? The pivot is zero even though AA is invertible.

Fix: partial pivoting. Swap rows so the largest-magnitude entry sits on the pivot. We record swaps in a permutation matrix PP and factor PA=LUPA=LU. Here swap the two rows: PA=(1101)=(1001)(1101).PA=\begin{pmatrix}1&1\\0&1\end{pmatrix}=\begin{pmatrix}1&0\\0&1\end{pmatrix}\begin{pmatrix}1&1\\0&1\end{pmatrix}. To solve Ax=bA\mathbf{x}=\mathbf{b} you solve LUx=PbLU\mathbf{x}=P\mathbf{b} (permute b\mathbf{b} the same way).


A handy bonus: the determinant

Since detL=1\det L=1 (unit diagonal) and detU=uii\det U=\prod u_{ii}, detA=det(LU)=i=1nuii×(1)#row swaps.\det A=\det(LU)=\prod_{i=1}^{n}u_{ii}\times(-1)^{\#\text{row swaps}}. Why? Determinant of a triangular matrix is the product of its diagonal; permutations flip sign once per swap.


Recall Feynman: explain to a 12-year-old

Imagine solving a maze takes lots of careful steps. Instead of solving the same maze again every time someone gives you a new "exit", you write down a cheat sheet of moves the first time. LL and UU are that cheat sheet. Once you have them, getting from start to any exit is super fast: walk down (LL, forward), then walk back up (UU, back). If a turn is "blocked" (a zero pivot), you just swap the order of paths (pivoting) and keep going.


Flashcards

What does LU decomposition factor AA into?
A lower-triangular LL times an upper-triangular UU, A=LUA=LU.
In Doolittle convention, which matrix has 1's on its diagonal?
LL (the lower-triangular factor).
After computing L,UL,U, how do you solve Ax=bA\mathbf{x}=\mathbf{b}?
Forward-solve Ly=bL\mathbf{y}=\mathbf{b}, then back-solve Ux=yU\mathbf{x}=\mathbf{y}.
What are the entries ij\ell_{ij} equal to?
The Gaussian-elimination multipliers used to zero entry (i,j)(i,j).
Doolittle formula for uiju_{ij} (jij\ge i)?
uij=aijk=1i1ikukju_{ij}=a_{ij}-\sum_{k=1}^{i-1}\ell_{ik}u_{kj}.
Doolittle formula for ij\ell_{ij} (i>ji>j)?
ij=1ujj(aijk=1j1ikukj)\ell_{ij}=\frac{1}{u_{jj}}\big(a_{ij}-\sum_{k=1}^{j-1}\ell_{ik}u_{kj}\big).
Why use LU rather than re-running elimination?
Factor once, then each new right-hand side costs only two cheap triangular solves.
What goes wrong if a pivot ujj=0u_{jj}=0?
Division by zero / instability; fix with partial pivoting (PA=LUPA=LU).
What does partial pivoting guarantee about multipliers?
ij1|\ell_{ij}|\le 1, keeping rounding errors bounded.
How to get detA\det A from LU?
detA=(1)#swapsiuii\det A=(-1)^{\#\text{swaps}}\prod_i u_{ii}.
Why is detL=1\det L=1 in Doolittle form?
Triangular determinant = product of diagonal, and LL's diagonal is all 1's.

Connections

  • Gaussian Elimination — LU stores its multipliers.
  • Forward and Back Substitution — the two solve phases.
  • Partial Pivoting / Permutation Matrices — stability and PA=LUPA=LU.
  • Cholesky Decomposition — special LU for symmetric positive-definite AA (A=LLA=LL^\top).
  • Crout Decomposition — sister convention (1's in UU).
  • Determinants — computed cheaply from UU.
  • Condition Number and Numerical Stability — why pivoting matters.

Concept Map

motivates

L is

U is

Doolittle convention

Doolittle convention

derived by

row and column order

u_jj is

l_ij is

then solve

then

yields

equivalent to

equivalent to

Solve Ax=b repeatedly

LU decomposition A=LU

Lower triangular unit diagonal

Upper triangular

Doolittle form

Match LU entries with A

Doolittle formulas

Pivot from elimination

Elimination multiplier

Ly=b forward substitution

Ux=y back substitution

Solution x

Gaussian elimination

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Dekho, LU decomposition ka basic funda yeh hai: Ax=bA\mathbf{x}=\mathbf{b} solve karna Gaussian elimination se hota hai, lekin agar aapko same AA ke saath alag-alag b\mathbf{b} ke liye baar-baar solve karna ho, toh har baar poori elimination dohrana bekaar mehnat hai. Isliye hum AA ko ek baar do triangular matrices mein tod dete hain: A=LUA=LU, jahan LL lower triangular hai (1's diagonal pe, Doolittle convention) aur UU upper triangular. Phir koi bhi naya solve sirf do aasaan steps: pehle Ly=bL\mathbf{y}=\mathbf{b} forward substitution se, phir Ux=yU\mathbf{x}=\mathbf{y} back substitution se. "Factor once, solve many times" — yahi pura game hai.

Yeh LL aur UU aate kahan se hain? Bilkul Gaussian elimination ke multipliers se! Jo number aap row ko zero karne ke liye use karte ho (jaise 21=a21/u11\ell_{21}=a_{21}/u_{11}), wahi LL mein store ho jaata hai. Plain elimination mein hum yeh multipliers phenk dete the; LU mein hum sambhaal lete hain. Diagonal pe jo pivots bachte hain woh UU ke uiiu_{ii} ban jaate hain.

Ek important practical baat: agar pivot ujj=0u_{jj}=0 ho gaya toh divide-by-zero ho jayega, formula phat jaayega — jaise example mein (0111)\begin{pmatrix}0&1\\1&1\end{pmatrix}. Iska solution hai partial pivoting: rows ko swap karke sabse bada element pivot position pe le aao, aur swap ko ek permutation matrix PP mein note karlo, toh PA=LUPA=LU. Yeh sirf zero-pivot bachata nahi, accuracy bhi improve karta hai kyunki chhote pivot se divide karne par rounding errors badh jaate hain.

Bonus tip exam ke liye: determinant nikalna ho toh detA=uii\det A = \prod u_{ii} (agar swaps hue ho toh (1)(-1) har swap pe). Aur yaad rakhna — A1A^{-1} nikal kar solve karna slow aur unstable hai, LU-solve hi smart aur professional tarika hai.

Go deeper — visual, from zero

Test yourself — Numerical Methods

Connections