MathsAlgebra

Systems of Equations Solver
2×2.

Find the values that fit two or three linear equations at the same time.

How it's worked out

Each linear equation in x and y is a straight line of points that make it true. A system asks which point lies on every line at once. There are three methods here, and when a single answer exists, all three reach it.

Cramer's rule

Write the two equations with x and y on the left. The determinant D is one number built from the coefficients. Then DxD_x and DyD_y are the same determinant, with the right sides swapped into the x column or the y column.

a1x+b1y\displaystyle a_1 x + b_1 y=c1\displaystyle {}= c_1
a2x+b2y\displaystyle a_2 x + b_2 y=c2\displaystyle {}= c_2
D\displaystyle D=a1b2−b1a2\displaystyle {}= a_1 b_2 - b_1 a_2
x\displaystyle x=DxD\displaystyle {}= \frac{D_x}{D}
y\displaystyle y=DyD\displaystyle {}= \frac{D_y}{D}

Three equations work the same way with larger determinants, and a DzD_z as well. The rule needs D to be something other than 0. When D is 0 it can tell you there is no single answer, but it cannot say which of the other two cases you have, so elimination has to decide.

Elimination

Write the numbers as a grid and use three moves on its rows: swap two rows, multiply a row by a number, or add a multiple of one row to another. None of these changes the solution. You keep going until each unknown stands alone, and the last column then holds the answers. A row that reads 0 = 5 means no solution, and a row of all zeros means one unknown is free.

Substitution

Solve one equation for one unknown and put that into the other equation, which leaves one unknown to find. This is easiest when a coefficient is 1 or −1, so the solver looks for one of those first. In the exact view the numbers stay as fractions in all three methods, so rounding never creeps into the working.

Worked examples

A theater counts its tickets

A theater sold 120 tickets, some at $8 and some at $5, and took in $780. Let x be the $8 tickets and y the $5 tickets. One fact counts tickets and one counts money, which gives x + y = 120 and 8x + 5y = 780.

The first equation has coefficients of 1, so substitution suits it: x=120−yx = 120 - y. Putting that in leaves −3y=−180-3y = -180, so y = 60 and x = 60. Check it the way the box office would: 60 tickets at $8 plus 60 at $5 is $780.

Open this example in the tool

Dana mixes two solutions

Dana needs 10 L of a 25% solution and has a 10% and a 40% stock. Let x and y be the liters of each. The volumes add to 10, and the pure substance adds to 25% of 10, which is 2.5 L. That gives x + y = 10 and 0.1x + 0.4y = 2.5.

The answer is 5 L of each. That makes sense, because 25% sits exactly halfway between 10% and 40%. If she wanted a target nearer one stock, she would need more of that stock.

Open this example in the tool

Sam works out prices from three receipts

Sam has three receipts from a cafe: one coffee, one muffin and one sandwich for $12; two coffees, three muffins and a sandwich for $19; and one coffee, one muffin and two sandwiches for $19. With x, y and z as the three prices, each receipt is one equation.

The determinant is 1, so there is one answer: the coffee is $3, the muffin is $2 and the sandwich is $7. You can spot the sandwich straight away, since the first and third receipts differ by one sandwich and $7.

Open this example in the tool

Reading your result

Every system lands in one of three cases. The determinant D separates the first case from the other two, and elimination separates those two from each other.

The three cases, using the same first equation
SystemDResult
x + 2y = 4; 3x − y = 5−7Lines cross once, at (2, 1)
x + 2y = 4; 2x + 4y = 30Parallel lines, no solution
x + 2y = 4; 2x + 4y = 80The same line, infinitely many

In the last row the second equation is just twice the first, so it adds nothing new. Any point on the line works, and you write the answer with y free: x=4−2yx = 4 - 2y. Pick any y and that gives you the x to go with it.

The right sides tell you how firm an answer is. For the steady pair x + y = 2 and x − y = 0, adding 1 to a right side moves x by only 0.5. For the nearly parallel pair x + y = 2 and x + 1.001y = 3, adding 1 to the second right side moves y by 1,000. If your numbers came from measurements, an answer like that is not one to trust.

Exact fractions help you compare with a textbook. The answer to 2x + y = 1 and x + 2y = 1 is x=13x = \frac{1}{3} and y=13y = \frac{1}{3}. As a decimal that is about 0.333333, which can only ever be close.

Common mistakes

  • Leaving an equation unsorted. Before you read off coefficients, move the x and y terms to the left and the number to the right. In y=3x+2y = 3x + 2, the x coefficient is −3 and the y coefficient is 1, with 2 on the right.
  • Skipping a zero. An equation such as 2x=62x = 6 has a y coefficient of 0, and that 0 still has to be entered. Its line is vertical, at x = 3.
  • Mixing up the columns in Cramer's rule. For DxD_x the right sides replace the x column, not the y column. Swapping them gives you y over D, and then the two answers trade places.
  • Calling D = 0 "no solution". D = 0 only means there is no single solution. Parallel lines have no solution and a repeated line has infinitely many, and both of those give D = 0.
  • Stopping before the check. Put your answer back into every equation, not just the one you used last. An answer that fits only one of them points to a slip in the arithmetic.

Questions people ask

It stops working when the determinant D is 0, because every answer is a division by D. That does not mean the system is unsolvable. It means the system has no single answer, and elimination will show whether it has none or infinitely many.

Sources