System of linear equations solver with step-by-step working
Type a system, and the solver finds the answer by substitution, elimination, Cramer’s rule or Gaussian elimination, explains every step and draws the lines or planes.
2x + 3y = 7; x - y = 1
3x - 2y = 4; 5x + 3y = 13 by Cramer's rule
x + y + z = 6; x - y + z = 2; 2x + y - z = 1
x + 2y = 3; 2x + 4y = 5
x + y + z = 1; x - y + 2z = 3
x + y = 5; xy = 6
Loading the solver…
What you can type
Separate the equations with semicolons or put each on its own line: 2x + 3y = 7; x - y = 1. The solver treats every letter it meets as an unknown: x, y, z, a, b, and for bigger systems x1, x2, x3 are handy. Coefficients can be integers, fractions (x/2 + y/3 = 2) or decimals (0.5x + 1.2y = 3); brackets are expanded automatically. The limit is eight equations in eight unknowns.
Choose the method with the buttons under the field or in words in the input itself: “by Cramer’s rule”, “by Gaussian elimination”, “by substitution”, “by elimination”. If you choose nothing, the solver does what a careful student would: it solves a 2 × 2 system by substitution if one of the unknowns has a coefficient of one, otherwise by elimination, and anything bigger by Gaussian elimination. It can also solve a pair made of a linear and a non-linear equation, such as x + y = 5; xy = 6.
Four methods and when to use which
Substitution
From one equation, express one unknown in terms of the other and substitute that expression into the second equation. What’s left is an equation in one unknown, which we already know how to solve. Substitute the number you find back and you get the second unknown. It’s best to express the letter whose coefficient is $1$ or $-1$: then no fractions appear. In the system $2x + 3y = 7$, $x - y = 1$ the obvious move is $x = y + 1$.
Elimination
If the left and right sides of two equalities are equal, so are their sums. Multiply the equations by numbers that make the coefficients of one unknown opposite, and add: that unknown disappears. In the system $3x - 2y = 4$, $5x + 3y = 13$, multiply the first equation by $3$ and the second by $2$: this gives $9x - 6y = 12$ and $10x + 6y = 26$, and adding them gives $19x = 38$, that is, $x = 2$. This method is good when no unknown has a coefficient of one and substitution would drag fractions along.
Cramer’s rule
The answer is written straight away in terms of determinants. Gabriel Cramer published the rule in 1750, and for a 2 × 2 or 3 × 3 system it is the shortest route: compute three or four determinants and divide. But as the system grows there are more and more determinants, and each is more and more expensive to compute, so large systems aren’t solved this way.
Where the formula comes from is clear from elimination. Multiply the first equation by $b_2$ and the second by $b_1$, and subtract: $y$ disappears, and what’s left is $(a_1 b_2 - a_2 b_1)x = c_1 b_2 - c_2 b_1$, that is, $\Delta \cdot x = \Delta_x$. Cramer’s rule is elimination done once and for all in general form.
Gaussian elimination
The main method for anything bigger than 2 × 2. Write the coefficients and the right-hand sides in a table, the augmented matrix. Three operations on the rows are allowed: swap two rows, multiply a row by a non-zero number, and add to a row another row multiplied by a number. These are exactly the operations you can perform on equations, so the solutions of the system don’t change. First make everything below the diagonal zero, which gives a “staircase”, the row echelon form. Then clear the entries above the leading elements too, and the answer can be read off the last column.
The method is named after Gauss, who used it in 1809 to compute the orbits of celestial bodies. But the table method of eliminating unknowns is already described in the Chinese treatise “The Nine Chapters on the Mathematical Art”, which is about two thousand years old. Computers solve systems this way too: a system of $n$ equations takes about $\frac{2}{3}n^3$ arithmetic operations, while Cramer’s rule with honestly computed determinants needs incomparably more.
Why there’s one solution, none, or infinitely many
An equation in two unknowns defines a line in the plane, and a solution of the system is a point common to both lines. Two lines either cross at one point, are parallel, or coincide. There are no other options, so a 2 × 2 system has exactly one solution, none, or infinitely many. The picture in the solver shows which case you have.
You can tell from the coefficients without a drawing. If $\Delta \ne 0$, there is one solution. If $\Delta = 0$, the lines are parallel or coincide: the coefficients of the unknowns are proportional. When the right-hand sides are proportional too, one equation is a multiple of the other, and there are infinitely many solutions. When they aren’t, a false equality like $0 = 5$ turns up along the way, and there are no solutions.
With three unknowns, an equation is a plane in space. Three planes usually meet at one point, but they can share a common line (then there are infinitely many solutions) or have no common point at all. In Gaussian elimination these cases are told apart by the number of leading elements, the rank of the matrix: if it equals the number of unknowns, the solution is unique; if it is smaller, free unknowns appear; and a row of the form $0 = b$ with $b \ne 0$ means there are no solutions. This is the Rouché–Capelli theorem (some textbooks call it the Kronecker–Capelli theorem).
Worked examples
Example 1. By substitution: $2x + 3y = 7$, $x - y = 1$
From the second equation, $x = y + 1$. Substitute into the first: $2(y + 1) + 3y = 7$, that is, $5y + 2 = 7$, $y = 1$. Then $x = 1 + 1 = 2$.
Check: $2 \cdot 2 + 3 \cdot 1 = 7$ and $2 - 1 = 1$. Answer: $(2, 1)$. In the picture it’s the point where the lines $y = \frac{7 - 2x}{3}$ and $y = x - 1$ cross.
Example 2. By Gaussian elimination: $x + y + z = 6$, $x - y + z = 2$, $2x + y - z = 1$
The augmented matrix and the first two steps: subtract the first row from the second, and twice the first row from the third:
$$\left(\begin{array}{ccc|c} 1 & 1 & 1 & 6 \\ 1 & -1 & 1 & 2 \\ 2 & 1 & -1 & 1 \end{array}\right) \to \left(\begin{array}{ccc|c} 1 & 1 & 1 & 6 \\ 0 & -2 & 0 & -4 \\ 0 & -1 & -3 & -11 \end{array}\right).$$
The second row says $-2y = -4$, that is, $y = 2$. The third: $-y - 3z = -11$, so $3z = 9$, $z = 3$. From the first: $x = 6 - 2 - 3 = 1$. Answer: $(1, 2, 3)$. Check in the third equation: $2 \cdot 1 + 2 - 3 = 1$.
Example 3. No solutions: $x + 2y = 3$, $2x + 4y = 5$
Multiply the first equation by $2$: $2x + 4y = 6$. Subtract it from the second: $0 = -1$. That can’t happen for any $x$ and $y$, so there are no solutions. Geometrically, the lines $x + 2y = 3$ and $2x + 4y = 5$ are parallel: they have the same slope but cross the axes at different points. The main determinant is $1 \cdot 4 - 2 \cdot 2 = 0$, so this system can’t be solved by Cramer’s rule.
Example 4. Infinitely many solutions: $x + y + z = 1$, $x - y + 2z = 3$
There are two equations and three unknowns, so one unknown will have to stay free. Subtract the first equation from the second: $-2y + z = 2$, so $y = \frac{z}{2} - 1$. From the first, $x = 1 - y - z = 2 - \frac{3z}{2}$. Write $z = t$:
$$(x, y, z) = \left(2 - \tfrac{3t}{2},\ -1 + \tfrac{t}{2},\ t\right),\quad t \in \mathbb{R}.$$
At $t = 0$ we get the solution $(2, -1, 0)$, and at $t = 2$ the solution $(-1, 0, 2)$; both satisfy both equations. The two planes meet in a line, and every point of it is a solution.
Common mistakes
- Losing a sign when moving a term across. $x - y = 1$ gives $x = y + 1$, not $x = y - 1$. A term moved across the equals sign changes its sign.
- Substituting into the same equation you rearranged. You get an identity like $y + 1 - y = 1$, and it looks as if there are infinitely many solutions. Substitute into the other equation.
- Multiplying only the left-hand side by a number. If the first equation is multiplied by $3$, its right-hand side is multiplied by $3$ too.
- Mixing up the diagonals in a determinant. $\begin{vmatrix} a & b \\ c & d \end{vmatrix} = ad - bc$: the product of the main diagonal minus the product of the other one, not the other way round.
- Dividing by zero in Cramer’s rule. When $\Delta = 0$ the formulas don’t work, and it’s too early to conclude “no solutions”: there may be infinitely many. Sort it out by Gaussian elimination.
- Swapping columns in Gaussian elimination. It’s rows you may swap. Swapping columns changes the order of the unknowns, and that’s easy to forget when you read off the answer.
- Not checking the answer. Substituting the numbers into each equation takes half a minute and catches almost any arithmetic slip. The solver always does it.
See also
Two lines, a factory with limited resources and linear programming are in the chapter on systems of equations and inequalities. Gaussian elimination in full, rank, the Rouché–Capelli theorem and three planes in space are in the chapter on Gaussian elimination. Determinants, inverse matrices and rank are computed by the matrix solver, a single equation in one unknown by the linear equation solver, and if substitution leaves you with a quadratic equation, go to the quadratic equation solver.
Where this is explained
Other solvers
- Quadratic equation
- Linear equation
- Higher-degree equations and factoring
- Inequalities by the interval method
- Derivative
- Integral
- Limit
- Curve sketching
- Fraction arithmetic
- GCD, LCM and Euclid's algorithm
- Prime factorisation
- Solving a triangle
- Matrices: determinant, inverse, rank, eigenvalues
- Trigonometric equation
- Exponential and logarithmic equations
- Percentages, compound interest, loans
- Permutations and combinations
- Number bases
- Complex numbers
- Congruences
- Progressions
- Probability: Bayes and Bernoulli trials
- Differential equation