How to Solve a System of Linear Equations with Matrices

Two equations, two unknowns, one answer. Here's how elimination turns into matrix multiplication, why some systems have no answer at all, and why solving Ax = b is really just running a transformation backward.

By Petrus Sheya

July 21, 2026 · 6 min read

You have two equations and two unknowns. How do you find the exact pair of numbers that makes both of them true at the same time?

You could guess and check. But that gets old fast, and it falls apart completely once you have five unknowns instead of two. There's a better way, and it turns out to be one of the most useful ideas in applied math: turn the equations into a matrix, and solve the matrix instead.


What does "solving a system" actually mean?

Say we have:

x+y=62xy=c\begin{aligned} x + y &= 6 \\ 2x - y &= c \end{aligned}

Each equation, on its own, describes a whole line of possible (x,y)(x,y) pairs. The first equation is satisfied by infinitely many points. So is the second. The solution to the system is the one point that satisfies both at once, the point where the two lines cross.

That's it. That's the whole idea, before any matrices show up.

Visualizer 01

The Solution Is Where the Lines Cross

Drag the slider to move the second line. The crossing point always stays on the first line, because it has to satisfy both equations at once.

x + y = 62x − y = 2.0
x2.667
y3.333

Drag the slider and watch the second line swing around. The crossing point slides along the first line, because it always has to sit on both lines at once. Hover over the dot to read off its exact coordinates.

We write two equations in two unknowns as a system because we need both constraints at the same time, not because there's anything special about matrices yet. The matrices come later, as bookkeeping.


How do we find that point without guessing?

Here's the trick: if two things are equal, we can add or subtract them from another equation and the equality still holds. So we combine the equations to cancel a variable out.

Take x+y=6x + y = 6 and 2xy=c2x - y = c. Add them together and yy vanishes: 3x=6+c3x = 6 + c. Now we have one equation, one unknown. Solve for xx, then plug it back in for yy.

This trick scales. With three equations and three unknowns, we do it in stages: use equation 1 to cancel xx out of equations 2 and 3, then use the new equation 2 to cancel yy out of equation 3. What's left is one equation in one unknown, and we work backward from there. This staged cancellation is called Gaussian elimination.

Visualizer 02

Gaussian Elimination, One Row at a Time

Step through the elimination. Each move replaces one row with itself minus a multiple of another row, chosen to zero out one entry.

111621−111−125Starting augmented matrix
Step1 / 5
z, y, x?

Step through it. At each stage, one row gets replaced by itself minus a multiple of another row, chosen specifically to zero out one entry. By the last step, the system has collapsed into a staircase shape, one variable revealed at a time, and reading off the answer is just back-substitution.

We write this bookkeeping as an augmented matrix, coefficients on the left, constants on the right:

[111621111125]\left[\begin{array}{ccc|c} 1 & 1 & 1 & 6 \\ 2 & 1 & -1 & 1 \\ 1 & -1 & 2 & 5 \end{array}\right]

Every "R2 → R2 − 2R1" you just watched is a row operation, and stacking them together is exactly what turns this into row echelon form.


What if there's no single crossing point?

Two lines almost always cross exactly once. But not always. If they're parallel, they never cross, no solution exists. If they're the same line, they cross everywhere, infinitely many solutions.

Visualizer 03

When the Determinant Hits Zero

Drag k toward 1. The second line rotates toward parallel, the crossing point races off toward infinity, and the determinant crosses zero exactly when it vanishes.

x + y = 4x + 0.00y = 2
det(A)-1.000
StatusUnique solution

Watch the second line rotate as you drag kk. Near k=1k = 1, it swings almost parallel to the first line, and the crossing point shoots off toward infinity before vanishing entirely...

There's a single number that predicts this without drawing anything: the determinant. For a 2×22\times 2 system with coefficient matrix

A=[abcd],det(A)=adbcA = \begin{bmatrix} a & b \\ c & d \end{bmatrix}, \qquad \det(A) = ad - bc

when det(A)=0\det(A) = 0, the two rows of AA point in the same direction, and geometrically that's exactly what "parallel" means. Elimination breaks down because there's no way left to isolate a single point. A unique solution exists exactly when the determinant is nonzero.


Where does the matrix actually come in?

Now for the interesting part: we can write the entire system as a single equation.

Ax=b,A=[a11a12a21a22],x=[xy],b=[b1b2]A\mathbf{x} = \mathbf{b}, \qquad A = \begin{bmatrix} a_{11} & a_{12} \\ a_{21} & a_{22} \end{bmatrix}, \quad \mathbf{x} = \begin{bmatrix} x \\ y \end{bmatrix}, \quad \mathbf{b} = \begin{bmatrix} b_1 \\ b_2 \end{bmatrix}

Think of AA as a machine. Feed it an input vector x\mathbf{x}, and it spits out an output vector b\mathbf{b}. Solving the system means running the machine backward: we know what came out, we need to know what went in.

Running a machine backward is exactly what the inverse matrix does. If det(A)0\det(A) \neq 0, then A1A^{-1} exists, and:

Ax=bx=A1bA\mathbf{x} = \mathbf{b} \quad \Longrightarrow \quad \mathbf{x} = A^{-1}\mathbf{b}
Visualizer 04

Run the Machine Backward

Drag the point on the right, that's b. The left panel shows the exact x that A maps to it, computed live as x = A⁻¹b.

INPUT SPACE (x)OUTPUT SPACE (b)
b = (b₁, b₂)(2.00, 1.50)
x = A⁻¹b(0.90, 0.20)

Drag the point in the right-hand panel, that's b\mathbf{b}, whatever output you want. Watch the left-hand panel update instantly, that's the exact x\mathbf{x} that produces it. Every drag is a fresh system solved in real time, by the same A1bA^{-1}\mathbf{b} formula every time.

Behind the scenes, Gaussian elimination and multiplying by A1A^{-1} are doing the same job. Elimination is usually faster to compute by hand, and computers use a version of it too, but the inverse is the cleanest way to think about what solving means: undoing a transformation.


Why any of this matters

GPS receivers solve a system of equations every time they compute your position, using timing signals from multiple satellites as constraints, the same intersecting-lines idea from above, just in three dimensions with spheres instead of lines.

Computer graphics engines invert transformation matrices constantly, to convert between world coordinates and camera coordinates.

Economists solve linear systems to find equilibrium prices, the point where supply equations and demand equations agree.

Structural engineers solve systems with hundreds of unknowns to figure out the forces on every joint of a bridge, all at once.

Anywhere you have several linear constraints and need the one answer that satisfies all of them, this is the machinery running underneath.


The plain-English version

A system of linear equations asks for the one point that satisfies every equation at once, geometrically, where the lines (or planes) all cross. Gaussian elimination finds that point by systematically cancelling variables, one at a time, until only one is left. Writing the system as Ax=bA\mathbf{x} = \mathbf{b} turns that same process into a single machine, and solving it means running the machine in reverse, x=A1b\mathbf{x} = A^{-1}\mathbf{b}. That inverse only exists when the determinant is nonzero, which is algebra's way of saying the equations aren't secretly redundant or contradictory.


All four visualizations are interactive React components running in your browser. No libraries beyond React.