4.3 Linear systems: solving Ax = b

The everyday task of linear algebra: given an n×nn \times n matrix AA and an nn-vector b\mathbf{b}, find the vector x\mathbf{x} such that

Ax  =  b.A \mathbf{x} \;=\; \mathbf{b}.

Concretely this is a system of nn linear equations in nn unknowns. For example,

2x1+1x21x3=8,3x11x2+2x3=11,2x1+1x2+2x3=3,\begin{aligned} 2 x_1 + \phantom{1}x_2 - \phantom{1}x_3 &= 8, \\ -3 x_1 - \phantom{1}x_2 + 2 x_3 &= -11, \\ -2 x_1 + \phantom{1}x_2 + 2 x_3 &= -3, \end{aligned}

written as the single matrix equation

(211312212)(x1x2x3)  =  (8113).\begin{pmatrix} 2 & 1 & -1 \\ -3 & -1 & 2 \\ -2 & 1 & 2 \end{pmatrix} \begin{pmatrix} x_1 \\ x_2 \\ x_3 \end{pmatrix} \;=\; \begin{pmatrix} 8 \\ -11 \\ -3 \end{pmatrix}.

There are infinitely many ways to phrase this problem and one canonical algorithm that solves it: Gaussian elimination. The algorithm is simple, deterministic, and is exactly the row-reduction procedure that high-school algebra teaches without ever using the matrix word.

Three things that can happen

Before the algorithm, the structure. A square linear system Ax=bA \mathbf{x} = \mathbf{b} has one of exactly three outcomes:

  1. A unique solution. This is the generic case — it happens precisely when AA is invertible, equivalently when detA0\det A \neq 0, equivalently when the columns of AA are linearly independent.
  2. No solution. The system is inconsistent: the equations contradict each other. Geometrically (for two equations in two unknowns): two parallel lines that never meet. Algebraically: Gaussian elimination produces a row of the form ”0=0 = nonzero”, which can’t be satisfied.
  3. Infinitely many solutions. The equations are consistent but redundant: some are linear combinations of others. Geometrically (for three planes in 3-D): they intersect in a line or a plane rather than a point. Algebraically: elimination produces a row of all zeros, and at least one variable is free — it can take any value, with the other variables determined by it.

Cases 2 and 3 both correspond to detA=0\det A = 0 — a singular matrix. The distinction between them is whether b\mathbf{b} happens to lie in the span of AA‘s columns (case 3) or doesn’t (case 2). Gaussian elimination tells you which case you’re in without you having to think about it: it just runs and you read off the answer from the final form.

The algorithm

Gaussian elimination works on the augmented matrix [Ab][A \mid \mathbf{b}] — the matrix AA with the right-hand-side vector tacked on as an extra column:

[2118312112123].\left[ \begin{array}{ccc|c} 2 & 1 & -1 & 8 \\ -3 & -1 & 2 & -11 \\ -2 & 1 & 2 & -3 \end{array} \right].

Three elementary row operations are allowed, each of which preserves the solution set of the underlying linear system:

  1. Swap two rows.
  2. Multiply a row by a non-zero scalar.
  3. Add a scalar multiple of one row to another.

The procedure is to use these operations to bring the matrix into upper-triangular form (zeros below the diagonal) — also called row echelon form. Once you have that, you read the answer from the bottom up by back substitution.

The standard pattern is: pick the top-left entry as the first pivot, use operation 3 to zero out everything below it in column 1, move to position (2, 2) as the next pivot, zero out below it, and so on. If the pivot position is already zero, swap rows to bring a non-zero entry there first.

Initial augmented matrix [A | b]
21-1|8
-3-12|-11
-212|-3
system:
step 1 of 5

Each step performs one elementary row operation — a row swap or a "subtract a multiple of one row from another". The pivot column for the current step is highlighted. Once the matrix is in upper-triangular form (echelon), the solution is read off by back-substitution from the last row up. The inconsistent and dependent-rows presets show the two ways a 3×3 system can fail to have a unique solution: an "0 = nonzero" contradiction (no solution) or a "0 = 0" tautology (a whole line or plane of solutions).

Step through the algorithm on four representative systems: a standard 3×33 \times 3 with a unique solution, one that needs a row swap to find a pivot, an inconsistent system that produces a "0=nonzero0 = \text{nonzero}" contradiction, and a dependent system whose third equation is a linear combination of the first two.

Worked example

Worked example: every step, no shortcuts

The problem. Solve

2x1+x2x3=8,3x1x2+2x3=11,2x1+x2+2x3=3.\begin{aligned} 2 x_1 + x_2 - x_3 &= 8, \\ -3 x_1 - x_2 + 2 x_3 &= -11, \\ -2 x_1 + x_2 + 2 x_3 &= -3. \end{aligned}

Step 1 — Write the augmented matrix.

[2118312112123].\left[ \begin{array}{ccc|c} 2 & 1 & -1 & 8 \\ -3 & -1 & 2 & -11 \\ -2 & 1 & 2 & -3 \end{array} \right].

Step 2 — Eliminate the first column below the pivot a11=2a_{11} = 2. We want zeros in positions (2,1)(2, 1) and (3,1)(3, 1).

For row 2: R2R2(3/2)R1=R2+(3/2)R1R_2 \to R_2 - (-3/2) R_1 = R_2 + (3/2) R_1.

R2(3+(3/2)(2),  1+(3/2)(1),  2+(3/2)(1),  11+(3/2)(8))=(0,  1/2,  1/2,  1).R_2 \to \bigl(-3 + (3/2)(2),\; -1 + (3/2)(1),\; 2 + (3/2)(-1),\; -11 + (3/2)(8)\bigr) = (0,\; 1/2,\; 1/2,\; 1).

For row 3: R3R3(2/2)R1=R3+R1R_3 \to R_3 - (-2/2) R_1 = R_3 + R_1.

R3(2+2,  1+1,  2+(1),  3+8)=(0,  2,  1,  5).R_3 \to (-2 + 2,\; 1 + 1,\; 2 + (-1),\; -3 + 8) = (0,\; 2,\; 1,\; 5).

Matrix now:

[211801/21/210215].\left[ \begin{array}{ccc|c} 2 & 1 & -1 & 8 \\ 0 & 1/2 & 1/2 & 1 \\ 0 & 2 & 1 & 5 \end{array} \right].

Step 3 — Eliminate the second column below the pivot a22=1/2a_{22} = 1/2. We want a zero in position (3,2)(3, 2). Multiplier: 2/(1/2)=42 / (1/2) = 4.

R3R34R2R_3 \to R_3 - 4 R_2:

R3(0,  241/2,  141/2,  541)=(0,  0,  1,  1).R_3 \to (0,\; 2 - 4 \cdot 1/2,\; 1 - 4 \cdot 1/2,\; 5 - 4 \cdot 1) = (0,\; 0,\; -1,\; 1).

Matrix now in upper-triangular form:

[211801/21/210011].\left[ \begin{array}{ccc|c} 2 & 1 & -1 & 8 \\ 0 & 1/2 & 1/2 & 1 \\ 0 & 0 & -1 & 1 \end{array} \right].

Step 4 — Back-substitute. Read from the bottom up.

Row 3 says x3=1-x_3 = 1, so x3=1x_3 = -1.

Row 2 says (1/2)x2+(1/2)x3=1(1/2) x_2 + (1/2) x_3 = 1. Substitute x3=1x_3 = -1: (1/2)x21/2=1(1/2) x_2 - 1/2 = 1, so x2=3x_2 = 3.

Row 1 says 2x1+x2x3=82 x_1 + x_2 - x_3 = 8. Substitute x2=3x_2 = 3 and x3=1x_3 = -1: 2x1+3(1)=82 x_1 + 3 - (-1) = 8, so 2x1=42 x_1 = 4 and x1=2x_1 = 2.

Step 5 — Final answer.

  x=(x1,x2,x3)=(2,3,1).  \boxed{\;\mathbf{x} = (x_1, x_2, x_3) = (2, 3, -1).\;}

Step 6 — Sanity-check by substitution.

  • 2(2)+1(3)+(1)(1)=4+3+1=8.2(2) + 1(3) + (-1)(-1) = 4 + 3 + 1 = 8.
  • 3(2)+(1)(3)+2(1)=632=11.-3(2) + (-1)(3) + 2(-1) = -6 - 3 - 2 = -11.
  • 2(2)+1(3)+2(1)=4+32=3.-2(2) + 1(3) + 2(-1) = -4 + 3 - 2 = -3.

What if A isn’t square?

If the system Ax=bA \mathbf{x} = \mathbf{b} has more equations than unknowns (overdetermined) or fewer equations than unknowns (underdetermined), the same elimination machinery still applies, but the answer is no longer a single point.

Both extensions belong to “applied linear algebra” rather than the working subset this chapter covers. Knowing they exist is enough; the algorithms reduce, under the hood, to the same elimination procedure used here.

Connection to invertibility

Gaussian elimination also tells you whether AA is invertible without computing the inverse: AA is invertible if and only if reducing [AI][A \mid I] produces [IA1][I \mid A^{-1}] without running into a row of zeros on the AA side. This is the same algorithm as solving Ax=bA \mathbf{x} = \mathbf{b}, run with b\mathbf{b} replaced by the columns of II one at a time.

Computing inverses directly is rarely what one wants in practice — solving Ax=bA \mathbf{x} = \mathbf{b} by elimination is faster and more numerically stable. The conceptual point (”AA is invertible \Leftrightarrow Ax=bA \mathbf{x} = \mathbf{b} has a unique solution for every b\mathbf{b}”) matters; the practical action — “compute the inverse” — usually does not.

What we use this for

Linear systems are everywhere. A short, representative list:

The next lesson, 4.4 — Eigenvalues and eigenvectors, takes us in a different direction: rather than solving Ax=bA \mathbf{x} = \mathbf{b} for arbitrary b\mathbf{b}, we ask which special inputs v\mathbf{v} the matrix sends to scalar multiples of themselves. The answer turns out to be the unifying concept across linear algebra.