Chapter 4: Solving linear systems

Previous: LA 03 Matrices as Linear Maps | LA 00 Course Map | Next: LA 05 Subspaces Basis and Rank

The big idea

Solving means finding the weights that combine the columns of into . Gaussian elimination finds them by turning the system into a staircase shape you can solve from the bottom up. Every system ends in exactly one of three ways: one solution, none, or infinitely many.

In this chapter you will learn to
  1. Read a system of equations in three ways: rows, columns, and as a matrix map.
  2. Run Gaussian elimination and back-substitution by hand.
  3. Recognize from the final staircase whether there is one solution, none, or infinitely many.
  4. Write the full solution set using free variables.
  5. Compute inverses by elimination, and record elimination as .
Before you start

You need the column view of from LA 03 Matrices as Linear Maps, and comfort solving two equations in two unknowns.


4.1 Three views of the same problem

Take the system

View 1: rows (equations as lines). Each equation describes a line in the plane. The solution is the point where the two lines cross. Here they cross at .

View 2: columns (finding a recipe). Rewrite as one vector equation:

Now the question is: what amounts of the two column vectors build ? Answer: 1 of the first and 2 of the second.

View 3: matrix (running a map backwards).

The matrix sends inputs to outputs. Which input did it send to ?

All three views describe one problem. The row view is easy to draw in 2-D. The column view and matrix view are the ones that scale to hundreds of unknowns.

Vocabulary

WordMeaning
coefficient matrix, the numbers multiplying the unknowns
right-hand side
augmented matrix: with attached as an extra column
solutiona vector that makes every equation true
solution setthe set of all solutions
consistenthas at least one solution

4.2 Gaussian elimination

The idea

The easiest systems are triangular:

Solve the last equation first (), substitute upward (), then again (). This is back-substitution.

Elimination is a method for turning any system into a triangular one without changing its solutions.

The three allowed moves

Elementary row operations
  1. Replace a row by itself plus a multiple of another row.
  2. Swap two rows.
  3. Scale a row by a nonzero number.

None of these changes the solution set.

Why they are safe. Each move can be undone by another move of the same kind (subtract the multiple back; swap again; divide by the same number). So any solution of the new system is a solution of the old one and vice versa. Nothing is gained or lost.

The procedure

  1. Write the augmented matrix .
  2. Take the first column. Use the top entry (the pivot) to create zeros below it.
  3. Move to the next row and the next column. Use its pivot to create zeros below it.
  4. Continue until the left part is a staircase (echelon form).
  5. Back-substitute from the bottom.

Worked example 4.1 (step by step)

Column 1. The pivot is the 1 in row 1. We need zeros below it.

  • Row 2 has a 2 there. Subtract 2 times row 1: .
  • Row 3 has a 1 there. Subtract 1 times row 1: .

The multiplier is always (entry to eliminate) (pivot). Here and .

Column 2. The pivot is now the 1 in row 2. Row 3 has a 1 below it. Subtract 1 times row 2: .

This is echelon form. The pivots are .

Back-substitution.

  • Row 3 says , so .
  • Row 2 says , so .
  • Row 1 says , so .

Check in all three original equations: ✓; ✓; ✓.

Always check

Arithmetic slips are the main source of wrong answers. Substituting back into the original equations takes a minute and catches nearly all of them.

When a pivot is zero

If the entry you want to use as a pivot is 0, you cannot divide by it. Swap with a lower row that has a nonzero entry in that column.

Worked example 4.2.

Already triangular: gives ; gives .

If there is no nonzero entry anywhere below in that column, the column has no pivot. Move on to the next column. That situation leads to free variables (section 4.3).


4.3 The three possible outcomes

Outcome 1: no solution

Worked example 4.3.

The last row says , that is . Impossible. No solution.

  • Row picture: two parallel lines that never meet.
  • Column picture: both columns equal , so every combination has equal entries. The target does not, so it cannot be built.
Test for no solution

A row of the form with means the system is inconsistent.

Outcome 2: infinitely many solutions

Worked example 4.4.

The second row says : always true, no information. Only one real equation remains, , with two unknowns.

Column 2 has no pivot, so is a free variable: it can be anything. Call it . Then .

Every value of gives a solution: gives , gives , gives . Geometrically, the two equations describe the same line, and the whole line is the solution set.

Outcome 3: exactly one solution

When there is a pivot in every column of and no impossible row, every variable is determined: exactly one solution, as in example 4.1.

Summary of outcomes

After eliminationOutcome
a row with no solution
consistent, and every column of has a pivotexactly one solution
consistent, and some column of has no pivotinfinitely many solutions

Pivot variables are determined by the equations; free variables (columns without pivots) can be chosen freely.

Why never exactly two?

Suppose and are two different solutions: and . Take any point on the line between them, . By linearity,

So every point on that line is also a solution. Two solutions force infinitely many.


4.4 The structure of the solution set

Homogeneous systems

A system with right-hand side zero, , is called homogeneous. It is always consistent, since works. The question is whether there are other solutions.

The set of all solutions of is the null space of (the main topic of the next chapter).

Particular plus homogeneous

Structure of solutions

If is any one solution of , then every solution has the form

where is a solution of .

Why.

  • Every is a solution: .
  • Every solution has this form: if , set . Then .

In example 4.4, and .

Picture. The solutions of form a line (or plane, …) through the origin. The solutions of are that same line, shifted to pass through . Same shape, moved.

Worked example 4.5 (a 3-unknown system).

Pivots in columns 1 and 3; is free. Set . Row 2: . Row 1: .

Check : gives ✓ and ✓.


4.5 Reduced row echelon form

Echelon form needs back-substitution at the end. If you keep eliminating upward as well, and scale each pivot to 1, you reach reduced row echelon form (RREF), where the answer can be read off directly.

Reduced row echelon form
  1. Every pivot is 1.
  2. Each pivot is the only nonzero entry in its column.
  3. Pivots move right as you go down; zero rows are at the bottom.

Worked example 4.6. Continue from the echelon form of example 4.1.

Clear above the third pivot: and :

Clear above the second pivot: :

Read off: , , .

This full process is Gauss-Jordan elimination. By hand, echelon form plus back-substitution is usually less work. RREF is useful for understanding structure and for computing inverses.


4.6 Inverses by elimination

To find , you want with . Each column of solves . Solve all of them at once by eliminating on the wide matrix :

Gauss-Jordan for inverses

Row reduce . If the left half becomes , the right half is . If the left half develops a zero row, is not invertible.

Worked example 4.7. Invert .

So , matching the formula from chapter 3.

In code, do not invert to solve

To solve in software, use np.linalg.solve(A, b), never np.linalg.inv(A) @ b. Solving directly does about a third of the work and is more accurate. You almost never need the inverse itself.

Invertibility in one list

For a square matrix, these statements are all equivalent. If one is true, all are:

  1. is invertible.
  2. Elimination finds pivots.
  3. has exactly one solution for every .
  4. has only the solution .
  5. The columns of are linearly independent.
  6. The columns of span .
  7. (chapter 7).

This list keeps growing through the course. It is worth rereading after each chapter.


4.7 LU factorization: elimination as a matrix product

Elimination can be recorded as a factorization

  • is the upper triangular matrix you end with.
  • is lower triangular, with 1s on the diagonal and the multipliers you used in the positions they eliminated.

For example 4.1 the multipliers were 2 (row 2, column 1), 1 (row 3, column 1), and 1 (row 3, column 2):

Multiply it out to check; it works.

Why bother? Elimination on an matrix costs about operations. Once you have and , solving for a new is two triangular solves, about operations:

  1. Solve by forward substitution (top to bottom).
  2. Solve by back-substitution.

If you solve with the same many times (a simulation step, a control loop), you factor once and reuse.

When row swaps are needed, the factorization becomes with a permutation matrix recording the swaps. Software also swaps deliberately to put the largest available entry in each pivot position (partial pivoting), because dividing by tiny pivots magnifies rounding errors.


Summary

StepWhat you do
set upwrite
eliminatecreate zeros below each pivot (multiplier = entry ÷ pivot)
inspect row? no solution. Free columns? infinitely many. Else one
solveback-substitute; free variables become parameters
write
checksubstitute into the original equations

Three facts to remember:

  1. Row operations never change the solutions.
  2. One, none, or infinitely many: never exactly two.
  3. All solutions = one particular solution + all solutions of .

Exercises

Part A: warm-up

A1. Solve , .

A2. Solve by elimination:

A3. Solve and describe the solution set geometrically.

A4. Decide whether , has solutions.

A5. Find the inverse of by Gauss-Jordan.

Part B: core

B1. For which values of does the system , have (a) exactly one solution, (b) no solution, (c) infinitely many?

B2. Find all solutions of

in the form .

B3. Find the factorization of and use it to solve .

B4. A small factory makes chairs and tables. A chair uses 2 hours of cutting and 1 of finishing; a table uses 3 of cutting and 4 of finishing. This week there are 70 cutting hours and 60 finishing hours, and you want to use them all. How many of each should be made?

B5. Find a quadratic through the points , , by setting up and solving a system.

B6. Explain why the system in A2 has exactly one solution for any right-hand side, not only .

Part C: explain and prove

C1. Prove that adding a multiple of one equation to another does not change the solution set. (Show both directions: old solutions solve the new system, and new solutions solve the old.)

C2. Prove: if has only the zero solution, then has at most one solution for each .

C3. A system has 3 equations and 5 unknowns. Explain why, if it has any solution, it has infinitely many.

C4. Explain why the solution set of with never contains the zero vector, and so is never a “span”.

Part D: practise with code

D1. Solve A2 with np.linalg.solve. Then check with A @ x.

D2. Write your own gaussian_elimination(A, b) that reduces to echelon form with partial pivoting and back-substitutes. Test it on example 4.1 and A2.

D3. Use scipy.linalg.lu(A) on the matrix of example 4.1. It returns P, L, U. Compare with the and in section 4.7, and explain any differences.

D4. Make the “nearly singular” system , . Solve it, then change the last right-hand side to and solve again. How much did the answer move? (Chapter 12 explains why.)


Where this is used

  • Inverse kinematics linearized around a pose: solve for the joint change that produces a desired hand motion (02 Geometry and Kinematics).
  • Calibration and fitting: every least squares problem ends in a linear system (LA 06 Orthogonality and Least Squares).
  • Circuits and physics: Kirchhoff’s laws and balance equations are linear systems.

Next: LA 05 Subspaces Basis and Rank, which explains why a system has one, none, or infinitely many solutions, using the shape of the column space and null space.