4.8.18Numerical Methods

Solving linear systems — Gaussian elimination with partial pivoting

1,661 words8 min readdifficulty · medium5 backlinks

1. What problem are we solving?


2. Forward elimination — derived from scratch

We want zeros below the diagonal of column kk. Look at column kk, rows k+1,,nk+1,\dots,n.

HOW to zero entry aika_{ik} (for i>ki>k) without changing the solution? Subtract a multiple of the pivot row kk from row ii: RowiRowimikRowk.\text{Row}_i \leftarrow \text{Row}_i - m_{ik}\,\text{Row}_k.

We need the new (i,k)(i,k) entry to be 00: aikmikakk=0    mik=aikakk.a_{ik} - m_{ik}\,a_{kk} = 0 \;\Longrightarrow\; \boxed{m_{ik} = \dfrac{a_{ik}}{a_{kk}}}.

WHY partial pivoting? The multiplier has akka_{kk} in the denominator. If akka_{kk} is tiny, mikm_{ik} is huge, and huge multipliers amplify the floating-point error in every other entry.


3. Back-substitution — derived

After forward elimination we have an upper-triangular system Ux=cU\mathbf{x}=\mathbf{c}:

unnxn=cn,un1,n1xn1+un1,nxn=cn1, \begin{aligned} u_{nn}x_n &= c_n,\\ u_{n-1,n-1}x_{n-1}+u_{n-1,n}x_n &= c_{n-1},\ \dots \end{aligned}

The last equation has one unknown — solve it. Substitute upward.

Figure — Solving linear systems — Gaussian elimination with partial pivoting

4. Worked example (full)

Solve {0.0003x1+3.0000x2=2.00011.0000x1+1.0000x2=1.0000\begin{cases} 0.0003x_1 + 3.0000x_2 = 2.0001\\ 1.0000x_1 + 1.0000x_2 = 1.0000\end{cases} Exact answer: x1=13, x2=23x_1=\tfrac{1}{3},\ x_2=\tfrac{2}{3} (≈ 0.33333, 0.666670.33333,\ 0.66667).

Step 1 — Partial pivoting. Column 1 entries: 0.0003|0.0003| vs 1.0000|1.0000|. Why this step? 1.00001.0000 is larger → swap rows so we never divide by the tiny 0.00030.0003. [1110.000332.0001].\begin{bmatrix}1 & 1 & | & 1\\ 0.0003 & 3 & | & 2.0001\end{bmatrix}.

Step 2 — Eliminate. m21=0.0003/1=0.0003m_{21}=0.0003/1=0.0003. Why: this is the multiplier that zeros a21a_{21}. Row2_2\leftarrowRow20.0003_2-0.0003\cdotRow1_1: a22=30.0003(1)=2.9997,b2=2.00010.0003(1)=1.9998.a_{22}=3-0.0003(1)=2.9997,\quad b_2=2.0001-0.0003(1)=1.9998. [11102.99971.9998].\begin{bmatrix}1 & 1 & | & 1\\ 0 & 2.9997 & | & 1.9998\end{bmatrix}.

Step 3 — Back-substitute. x2=1.99982.9997=0.66667,x1=1x21=0.33333. x_2=\frac{1.9998}{2.9997}=0.66667,\qquad x_1=\frac{1-x_2}{1}=0.33333.\ \checkmark


5. Common mistakes


6. Cost & when it fails


Recall Feynman: explain to a 12-year-old

Imagine a staircase of equations. You want to knock out the first variable from every equation except the top one — like erasing xx from all but the first row. To erase it cleanly you subtract the right multiple of the top equation from the others. But if the top equation has a teeny number in front of xx, dividing by it makes monster numbers and your calculator gets confused. So first you pick the equation with the BIGGEST xx-coefficient and move it to the top — that's pivoting. Repeat for the next variable, and so on, until the last equation has only one unknown. Solve it, then climb back up the staircase plugging in answers.


Flashcards

What is the goal of forward elimination in Gaussian elimination?
Transform AA into an upper-triangular matrix UU (zeros below the diagonal) using row operations.
Why do we use partial pivoting?
To avoid dividing by tiny/zero pivots; it keeps all multipliers mik1|m_{ik}|\le 1, controlling round-off error (numerical stability).
What is the partial-pivoting rule for column kk?
Among rows knk\dots n, find the entry of largest absolute value in column kk and swap that row into position kk.
Formula for the multiplier mikm_{ik}?
mik=aik/akkm_{ik}=a_{ik}/a_{kk} — chosen so aikmikakk=0a_{ik}-m_{ik}a_{kk}=0.
The row update during elimination?
aijaijmikakja_{ij}\leftarrow a_{ij}-m_{ik}a_{kj} and bibimikbkb_i\leftarrow b_i-m_{ik}b_k (apply to whole augmented row).
Back-substitution formula?
xi=1uii(cij>iuijxj)x_i=\frac{1}{u_{ii}}\big(c_i-\sum_{j>i}u_{ij}x_j\big), computed from i=ni=n down to 11.
Why bottom-up for back-substitution?
The last equation has only one unknown; each earlier xix_i needs the already-known xjx_j (j>ij>i).
Approximate flop count of Gaussian elimination?
23n3\sim \tfrac{2}{3}n^3 (forward elimination dominates; back-sub is O(n2)O(n^2)).
What does an unavoidable zero pivot indicate?
The matrix is singular — no unique solution.
Difference between partial and complete pivoting?
Partial: search only the current column (rows k..nk..n). Complete: search the whole remaining submatrix (more stable, costlier).

Connections

  • LU Decomposition — Gaussian elimination is an LU factorization; pivoting gives PA=LUPA=LU.
  • Back-substitution and Forward-substitution
  • Condition Number and Numerical Stability
  • Round-off Error in Floating Point
  • Determinants — product of pivots (×(1)#swaps\times(-1)^{\text{\#swaps}}) gives detA\det A.
  • Cramer's Rule — exact but O(n!)O(n!), impractical contrast.
  • Iterative Methods (Jacobi, Gauss-Seidel) — alternative for large sparse systems.

Concept Map

represented as

apply

preserve

used in

zeros below diagonal via

divides by

tiny pivot causes

fixed by

swaps row with

guarantees

produces

solved by

yields

Ax = b system

Augmented matrix A | b

Elementary row operations

Solution set unchanged

Forward elimination

Multiplier m = a_ik / a_kk

Pivot a_kk

Huge multipliers, rounding error

Partial pivoting

Largest magnitude entry

|m| <= 1, stability

Upper-triangular Ux = c

Back-substitution

Solution x

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Dekho, hume solve karna hai Ax=bA\mathbf{x}=\mathbf{b} — yaani nn equations, nn unknowns. Idea simple hai: row operations use karke matrix ko upper-triangular banao (diagonal ke neeche sab zero). Phir sabse neeche wali equation me sirf ek unknown bachta hai — usko solve karo, aur upar ki taraf chadhte hue baaki values plug karte jao. Isko back-substitution kehte hain.

Ab partial pivoting ka funda: jab hum kisi column ko zero karne ke liye multiplier mik=aik/akkm_{ik}=a_{ik}/a_{kk} banate hain, to denominator me pivot akka_{kk} aata hai. Agar pivot bahut chhota (ya zero) hua, to multiplier huge ban jaata hai aur calculator ka rounding error explode ho jaata hai. Isliye har step se pehle hum us column me (rows kk se nn tak) sabse bada absolute value wala entry dhoondhte hain aur uski row ko upar swap kar dete hain. Isse har multiplier mik1|m_{ik}|\le 1 rehta hai — numerically stable.

Upar wale chhote example (0.0003 wala) me dekha — bina pivoting ke answer galat aata, pivoting laga ke ekdum sahi 1/3,2/31/3, 2/3 mila. Yahi reason hai ki real software (MATLAB, numpy) hamesha pivoting use karte hain. Cost ki baat karein to forward elimination 23n3\sim \tfrac{2}{3}n^3 operations leta hai — yani nn double karo to kaam 8 guna. Pivoting bas thode comparisons add karta hai, almost free insurance. Yaad rakho: Biggest pick karo, Swap, Subtract, phir Climb back up.

Go deeper — visual, from zero

Test yourself — Numerical Methods

Connections