1 Introduction: Solving for Multiple Unknowns
Suppose you visit a stationery shop and purchase 2 pens and 1 notebook for a total of \$70. Shortly after, your friend visits the same shop and buys 1 pen and 1 notebook of the identical brand for \$50.
Now consider the question: What is the individual unit price of a single pen, and what is the unit price of a single notebook?
Formulating the Equations
Let $x$ represent the price of a single pen, and let $y$ represent the price of a single notebook. We can express the receipts as two linear equations:
If you analyze equation (1) in isolation, infinitely many pairs of $(x, y)$ satisfy it—for instance, $x = 10, y = 50$, or $x = 25, y = 20$. However, when both constraints must hold simultaneously, a unique solution exists.
Subtracting Equation (2) from Equation (1) eliminates the variable $y$:
Substituting $x = 20$ back into Equation (2):
Hence, a pen costs \$20, and a notebook costs \$30. This mathematical system is known as a System of Linear Equations. From rendering 3D graphics and balancing electrical networks to training neural networks in machine learning, linear systems form the bedrock of computational problem solving.
2 Linear Equations & Systems of Linear Equations
Definition of a Linear Equation
An algebraic equation is called a Linear Equation if every variable appears to the first power ($1$) only, with no variable cross-products ($xy$), roots ($\sqrt{x}$), or non-linear transcendental functions ($\sin x, e^x$).
• Single Variable: $ax = b$ (e.g., $5x = 20 \implies x = 4$)
• Two Variables: $ax + by = c$ (e.g., $2x + 3y = 12$)
• $n$ Variables: $a_1 x_1 + a_2 x_2 + \dots + a_n x_n = b$
| Equation | Linear? | Rationale |
|---|---|---|
| $2x + 3y = 12$ | ✓ Yes (Linear) | Both variables have exponent 1; no cross-products or roots. |
| $x^2 + y = 10$ | ✗ No (Non-linear) | Variable $x$ has exponent 2 (quadratic parabolic term). |
| $xy = 12$ | ✗ No (Non-linear) | Variables $x$ and $y$ are multiplied together (cross-product). |
| $\sin(x) + 4y = 8$ | ✗ No (Non-linear) | Trigonometric sine function violates linearity. |
What is a System of Linear Equations?
A collection of two or more linear equations sharing the same set of variables is known as a System of Linear Equations.
In general mathematical notation, a system of $m$ linear equations in $n$ unknown variables is formulated as:
where $a_{ij}$ denotes coefficients, $x_j$ denotes unknown variables, and $b_i$ denotes constant scalar terms.
3 The Three Possible Solution Regimes
No matter how many variables or equations a linear system contains, its solution space will always fall into exactly one of three mutually exclusive categories:
Single Point of Intersection
Exactly one set of values satisfies all equations in the system simultaneously.
$x - y = 1$
$\implies (x, y) = (3, 2)$
Dependent Constraints
The equations represent identical or overlapping constraints with free parameters.
$2x + 2y = 4$
$\implies y = t, x = 2 - t$
Contradictory Constraints
Constraints are mutually exclusive. Geometrically, lines or planes are parallel and non-intersecting.
$x + y = 5$
$\implies 0 = 3$ (Contradiction!)
4 Graphical Method: The Geometry of Linear Systems
In the two-dimensional Cartesian plane ($\mathbb{R}^2$), every linear equation $ax + by = c$ plots as a straight line. Solving a system of two equations is geometrically equivalent to finding the relative spatial relationship between the two lines:
1. Intersecting Lines (Unique)
Slopes are distinct ($m_1 e m_2$). Exactly one intersection point exists.
2. Coincident Lines (Infinite)
Both equations depict the identical geometric line. Every point on the line is a solution.
3. Parallel Lines (None)
Equal slopes ($m_1 = m_2$) with different $y$-intercepts. No common points exist.
In $\mathbb{R}^3$, each linear equation $ax + by + cz = d$ represents a flat 2D plane. Solving three equations corresponds to finding the intersection of three planes: they can meet at a single point (unique solution), along a common intersection line (infinitely many solutions), or fail to have any mutual meeting point (no solution). In 4 or higher dimensions, graphical visualization is impossible, making algorithmic matrix methods mandatory.
5 The Substitution Method
The Substitution Method is an algebraic technique where one variable is isolated from one equation and substituted into the remaining equation(s), systematically reducing the number of unknowns.
Step-by-Step Worked Solution:
(1) $x + y = 7$
(2) $2x - y = 5$
Step 1 (Isolate a Variable): From Equation (1), express $y$ in terms of $x$:
$$y = 7 - x$$
Step 2 (Substitute into Equation 2): Replace $y$ with $(7 - x)$ in Equation (2):
$$2x - (7 - x) = 5$$
Caution: Distribute the negative sign to all terms within parentheses:
$$2x - 7 + x = 5 \implies 3x - 7 = 5 \implies 3x = 12 \implies \mathbf{x = 4}$$
Step 3 (Solve for the Remaining Unknown): Plug $x = 4$ back into the isolated expression:
$$y = 7 - 4 \implies \mathbf{y = 3}$$
Step 4 (Verification):
Eq (1): $4 + 3 = 7$ (True)
Eq (2): $2(4) - 3 = 8 - 3 = 5$ (True)
Solution: x = 4, y = 3
6 The Elimination Method (Linear Combinations)
In the Elimination Method, equations are scaled by scalar constants so that coefficients for a chosen unknown match or become opposites, allowing direct addition or subtraction to eliminate that variable.
Worked Example: Elimination via Scaling
(2) $x + y = 5$
Step 1 (Scale to Match Coefficients): Multiply Equation (2) by 2 so that the $x$-coefficient equals that of Equation (1):
$$2 imes (x + y = 5) \implies 2x + 2y = 10 \quad ext{--- (3)}$$
Step 2 (Subtract to Eliminate $x$): Subtract Equation (3) from Equation (1):
$$(2x + 3y) - (2x + 2y) = 13 - 10 \implies y = 3$$
Step 3 (Solve for $x$): Substitute $y = 3$ back into Equation (2):
$$x + 3 = 5 \implies x = 2$$
7 Gaussian Elimination & Augmented Matrices
Real-world computing problems frequently feature thousands of variables. Manual substitution or elimination is prone to bookkeeping errors. Pioneered by Carl Friedrich Gauss, Gaussian Elimination is a systematic algorithmic pipeline designed for programmable matrix computation.
The Augmented Matrix
We encode a linear system by assembling its coefficients into matrix $A$ and its constants into vector $\mathbf{b}$, forming the combined Augmented Matrix $[A \mid \mathbf{b}]$:
The vertical line separates the coefficient matrix $A$ from the constant column $\mathbf{b}$.
The 3 Elementary Row Operations (EROs)
1. Row Swapping ($R_i \leftrightarrow R_j$): Interchange the physical position of two rows.
2. Row Scaling ($R_i \leftarrow k R_i, k e 0$): Multiply all elements of a row by a non-zero scalar.
3. Row Replacement ($R_i \leftarrow R_i + k R_j$): Add or subtract a scalar multiple of another row to a row.
Complete 3-Variable Gaussian Elimination Worked Example
The leading pivot entry in Row 1 is 1. We eliminate entries beneath it:
$R_3 \leftarrow R_3 - R_1 \implies [1 - 1, \; 2 - 1, \; -1 - 1 \mid 2 - 6] = [0, \; 1, \; -2 \mid -4]$
Swap $R_2$ and $R_3$ to acquire a convenient pivot of 1 ($R_2 \leftrightarrow R_3$):
Eliminate $-3$ from Row 3 using $R_2$ ($R_3 \leftarrow R_3 + 3R_2$):
With the matrix in upper-triangular Row Echelon Form, solve from bottom to top:
• From Row 3: $-7z = -21 \implies \mathbf{z = 3}$
• From Row 2: $y - 2z = -4 \implies y - 2(3) = -4 \implies y - 6 = -4 \implies \mathbf{y = 2}$
• From Row 1: $x + y + z = 6 \implies x + 2 + 3 = 6 \implies x + 5 = 6 \implies \mathbf{x = 1}$
Final Solution: $\mathbf{(x, y, z) = (1, 2, 3)}$
8 The Matrix Equation Form: $A\mathbf{x} = \mathbf{b}$
Using the matrix-vector multiplication rules mastered in the previous lesson, every linear system collapses into a compact, unified equation:
Gilbert Strang's Dual Perspective: Row Picture vs. Column Picture
9 Detecting Consistent vs. Inconsistent Systems
During Gaussian elimination, the terminal rows of the augmented matrix immediately signal the existence and nature of solutions:
If a row exhibits zeros across all coefficients but ends with a non-zero constant:
If an entire row consists exclusively of zeros:
Fewer independent pivots exist than variables. Non-pivot columns represent free parameters ($t, s \in \mathbb{R}$) yielding an infinite solution continuum.
10 Solving Linear Systems in Python (NumPy)
In computational workflows, NumPy offers high-performance LAPACK routines via `linalg.solve` to compute solutions with optimal cache and vectorization:
import numpy as np
# Linear System:
# x + y + z = 6
# 2x - y + z = 3
# x + 2y - z = 2
A = np.array([
[1, 1, 1],
[2, -1, 1],
[1, 2, -1]
], dtype=float)
b = np.array([6, 3, 2], dtype=float)
# Solve Ax = b directly via LU factorization
x = np.linalg.solve(A, b)
print("Solution vector x:", x)
# Output: [1. 2. 3.] -> x=1, y=2, z=3
# Verify: A @ x must equal b within numerical tolerances
is_correct = np.allclose(A @ x, b)
print("Verification:", is_correct) # True
11 Real-World Applications in Computer Science & AI
Virtually every physical, statistical, or geometric simulation reduces to solving systems of linear equations:
1. Circuit Simulation (SPICE)
Applying Kirchhoff's Current and Voltage Laws at every node and loop in modern microchips generates sparse linear systems with millions of unknowns solved every millisecond.
2. Machine Learning: Normal Equations
Fitting an optimal linear model via Ordinary Least Squares analytically solves the Normal Equations $(X^T X)\mathbf{w} = X^T \mathbf{y}$ for model weights $\mathbf{w}$.
3. Computer Graphics & Ray Tracing
Detecting whether a camera light ray intersects a triangular polygon in 3D game engines uses the Möller–Trumbore algorithm, which solves a $3 imes 3$ linear system for ray distance and barycentric coordinates.
4. Google's Original PageRank
Modeling web user navigation as a Markov chain leads to a massive linear system $(I - \alpha P^T)\mathbf{r} = \frac{1 - \alpha}{N}\mathbf{1}$, determining global webpage ranking.
12 8 Common Pitfalls & Traps
Pitfall 1: Distributing Negative Signs Incorrectly
Failing to change signs across all terms when subtracting parentheses: $-(ax + b) = -ax - b$, not $-ax + b$.
Pitfall 2: Forgetting the Constant Column in Augmented Matrices
Scaling row coefficients by a scalar while neglecting to scale the constant vector entry $b_i$.
Pitfall 3: Dividing by a Zero Pivot
Attempting elimination when the pivot entry is zero. Always perform partial pivoting (row swapping) first.
Pitfall 4: Misinterpreting $0 = 0$ as "No Solution"
$0 = 0$ is an identity signifying a redundant constraint. The system has infinitely many solutions, not zero solutions.
Pitfall 5: Conflating $0 = c$ with Infinite Solutions
A row $[0 \dots 0 \mid c]$ with $c e 0$ is a flat contradiction ($0 = c$). It strictly denotes No Solution (Inconsistent).
Pitfall 6: Verifying on Only One Equation
Candidate solutions that satisfy Equation 1 might violate Equation 2. Always substitute into all system equations.
Pitfall 7: Overlooking Ill-Conditioned Systems
When lines are nearly parallel, tiny rounding noise produces wildly erratic solutions. Check condition numbers `np.linalg.cond(A)`.
Pitfall 8: Relying on `inv(A) @ b` in Software
Computing explicit matrix inverses is numerically unstable and computationally wasteful compared to direct Gaussian/LU solvers.
Systems of Linear Equations Workbench
Explore geometric intersections, step through 3x3 Gaussian elimination, and simulate real electrical circuits in real time.
1. KCL (Node): $I_1 - I_2 - I_3 = 0$
2. KVL (Loop 1): $R_1 I_1 + R_2 I_2 = V_1$
3. KVL (Loop 2): $R_2 I_2 - R_3 I_3 = 0$
Key Takeaways
A system of linear equations seeks variable assignments that satisfy every constraint at the same time.
Every linear system has either a Unique Solution, Infinitely Many Solutions, or No Solution.
Intersection points of lines in 2D or planes in 3D; higher dimensions generalize to hyperplanes.
Isolate one unknown and substitute into other equations—fast for manual small problems.
Scale and add/subtract equations to cancel variables—the foundational concept behind row operations.
Transform augmented matrices to upper-triangular Row Echelon Form and solve via back-substitution.
$A\mathbf{x} = \mathbf{b}$ expresses systems as a linear combination of matrix columns or intersection of row planes.
A row $[0 \dots 0 \mid c]$ with $c e 0$ proves Inconsistency (No Solution); $[0 \dots 0 \mid 0]$ reveals free variables.
Never use `inv(A) @ b` in software; always use `np.linalg.solve(A, b)` or LU factorization for stability.