Systems of Linear Equations
Linear algebra was born from one deceptively simple question: given several linear constraints, what values satisfy all of them at once? That question is a system of linear equations, and it shows up everywhere — from mixing ingredients in a factory to fitting a regression line through data.
A real-life example: the production plan
Imagine a small workshop that makes two products, tables and chairs. Each needs wood and labor:
- A table uses 4 units of wood and 2 hours of labor.
- A chair uses 1 unit of wood and 2 hours of labor.
This week you have 5 units of wood and 6 hours of labor, and you want to use them up exactly (no waste). How many tables and chairs should you make?
Each resource gives you one equation:
Two equations, two unknowns. This is a system of linear equations. Solving it (we will, below) tells you the unique plan that spends every resource.
The general form
With equations and unknowns , a system of linear equations looks like this:
The are known coefficients, the are known constants, and the are the unknowns we solve for. Any tuple that satisfies every equation simultaneously is called a solution.
The key question: how many solutions?
For a real-valued system, there are only three possibilities:
flowchart TD S["System of linear
equations"] S --> A["Exactly ONE solution
(lines cross at a point)"] S --> B["NO solution
(parallel, never meet)"] S --> C["INFINITELY many
(same line, fully overlap)"]
The geometry makes this vivid. With two unknowns, each equation is a line in the -plane. A solution must lie on all lines at once — so the solution set is the intersection of the lines:
- Lines cross at one point → one solution.
- Lines are parallel but distinct → no solution.
- Lines are identical → infinitely many solutions.
See it move
Watch two lines interact. One line (amber) stays fixed; the other (blue) sweeps through all three regimes. The white dot marks the solution when it exists — notice how it flies off to infinity as the lines become parallel, then the lines merge into one:
Right away this tells you something profound: most of the difficulty in solving a system is just figuring out which of these three cases you’re in. In machine learning, “no exact solution” is the normal case (more data points than parameters), which is precisely why we switch to least squares — finding the closest thing to a solution.
Solving our workshop system
Back to the tables and chairs:
From the second equation, , so . Substitute into the first:
Then . A single, unique answer — the two lines cross at exactly one point.
Let NumPy do it
For anything bigger than 2×2 you’ll reach for code. NumPy’s linalg.solvelinalg.solve finds the unique
solution directly:
import numpy as np
# 4*x1 + 1*x2 = 5 (wood)
# 2*x1 + 2*x2 = 6 (labor)
A = np.array([[4.0, 1.0],
[2.0, 2.0]])
b = np.array([5.0, 6.0])
x = np.linalg.solve(A, b)
print("tables x1 =", round(x[0], 4))
print("chairs x2 =", round(x[1], 4))
# Verify: plug the solution back in
print("check A @ x =", A @ x) # should equal bimport numpy as np
# 4*x1 + 1*x2 = 5 (wood)
# 2*x1 + 2*x2 = 6 (labor)
A = np.array([[4.0, 1.0],
[2.0, 2.0]])
b = np.array([5.0, 6.0])
x = np.linalg.solve(A, b)
print("tables x1 =", round(x[0], 4))
print("chairs x2 =", round(x[1], 4))
# Verify: plug the solution back in
print("check A @ x =", A @ x) # should equal btables x1 = 0.6667
chairs x2 = 2.3333
check A @ x = [5. 6.]tables x1 = 0.6667
chairs x2 = 2.3333
check A @ x = [5. 6.]The three regimes, side by side
flowchart LR
subgraph One["Unique"]
direction TB
O1["4x₁ + x₂ = 5
2x₁ + 2x₂ = 6"] --> O2["cross once"]
end
subgraph None["No solution"]
direction TB
N1["x₁ + x₂ = 3
x₁ + x₂ = 1"] --> N2["parallel"]
end
subgraph Inf["Infinite"]
direction TB
I1["x₁ + x₂ = 3
2x₁ + 2x₂ = 6"] --> I2["same line"]
end
Why this matters for ML
- Linear regression solves a system like this to fit a line/plane to data — except there are usually more equations than unknowns, so no exact solution exists and we find the best-fit instead (Chapter 9).
- The “singular matrix” error you’ll hit in practice is this exact theory surfacing: redundant or contradictory features make the system unsolvable.
- The compact form we’re heading toward is the single most common equation in all of numerical computing.
🧪 Try It Yourself
Exercise 1 – Solve a 2×2 system
Exercise 2 – Detect an unsolvable system
Exercise 3 – Verify a solution
Recap
- A system of linear equations asks for values satisfying several linear constraints at once.
- Geometrically each equation is a line (or plane); solutions are their intersection.
- There are exactly three outcomes: one, none, or infinitely many solutions.
np.linalg.solvenp.linalg.solvehandles the unique case; aSingular matrixSingular matrixerror signals the other two.
Next: we compress this whole system into a single object — the matrix — and learn how it both stores and transforms data.
If this helped you, consider buying me a coffee ☕
Buy me a coffeeWas this page helpful?
Let us know how we did
