j-devlog
KO
~/nav

// categories

// tags

[MMD]

Linear Algebra Basics Chapter 2: Elimination, Row Echelon Form, and Gaussian Elimination

·12 min read·

In Chapter 1 we covered the concept of linear equation systems, matrix singularity, and determinants. This post focuses on actually solving those systems — starting from elimination, moving through row echelon forms, Gaussian elimination, and Rank.

This post is based on Week 1 of DeepLearning.AI's Mathematics for Machine Learning and Data Science.

What You'll Learn#

  • Solving linear systems with Elimination
  • Using Matrix Row Reduction to express the same process in matrix form
  • Computing Row Echelon Form (REF) and Reduced Row Echelon Form (RREF)
  • Finding Rank and using it to determine how many solutions a system has

Solving a Non-Singular System — Elimination#

Elimination works by combining equations to cancel out variables one at a time.

Example:


{a+b=11ab=5\begin{cases} a + b = 11 \\ a - b = -5 \end{cases}


If both equations are true, then any sum or difference of them is also true.

Step 1 — Add the two equations:


(a+b)+(ab)=11+(5)(a + b) + (a - b) = 11 + (-5)


2a=6a=32a = 6 \quad \Rightarrow \quad a = 3


Step 2 — Substitute a=3a = 3:


3+b=11b=83 + b = 11 \quad \Rightarrow \quad b = 8


Verify: 3+8=113 + 8 = 11 ✓, 38=53 - 8 = -5

Core principle: If an equation is true, then any linear combination of it — sums, differences, or scalar multiples — is also true. This is the mathematical foundation of elimination.


Solving Singular Systems#

1 Degree of Freedom — Infinitely Many Solutions#

{a+b=52a+2b=10\begin{cases} a + b = 5 \\ 2a + 2b = 10 \end{cases}


Subtracting twice equation 1 from equation 2:


(2a+2b)2(a+b)=1010(2a + 2b) - 2(a + b) = 10 - 10


0=00 = 0


This is an identity — always true. Both equations carry the same information, so aa can be any value and b=5ab = 5 - a follows along.

This is called 1 degree of freedom — there is one variable we can freely choose.

No Solution — Inconsistent System#

{a+b=52a+2b=12\begin{cases} a + b = 5 \\ 2a + 2b = 12 \end{cases}


Subtracting twice equation 1 from equation 2:


0=20 = 2


This is a contradiction. The system has no solution.


Systems with More Variables#

The same principle applies to three-variable systems.


{x+y+z=62x+y+z=8x+2y+z=9\begin{cases} x + y + z = 6 \\ 2x + y + z = 8 \\ x + 2y + z = 9 \end{cases}


Step 1 — Eliminate xx from rows 2 and 3 using row 1:

  • R2R22R1R_2 \leftarrow R_2 - 2R_1: yz=4\quad -y - z = -4
  • R3R3R1R_3 \leftarrow R_3 - R_1: y+0z=3\quad y + 0z = 3

Step 2 — Substitute y=3y = 3:

3z=4z=1-3 - z = -4 \Rightarrow z = 1

Step 3 — Back substitution:

x+3+1=6x=2x + 3 + 1 = 6 \Rightarrow x = 2

Solution: x=2, y=3, z=1x = 2,\ y = 3,\ z = 1


Matrix Row Reduction#

The same process can be expressed using matrices instead of equations.


{a+b=112ab=2[1121]\begin{cases} a + b = 11 \\ 2a - b = 2 \end{cases} \quad \Rightarrow \quad \begin{bmatrix} 1 & 1 \\ 2 & -1 \end{bmatrix}


Apply row operation (R2R22R1R_2 \leftarrow R_2 - 2R_1):


[1103]\begin{bmatrix} 1 & 1 \\ 0 & -3 \end{bmatrix}


This form is Row Echelon Form (REF). From here, 3b=24b=8-3b = -24 \Rightarrow b = 8, then a=3a = 3.

Reduced Row Echelon Form (RREF) goes one step further — each variable is fully isolated:


[1001]a=3, b=8\begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix} \quad \Rightarrow \quad a = 3,\ b = 8

Row Echelon Form of a Singular System#

For a singular system, elimination produces an all-zero row.


[1122]R22R1[1100]\begin{bmatrix} 1 & 1 \\ 2 & 2 \end{bmatrix} \xrightarrow{R_2 - 2R_1} \begin{bmatrix} 1 & 1 \\ 0 & 0 \end{bmatrix}


The second row is entirely zero, indicating infinitely many solutions (1 degree of freedom).


The 3 Rules of Row Echelon Form#

A matrix is in Row Echelon Form (REF) if:

  1. Each pivot (diagonal element) is 0 or 1
  2. Everything below the diagonal is 0
  3. Everything above the diagonal:
    • Can be any value if the pivot is 1
    • Must be 0 if the pivot is 0
REFRREF
Below diagonal00
Above diagonalfree0
Diagonal (pivot)0 or 10 or 1

Row Operations That Preserve Singularity#

The operations applied to equations can be applied equally to matrix rows. Crucially, these operations do not change the singularity of the matrix.

OperationExamplePreserves singularity?
Swap two rowsR1R2R_1 \leftrightarrow R_2✅ Yes
Add one row to anotherR2R2+R1R_2 \leftarrow R_2 + R_1✅ Yes
Multiply a row by a scalarR13R1R_1 \leftarrow 3R_1✅ Yes
Add a constant to all elements of a rowR1R1+5R_1 \leftarrow R_1 + 5❌ No

Note: Adding a fixed constant to every element of a row is not a valid row operation — it can change the singularity of the matrix.


Matrix Rank#

Rank represents the amount of independent information a matrix contains.

  • After converting to REF, the number of non-zero rows equals the rank
  • Equivalently: the maximum number of linearly independent rows

[1234]REF[1202]rank=2(non-singular)\begin{bmatrix} 1 & 2 \\ 3 & 4 \end{bmatrix} \xrightarrow{\text{REF}} \begin{bmatrix} 1 & 2 \\ 0 & -2 \end{bmatrix} \quad \Rightarrow \quad \text{rank} = 2 \quad \text{(non-singular)}


[1224]REF[1200]rank=1(singular)\begin{bmatrix} 1 & 2 \\ 2 & 4 \end{bmatrix} \xrightarrow{\text{REF}} \begin{bmatrix} 1 & 2 \\ 0 & 0 \end{bmatrix} \quad \Rightarrow \quad \text{rank} = 1 \quad \text{(singular)}

Rank and the Number of Solutions#

For an n×nn \times n matrix (nn variables, nn equations):

RankNumber of solutionsSystem type
rank=n\text{rank} = nExactly 1Non-singular
rank<n\text{rank} < n0 or infinitely manySingular

Gaussian Elimination#

Gaussian elimination is a systematic algorithm that applies row operations to an augmented matrix — the coefficient matrix combined with the constants column — to solve a system.

Step-by-Step Example#

{x+2y+z=72x+y+z=8x+y+2z=8\begin{cases} x + 2y + z = 7 \\ 2x + y + z = 8 \\ x + y + 2z = 8 \end{cases}


Augmented matrix:


[121721181128]\left[\begin{array}{ccc|c} 1 & 2 & 1 & 7 \\ 2 & 1 & 1 & 8 \\ 1 & 1 & 2 & 8 \end{array}\right]


Step 1R2R22R1R_2 \leftarrow R_2 - 2R_1, R3R3R1R_3 \leftarrow R_3 - R_1:


[121703160111]\left[\begin{array}{ccc|c} 1 & 2 & 1 & 7 \\ 0 & -3 & -1 & -6 \\ 0 & -1 & 1 & 1 \end{array}\right]


Step 2R3R313R2R_3 \leftarrow R_3 - \frac{1}{3}R_2:


[1217031600433]\left[\begin{array}{ccc|c} 1 & 2 & 1 & 7 \\ 0 & -3 & -1 & -6 \\ 0 & 0 & \frac{4}{3} & 3 \end{array}\right]


Row Echelon Form (REF) is now complete.

Step 3 — Back Substitution:


43z=3z=94\frac{4}{3}z = 3 \Rightarrow z = \frac{9}{4}


3y94=6y=54-3y - \frac{9}{4} = -6 \Rightarrow y = \frac{5}{4}


x+254+94=7x=94x + 2 \cdot \frac{5}{4} + \frac{9}{4} = 7 \Rightarrow x = \frac{9}{4}

Algorithm summary: Forward elimination builds the REF → Back substitution yields the solution.


Key Concepts Summary#

ConceptDescription
EliminationAdd or subtract equations to cancel out variables
Row Echelon Form (REF)Intermediate matrix form with zeros below the diagonal
Reduced Row Echelon Form (RREF)Fully solved form with zeros both above and below the diagonal
RankNumber of non-zero rows = amount of independent information
Gaussian EliminationSystematic method applying row operations to an augmented matrix
Degrees of FreedomNumber of freely choosable variables (in a singular system)


Quiz#

Q1. Solve the following system using elimination.


{3x+2y=1xy=3\begin{cases} 3x + 2y = 1 \\ x - y = 3 \end{cases}


Show answer

R1R13R2R_1 \leftarrow R_1 - 3R_2: (3x+2y)3(xy)=19(3x + 2y) - 3(x - y) = 1 - 9

5y=8y=855y = -8 \Rightarrow y = -\frac{8}{5}

x=3+y=385=75x = 3 + y = 3 - \frac{8}{5} = \frac{7}{5}

Solution: x=75, y=85x = \dfrac{7}{5},\ y = -\dfrac{8}{5}


Q2. Convert the following matrix to Row Echelon Form (REF) and find its rank.


[123246011]\begin{bmatrix} 1 & 2 & 3 \\ 2 & 4 & 6 \\ 0 & 1 & 1 \end{bmatrix}


Show answer

R2R22R1R_2 \leftarrow R_2 - 2R_1:


[123000011]\begin{bmatrix} 1 & 2 & 3 \\ 0 & 0 & 0 \\ 0 & 1 & 1 \end{bmatrix}


R2R3R_2 \leftrightarrow R_3 (swap rows):


[123011000]\begin{bmatrix} 1 & 2 & 3 \\ 0 & 1 & 1 \\ 0 & 0 & 0 \end{bmatrix}


There are 2 non-zero rows, so rank = 2 (singular matrix).


Q3. Which of the following operations does NOT preserve the singularity of a matrix?

  1. Swap two rows
  2. Add one row to another
  3. Add 5 to every element in a row
  4. Multiply a row by 3
Show answer

Option 3 — Adding a fixed constant to all elements of a row is not a valid equation operation and can change the singularity of the matrix.

Options 1, 2, and 4 are all valid row operations that preserve singularity.


Q4. Determine the rank and solution type for the following system.


{x+y=32x+2y=63x+3y=9\begin{cases} x + y = 3 \\ 2x + 2y = 6 \\ 3x + 3y = 9 \end{cases}


Show answer

Augmented matrix:


[113226339]\left[\begin{array}{cc|c} 1 & 1 & 3 \\ 2 & 2 & 6 \\ 3 & 3 & 9 \end{array}\right]


After applying R2R22R1R_2 \leftarrow R_2 - 2R_1 and R3R33R1R_3 \leftarrow R_3 - 3R_1:


[113000000]\left[\begin{array}{cc|c} 1 & 1 & 3 \\ 0 & 0 & 0 \\ 0 & 0 & 0 \end{array}\right]


rank = 1, degrees of freedom = 1 → Infinitely many solutions (singular system)

All three equations carry the same information.


In the next post, we'll cover vector operations (addition, subtraction, dot product, norm), linear transformations, matrix multiplication, matrix inverses, and how all of this connects to neural networks (perceptrons).

// Related Posts