1.1.12Linear Algebra Essentials

Solving linear systems (Gaussian elimination)

1,853 words8 min readdifficulty · medium1 backlinks

WHAT is a linear system?

The three elementary row operations (each is reversible, so they never change the solution set):

  1. Swap two rows. (RiRjR_i \leftrightarrow R_j)
  2. Scale a row by a nonzero constant. (RicRiR_i \to cR_i)
  3. Add a multiple of one row to another. (RiRi+cRjR_i \to R_i + cR_j)

HOW: the algorithm (Derivation from scratch)

Gaussian elimination has two phases.

Phase 1 — Forward elimination → row echelon form (REF). Goal: make everything below each leading entry (pivot) zero, working left to right.

  • Pick the pivot in column jj (a nonzero entry).
  • For every row ii below it, subtract aijajj\dfrac{a_{ij}}{a_{jj}} times the pivot row. This forces aij0a_{ij}\to 0.

Phase 2 — Back substitution. The last equation now has one unknown → solve it. Substitute upward into the previous equation, and repeat.

(Optionally continue elimination upward and scale pivots to 1 → reduced row echelon form (RREF), the identity-like form where you can read solutions off directly. This is Gauss–Jordan.)

Figure — Solving linear systems (Gaussian elimination)

Worked Example 1 — a clean 3×33\times3

Solve x+y+z=62x+3y+7z=30xy+2z=5\begin{aligned} x + y + z &= 6\\ 2x + 3y + 7z &= 30\\ x - y + 2z &= 5 \end{aligned}

Augmented: [1116237301125]\left[\begin{array}{ccc|c}1&1&1&6\\2&3&7&30\\1&-1&2&5\end{array}\right]

Step 1: R2R22R1R_2 \to R_2 - 2R_1. Why? Multiplier =2/1=2=-2/1=-2 kills the 22 under the pivot 11. [0,1,518]\to [0,\,1,\,5\mid 18]

Step 2: R3R31R1R_3 \to R_3 - 1R_1. Why? Kills the 11 in column 1 of row 3. [0,2,11]\to [0,\,-2,\,1\mid -1]

Now: [1116015180211]\left[\begin{array}{ccc|c}1&1&1&6\\0&1&5&18\\0&-2&1&-1\end{array}\right]

Step 3: R3R3+2R2R_3 \to R_3 + 2R_2. Why? Pivot in column 2 is now 11; multiplier =(2)/1=+2=-(-2)/1=+2 clears the 2-2. [0,0,1135]\to [0,\,0,\,11\mid 35]

REF: [111601518001135]\left[\begin{array}{ccc|c}1&1&1&6\\0&1&5&18\\0&0&11&35\end{array}\right]

Back-substitute. Why bottom-up? The last row has only zz.

  • 11z=35z=35/1111z = 35 \Rightarrow z = 35/11.
  • y+5z=18y=18175/11=23/11y + 5z = 18 \Rightarrow y = 18 - 175/11 = 23/11.
  • x+y+z=6x=623/1135/11=8/11x + y + z = 6 \Rightarrow x = 6 - 23/11 - 35/11 = 8/11.

Solution: (811,2311,3511)\left(\tfrac{8}{11}, \tfrac{23}{11}, \tfrac{35}{11}\right). (Verified in §VERIFY.)


Worked Example 2 — infinitely many solutions

x+2y+z=42x+4y+3z=9\begin{aligned} x + 2y + z &= 4\\ 2x + 4y + 3z &= 9 \end{aligned}

[12142439]\left[\begin{array}{ccc|c}1&2&1&4\\2&4&3&9\end{array}\right]

Step 1: R2R22R1[0,0,11]R_2 \to R_2 - 2R_1 \Rightarrow [0,0,1\mid 1]. Why? Clears the 22.

REF: [12140011]\left[\begin{array}{ccc|c}1&2&1&4\\0&0&1&1\end{array}\right]

Column 2 has no pivotyy is a free variable. Set y=ty=t.

  • Row 2: z=1z=1.
  • Row 1: x=42tz=32tx = 4 - 2t - z = 3 - 2t.

Solution: (x,y,z)=(32t, t, 1)(x,y,z) = (3-2t,\ t,\ 1), one solution per tt. WHY infinite? Fewer pivots than unknowns → a direction of freedom.


Worked Example 3 — no solution

x+y=2x+y=5\begin{aligned} x + y &= 2\\ x + y &= 5 \end{aligned}

R2R2R1[0,03]R_2 \to R_2 - R_1 \Rightarrow [0,0\mid 3], i.e. 0=30 = 3. Contradiction → the system is inconsistent. Two parallel lines never meet.


Common Mistakes (Steel-manned)


Recall Feynman: explain to a 12-year-old

Imagine 3 friends who each know one clue about a secret number trio. Alone the clues are messy. So you combine clues — "take twice my clue away from yours" — to knock out one unknown at a time. Keep doing this until one clue mentions only one number: solve it. Then walk backwards plugging it in. Gaussian elimination is exactly this "cancel one, then work backwards" trick, done neatly in a grid.


Cost & ML relevance


Flashcards

What are the three elementary row operations?
Swap two rows; scale a row by a nonzero constant; add a multiple of one row to another.
Why do elementary row operations not change the solution set?
Each corresponds to a reversible legal algebra move on the equations, so no solutions are added or lost.
What is the multiplier used to zero entry a_ij using pivot a_jj?
c = -a_ij / a_jj, applied as R_i -> R_i + c·R_j.
In REF, what does a pivot in every column of A mean?
The system has a unique solution.
In REF, what does a free column (no pivot, no contradiction) mean?
Infinitely many solutions (that variable is free).
A reduced row reads [0 0 ... 0 | c] with c ≠ 0. What does it mean?
The system is inconsistent — no solution.
What is partial pivoting and why use it?
Swap in the row with the largest-magnitude entry in the pivot column; avoids dividing by zero/tiny pivots and controls numerical error.
Difference between REF and RREF?
REF is upper-triangular with zeros below pivots; RREF additionally has pivots equal to 1 and zeros above them (identity-like).
What is the approximate op count of Gaussian elimination on an n×n system?
About (2/3)n^3 floating-point operations.
Why do back-substitution from the bottom row?
The bottom row of REF has only one unknown, so you can solve it directly and substitute upward.

Connections

Concept Map

written as

acted on by

swap scale add

so

Phase 1 forward

uses multiplier c = -a_ij/a_jj

Phase 2

yields

continue upward

read off directly

powers

Linear system Ax=b

Augmented matrix A given b

Elementary row operations

Reversible moves

Solution set preserved

Row echelon form

Pivot cancels entries below

Back substitution

Solution x

Reduced REF Gauss-Jordan

ML solves least-squares normal equations

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Dekho, linear system Ax=bA\mathbf{x}=\mathbf{b} ka matlab hai kuch equations jo saath-saath satisfy hone chahiye. Gaussian elimination sirf ek smart tareeka hai variables ko ek-ek karke hataane ka. Hum ek equation ka scaled version doosre me add/subtract karte hain taaki ek variable ka coefficient zero ho jaaye. Isko "forward elimination" kehte hain, aur jab matrix triangular (upper) ban jaata hai, tab neeche wali equation me sirf ek variable bachta hai — usse solve karo, phir upar ki taraf substitute karte jao. Yeh "back substitution" hai.

Ek zaroori cheez: hamesha augmented matrix [Ab][A\mid b] pe kaam karo, kyunki row operation asal me poori equation pe ho raha hai — RHS ko bhi change karna padega, warna answer galat aayega. Multiplier hamesha aij/ajj-a_{ij}/a_{jj} hota hai — yeh ratayad karne ki cheez nahi, yeh bas wahi number hai jo target entry ko cancel karta hai.

Answer teen tarah ka ho sakta hai: agar har column me pivot hai to unique solution; agar koi column bina pivot ke hai (free variable) to infinite solutions; aur agar koi row 0=c0 = c (c non-zero) de de to solution hi nahi (contradiction). Yaad rakho 0=00=0 galat nahi hota — woh sirf redundant equation hai.

ML me yeh cheez har jagah chhupi hoti hai — least squares regression, covariance matrix invert karna, Newton step — sab ke andar ek linear solve chal raha hota hai. Aur bade systems me tiny pivot se numerical error bhadak jaata hai, isliye "partial pivoting" (sabse bada element ko pivot banao) use karte hain. Mantra: Pick, Peel, Pop, Push.

Test yourself — Linear Algebra Essentials

Connections