Chapter 4: Solving linear systems
Previous: LA 03 Matrices as Linear Maps | LA 00 Course Map | Next: LA 05 Subspaces Basis and Rank
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.
- Read a system of equations in three ways: rows, columns, and as a matrix map.
- Run Gaussian elimination and back-substitution by hand.
- Recognize from the final staircase whether there is one solution, none, or infinitely many.
- Write the full solution set using free variables.
- Compute inverses by elimination, and record elimination as .
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
| Word | Meaning |
|---|---|
| coefficient matrix | , the numbers multiplying the unknowns |
| right-hand side | |
| augmented matrix | : with attached as an extra column |
| solution | a vector that makes every equation true |
| solution set | the set of all solutions |
| consistent | has 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
- Replace a row by itself plus a multiple of another row.
- Swap two rows.
- 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
- Write the augmented matrix .
- Take the first column. Use the top entry (the pivot) to create zeros below it.
- Move to the next row and the next column. Use its pivot to create zeros below it.
- Continue until the left part is a staircase (echelon form).
- 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: ✓; ✓; ✓.
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).
- Solve by elimination: , .
- What multiplier eliminates the 6 below a pivot of 3?
- Solve .
Answers. 1. Row 2 minus 2 row 1: , so , . 2. . 3. , , so .
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.
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 elimination | Outcome |
|---|---|
| a row with | no solution |
| consistent, and every column of has a pivot | exactly one solution |
| consistent, and some column of has no pivot | infinitely 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.
- After elimination you get . Which variables are free? Write the solution.
- After elimination you get . Solutions?
Answers. 1. Pivots in columns 1 and 3, so is free. , , : . 2. None: the last row says .
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
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.
- Every pivot is 1.
- Each pivot is the only nonzero entry in its column.
- 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 :
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.
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:
- is invertible.
- Elimination finds pivots.
- has exactly one solution for every .
- has only the solution .
- The columns of are linearly independent.
- The columns of span .
- (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:
- Solve by forward substitution (top to bottom).
- 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
| Step | What you do |
|---|---|
| set up | write |
| eliminate | create zeros below each pivot (multiplier = entry ÷ pivot) |
| inspect | row? no solution. Free columns? infinitely many. Else one |
| solve | back-substitute; free variables become parameters |
| write | |
| check | substitute into the original equations |
Three facts to remember:
- Row operations never change the solutions.
- One, none, or infinitely many: never exactly two.
- 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.
A1. From the second, . Then , so , .
A2. : . : . Then : . So , , . Check equation 3: ✓.
A3. is free, . , . Solution : a line in .
A4. gives . No solution.
A5. . Inverse .
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 .
B1. gives . (a) : one solution. (b) : , none. (c) : , infinitely many.
B2. : . Free: , . Then and . So .
B3. Multiplier . , . Forward: , so . Back: , ; , .
B4. and . From the second, . Substituting: , so and . Twenty chairs and ten tables.
B5. Equations: ; ; . So and , giving , . The quadratic is .
B6. Elimination found three pivots in a matrix. The pivots depend only on , not on , so for any there is no impossible row and no free variable.
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”.
C1. Suppose rows become and . If satisfies and , it satisfies (add times one true equation to another). Conversely, if satisfies and , subtract times to get . The solution sets are identical.
C2. If , then , so by assumption.
C3. At most 3 pivots (one per row) among 5 columns, so at least 2 columns are free. A consistent system with a free variable has infinitely many solutions.
C4. , so is not a solution. Every span contains (chapter 1), so the solution set is a shifted copy of the null space, not a span itself.
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.)
D2. In each column, find the row with the largest absolute value at or below the diagonal (np.argmax(abs(...))), swap it up, then eliminate below.
D3. SciPy uses partial pivoting, so it may swap rows to put the largest entry first. Then and differ from the hand version, and records the swaps, but still equals .
D4. The first gives ; the second gives . A change of in the data moved the solution by . The two equations describe nearly parallel lines, so their crossing point is very sensitive.
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.