MATH 250 · Mathematics for Economics II

Solving Linear Systems With Matrices

Write several equations as one matrix equation Ax = b, then solve it by methodical row operations.

Key takeaways

  • A linear system is a set of equations in which each unknown appears only to the first power, never multiplied by another unknown.
  • You can write any such system as one matrix equation, Ax = b, where A holds the coefficients, x the unknowns and b the right-hand sides.
  • Three row operations (swap two rows, scale a row, add a multiple of one row to another) never change the solution.
  • Gaussian elimination uses row operations to turn the system into a staircase that you solve from the bottom up.
  • A system has exactly one solution, no solution, or infinitely many; there is no case with exactly two.

Picture Maya, who runs a smoothie cart, staring at her stockroom. She has 40 bananas and 70 cups of berries. Each strawberry smoothie takes 2 bananas and 1 cup of berries. Each green smoothie takes 1 banana and 3 cups of berries. She wants to use up everything, with nothing left to rot. How many of each should she make?

You can guess your way there with two goods. With twelve goods and twelve ingredients, guessing is hopeless. Economists face such problems all the time: many markets that must clear at once, many industries feeding each other, many unknown prices. The good news is that there is a method that always works, needs no inspiration, and is the same whether you have 2 equations or 2,000. It is called row reduction. This lesson shows how it works, why it works, and what happens when a system has no answer, or too many.

From equations to one matrix equation

Let s be the number of strawberry smoothies and g the number of green ones. Maya's two conditions are:

2s +  g = 40     (bananas)
 s + 3g = 70     (cups of berries)

These are linear equations: s and g appear alone, to the first power. Graphically each is a straight line.

Using the notation of Vectors and Matrices, collect the coefficients into a matrix A, the unknowns into a vector x and the right-hand sides into a vector b:

A = [ 2  1 ]     x = [ s ]     b = [ 40 ]
    [ 1  3 ]         [ g ]         [ 70 ]

Then the whole system is the single statement Ax = b. Multiply it out: the first row of A dotted with x is 2s + g, which must equal 40, and so on. One line, two equations. With a thousand equations it is still one line.

The picture is also worth having. Each equation is a line on a graph of s against g. A solution is a point on both lines at once, where they cross.

Two equations are two lines; the solution is where they cross
Green smoothies (g) 10 20 Bananas: 2s + g = 40 Berries: s + 3g = 70 s = 10, g = 20 Strawberry smoothies (s) Green smoothies (g) 10 20 Bananas: 2s + g = 40 Berries: s + 3g = 70 s = 10, g = 20 Strawberry smoothies (s)

Why we need a method

You could solve this by substitution: from the first equation g = 40 − 2s; put that into the second, s + 3(40 − 2s) = 70, so s + 120 − 6s = 70, and −5s = −50, so s = 10. Then g = 40 − 20 = 20. Check the berries: 10 + 60 = 70. It works.

Substitution is fine for two unknowns, but it gets tangled fast. Row reduction organizes the same steps so cleanly that a computer can do them. It is the standard method in every statistics and economics package.

Write the system as an augmented matrix: the matrix A with the column b stuck on the right, separated by a bar.

[ 2  1 | 40 ]
[ 1  3 | 70 ]

Each row stands for one equation. There are exactly three moves that change how the system looks but not what its solutions are:

  1. Swap two rows. (Reordering equations changes nothing.)
  2. Scale a row: multiply every entry in it by a nonzero number. (Doubling both sides of an equation changes nothing.)
  3. Add a multiple of one row to another. (If two things are true, so is their sum.)

The goal is to use these moves to create zeros below the diagonal, giving a staircase shape called echelon form. Then the last equation has one unknown, which you solve first and work upward.

For Maya's system: the second row is replaced by 2 × (row 2) − (row 1). Two times row 2 is (2, 6 | 140). Subtract row 1, (2, 1 | 40), to get (0, 5 | 100). Now the system is:

[ 2  1 |  40 ]
[ 0  5 | 100 ]

The bottom row says 5g = 100, so g = 20. Back-substitute into the top: 2s + 20 = 40, so s = 10. Maya makes 10 strawberry and 20 green smoothies, matching the graph.

A worked example with three unknowns

Three unknowns, x, y, z, show how the method scales. Take

 x +  y +  z = 6
2x −  y +  z = 3
 x + 2y −  z = 2

The augmented matrix has rows (1, 1, 1 | 6), (2, −1, 1 | 3) and (1, 2, −1 | 2). Work column by column.

Step 1: clear the first column. Replace row 2 by row 2 − 2 × row 1: (2 − 2, −1 − 2, 1 − 2 | 3 − 12) = (0, −3, −1 | −9). Replace row 3 by row 3 − row 1: (0, 1, −2 | −4).

[ 1   1   1 |  6 ]
[ 0  −3  −1 | −9 ]
[ 0   1  −2 | −4 ]

Step 2: clear the second column below the diagonal. Replace row 2 by row 2 + 3 × row 3: (0, −3 + 3, −1 − 6 | −9 − 12) = (0, 0, −7 | −21).

[ 1  1   1 |   6 ]
[ 0  0  −7 | −21 ]
[ 0  1  −2 |  −4 ]

Swap rows 2 and 3 to complete the staircase:

[ 1  1   1 |   6 ]
[ 0  1  −2 |  −4 ]
[ 0  0  −7 | −21 ]

Step 3: back-substitute. The bottom row gives −7z = −21, so z = 3. The middle row: y − 2 × 3 = −4, so y = 2. The top row: x + 2 + 3 = 6, so x = 1.

Check all three original equations: 1 + 2 + 3 = 6 ✓; 2 − 2 + 3 = 3 ✓; 1 + 4 − 3 = 2 ✓. Always check. A slip in arithmetic is the main way this method fails.

Gaussian elimination in four moves
1 Augment Write A and b side by side as one table. 2 Clear below Use row operations to make zeros under each leading number. 3 Read the staircase The last row now has a single unknown. 4 Back-substitute Solve upward from the bottom, then check in the originals. Augment Write A and b side by side as one table. 1 Clear below Use row operations to make zeros under each leading number. 2 Read the staircase The last row now has a single unknown. 3 Back-substitute Solve upward from the bottom, then check in the originals. 4

It helps to see why you can trust each move, rather than just obey it. Suppose a point (s, g) satisfies both of Maya's equations. Then it satisfies any equation made by combining them: if 2s + g is 40 and s + 3g is 70, then 2 × (s + 3g) − (2s + g) must be 2 × 70 − 40 = 100, which simplifies to 5g = 100. So every old solution is a solution of the new system.

The reverse also holds. The moves can be undone: if you replaced row 2 by 2 × row 2 − row 1, you can recover row 2 by adding row 1 back and halving. Since you can go back and forth, the old and new systems have exactly the same solutions. That is why scaling by zero is forbidden. It cannot be undone, and it would throw away an equation.

Each move is also cheap to carry out by hand and easy for a computer to repeat. A system with 100 unknowns needs about a third of a million of these little steps, which a laptop finishes in a blink. That is the real reason matrices matter to economists: models with many markets are practical because the method is mechanical.

When there is no answer, or too many

Not every system behaves. Row reduction tells you which case you are in.

  • One solution. Every column has a leading number, as above. The lines cross at one point.
  • No solution. Take x + y = 2 and x + y = 3. Subtract the first row from the second and you get 0 = 1, which is false. The lines are parallel and never meet. In economics: two conditions that cannot both hold, such as a market clearing at two different prices.
  • Infinitely many solutions. Take x + y = 2 and 2x + 2y = 4. The second is just twice the first, and subtracting gives 0 = 0, which is true but empty. Any point on the line works. Here the equations repeat each other, and you have one equation short of pinning down both unknowns.

Whenever row reduction ends with a row of zeros on the left of the bar, ask what is on the right. If it is a nonzero number, there is no solution. If it is zero, there is a free choice somewhere.

The three possible outcomes of a linear system
One solution Lines cross at a single point Every unknown can be found Example: 2s + g = 40, s + 3g = 70 No solution Lines are parallel Row reduction ends in 0 = 1 Example: x + y = 2 and x + y = 3 Many solutions Lines lie on top of each other Row reduction ends in 0 = 0 Example: x + y = 2 and 2x + 2y = 4 One solution Lines cross at a single point Every unknown can be found Example: 2s + g = 40, s + 3g = 70 No solution Lines are parallel Row reduction ends in 0 = 1 Example: x + y = 2 and x + y = 3 Many solutions Lines lie on top of each other Row reduction ends in 0 = 0 Example: x + y = 2 and 2x + 2y = 4

A rule of thumb: you need at least as many independent equations as unknowns. "Independent" means no equation is a combination of the others. The next lesson, Determinants, Inverses and Cramer's Rule, gives a single number, the determinant, that tests for this at once.

Where economists meet linear systems

A market model with three goods, each with a linear supply and demand curve, becomes a 3 × 3 system in the three prices. Setting excess demand to zero in every market gives equations just like these. Input-output analysis asks how much each industry must produce so that its output covers both final demand and other industries' needs; that too is a linear system, with one equation per industry. Regression estimates, which you may meet in statistics, come from a system called the normal equations. And the first-order conditions of a quadratic optimization problem, like those in Unconstrained Optimization With Several Variables, are linear in the unknowns.

A common mistake: operating on only part of a row

The most frequent error is applying a row operation to the left of the bar and forgetting the right. If you multiply row 2 by 2, the entry in the b column doubles too. Doing only half of it quietly changes the equation and produces a wrong answer that still looks tidy.

A related slip: subtracting rows in the wrong direction and losing a sign. Write each operation next to the row, like "R2 ← R2 − 2R1," so you can retrace your steps.

A third is dividing by something that might be zero. You may only scale a row by a nonzero number. If the number in the spot you want to use as a pivot is zero, swap in a row that has a nonzero number there.

Words to know

Linear system a set of equations where every unknown appears only to the first power and is never multiplied by another unknown.

Augmented matrix the coefficient matrix with the right-hand side placed beside it as an extra column.

Row operation swapping two rows, scaling a row by a nonzero number, or adding a multiple of one row to another.

Echelon form the staircase shape, with zeros below each leading entry, that row reduction aims for.

Gaussian elimination the method of using row operations to reach echelon form and then back-substituting.

Back-substitution solving from the last equation upward, using each answer in the row above.

Consistent system a system with at least one solution.

Check yourself

  1. Write the system 3x + y = 11 and x + 2y = 7 as Ax = b, naming A, x and b.
  2. Solve that system with row operations and check your answer in both equations.
  3. Maya has 60 bananas and 90 cups of berries, with the same recipes as the lesson (2 and 1 for strawberry; 1 and 3 for green). Set up the system and find how many of each she can make.
  4. Row reduction of a system ends with a row (0, 0 | 5). What does that tell you?
  5. Row reduction ends with a row (0, 0 | 0). What does that tell you, and what could be true about the original equations?
  6. Explain why swapping two equations cannot change the solutions of a system.
Show the answers
  1. A has rows (3, 1) and (1, 2); x = (x, y); b = (11, 7).
  2. Replace R2 by 3 × R2 − R1: (3, 6 | 21) − (3, 1 | 11) = (0, 5 | 10), so y = 2; then 3x + 2 = 11, so x = 3. Check: 9 + 2 = 11 and 3 + 4 = 7.
  3. 2s + g = 60 and s + 3g = 90. Replace R2 by 2 × R2 − R1: (0, 5 | 120), so g = 24; then 2s = 60 − 24 = 36, so s = 18. Check: 18 + 72 = 90.
  4. It says 0 = 5, which is false, so the system has no solution.
  5. It says 0 = 0, which is always true, so one equation was redundant (a copy or combination of the others) and there are infinitely many solutions if the system is otherwise consistent.
  6. The solutions are the points that satisfy every equation at once, and the order in which you list the equations does not change which points satisfy them all.

A free self-study program written for 4Economics with AI writing tools and not reviewed line by line by a person. It is not an accredited degree and awards no credit. Check anything you rely on against a textbook or primary source. Report an error.

In this unit: Matrices and dynamics

  1. Vectors and MatricesVectors and matrices let you handle dozens of prices, quantities and equations as single objects.11 min
  2. Solving Linear Systems With MatricesWrite several equations as one matrix equation Ax = b, then solve it by methodical row operations.10 min
  3. Determinants, Inverses and Cramer's RuleThe determinant tests whether a matrix can be undone, and the inverse and Cramer's rule solve systems directly.10 min
  4. Eigenvalues Without FearEigenvalues are the stretch factors of a matrix along special directions, and they decide whether a system settles down.10 min
  5. Integration and Consumer SurplusIntegrals add up a curve's height over a range, which is how economists measure consumer and producer surplus.10 min
  6. Difference Equations and the Cobweb ModelA difference equation links this period to the last, and the cobweb model shows prices that spiral in or out.11 min
  7. Differential Equations for Growth ModelsA differential equation ties a quantity's speed to its size, and solving it reveals growth paths and steady states.11 min
  8. Dynamic Choice: A First Look at Optimizing Over TimeOptimizing over time links today's choice to tomorrow's, and the Euler equation says how to trade them off.10 min

In the news