What is this tool for?
A system of linear equations is a group of equations that must all be true at the same time, where each unknown is only multiplied by a number. It appears whenever several conditions involve the same quantities: currents in an electric circuit, amounts in a mixture, balancing a chemical reaction, or fitting a line through measurements.
This tool solves the system with the method you choose and shows every operation. If you are a student, compare the method from class with your own working and check each operation. If you are a researcher, you get exact answers, rank analysis, and least squares when the data allow no exact solution.
The calculation runs in your browser, without sending your numbers to a server, and stays exact in fractions: 1/3 stays 1/3 until the last step. Results are indicative and do not replace your own review of the problem.
How to use it
- Set the number of equations and unknowns. Each row of the grid is one equation: the coefficients of x₁, x₂ and so on, then the right-hand side b after the bar.
- Write 0 for a missing unknown. So 2x − z = 5 becomes 2, 0, −1 and then 5 in column b. Fractions and decimals are accepted.
- Pick the method your course asks for. The result says whether there is one solution, none or infinitely many, and the step-by-step solution shows every operation.
How it is calculated
Ri ↔ Rj
Ri ← k · Ri (k ≠ 0)
Ri ← Ri + k · Rj (i ≠ j)
rank(A) ≠ rank(A|b): no solution
rank(A) = rank(A|b) = n: one solution
rank(A) = rank(A|b) < n: infinitely many solutions
Any system can be written A·x = b: the matrix A holds the coefficients, with one row per equation and one column per unknown, x holds the unknowns and b the right-hand sides. The augmented matrix [A | b] places b beside A: it is the grid you fill in.
Three row operations leave the solutions unchanged: swapping two rows, multiplying a row by a non-zero number, and adding a multiple of one row to another. The page works column by column: it chooses a pivot, which is a non-zero number, and uses it to create zeros.
The outcome is then read from the reduced rows. The rank is the number of pivots. A row that reads 0 = a non-zero value is impossible: rank(A|b) then exceeds rank(A), and there is no solution. If both ranks equal the number of unknowns n, the solution is unique. If they are equal but smaller than n, the columns without a pivot give free unknowns and infinitely many solutions.
Worked examples
Example 1: the default system, by Gaussian elimination
- The system is 2x + y − z = 8, −3x − y + 2z = −11 and −2x + y + 2z = −3. The rows of [A | b] are (2, 1, −1, 8), (−3, −1, 2, −11) and (−2, 1, 2, −3).
- Column 1, pivot 2: R₂ ← R₂ + (3/2)·R₁ and R₃ ← R₃ + R₁ give the rows (0, 1/2, 1/2, 1) and (0, 2, 1, 5).
- Column 2, pivot 1/2: R₃ ← R₃ − 4·R₂ gives the last row (0, 0, −1, 1).
- Back substitution starts from the last row: x₃ = 1 / (−1) = −1.
- The second row gives x₂ = (1 − (1/2)·(−1)) / (1/2) = 3.
- The first row gives x₁ = (8 − 1·3 − (−1)·(−1)) / 2 = 2.
- Check in the first equation: 2·2 + 3 − (−1) = 8.
x = 2, y = 3 and z = −1, shown on the page as x₁ = 2, x₂ = 3 and x₃ = −1. The system has one solution.
Example 2: a line through 4 points, by least squares
- Find the line y = x₁ + x₂·t closest to (1, 6), (2, 5), (3, 7) and (4, 10), with x₁ the intercept, meaning the value of y at t = 0, and x₂ the slope.
- Enter 4 equations and 2 unknowns: the rows of A are (1, 1), (1, 2), (1, 3) and (1, 4), and b = (6, 5, 7, 10). The points are not on one line: rank(A) = 2 and rank(A|b) = 3.
- Normal equations: Aᵀ · A has the rows (4, 10) and (10, 30), and Aᵀ · b is (28, 77).
- Column 1: R₁ ← (1/4)·R₁ and R₂ ← R₂ − 10·R₁ give the rows (1, 5/2, 7) and (0, 5, 7).
- Column 2: R₂ ← (1/5)·R₂ and R₁ ← R₁ − (5/2)·R₂ give the rows (1, 0, 7/2) and (0, 1, 7/5).
- The gaps b − A·x are 11/10, −13/10, −7/10 and 9/10, and the sum of their squares is 420/100 = 21/5.
Intercept x₁ = 7/2, slope x₂ = 7/5 and residual 21/5. The line is y = 7/2 + (7/5)·t, which is y = 3.5 + 1.4·t.
Each method explained
Gaussian elimination
The general method and the default choice: it suits any system, square or not, however many solutions it has.
Row operations create zeros below each pivot until the matrix reaches row echelon form. If the solution is unique, back substitution then gives the unknowns, from last to first.
For 2x + y = 5 and x − y = 1, R₂ ← R₂ − (1/2)·R₁ gives (0, −3/2, −3/2), so x₂ = 1, then x₁ = (5 − 1·1) / 2 = 2.
Gauss–Jordan elimination
For reading the answer directly, without back substitution, or for getting the general form when there are free unknowns.
Each pivot is scaled to 1, then zeros are created both below and above it, up to the reduced row echelon form, which is unique.
The same system reduces to the rows (1, 0, 2) and (0, 1, 1), so x₁ = 2 and x₂ = 1.
Cramer's rule
A direct formula, handy when there are few unknowns. It needs as many equations as unknowns and a non-zero determinant.
For each unknown, replace its column with b to get Aᵢ, then calculate xᵢ = det(Aᵢ) / det(A). The determinant calculator lets you check each determinant.
For the same system, det(A) = −3, det(A₁) = −6 and det(A₂) = −3, so x₁ = (−6) / (−3) = 2 and x₂ = (−3) / (−3) = 1.
Inverse matrix
Useful when A stays the same and b changes, because one inverse serves every right-hand side. A must be square and invertible.
The page reduces [A | I], where I is the identity matrix, until it reaches [I | A⁻¹], then calculates x = A⁻¹ · b. The matrix calculator also handles the inverse alone.
For the same system, A⁻¹ has the rows (1/3, 1/3) and (1/3, −2/3), which gives x₁ = 2 and x₂ = 1.
Montante's method (Bareiss)
For courses that ask for it, or to avoid fractions when the coefficients are whole numbers. It needs as many equations as unknowns and also gives the determinant.
Each cell outside the pivot row becomes (pivot × cell − cell in the pivot column × cell in the pivot row) / previous pivot, the first previous pivot being 1. With whole numbers, every division is exact. At the end, the last pivot fills the diagonal: it gives the determinant, up to the sign of the swaps, and the right-hand side is divided by that pivot.
For the same system, the first pivot, 2, gives (0, −3, −3) as the second row. The second pivot, −3, with 2 as the previous pivot, gives (−3, 0, −6) and (0, −3, −3). So det(A) = −3, x₁ = 2 and x₂ = 1.
Linear least squares
For when there are too many equations for an exact answer, as with noisy measurements. It gives the best compromise, not a solution of every equation.
The page multiplies A·x = b by the transpose of A, which gives the normal equations Aᵀ · A · x = Aᵀ · b, always consistent. Their solution makes the residual as small as possible, and the page shows that residual. If the columns of A are dependent, several x give the same residual, and the page shows the general form.
On the default system, which has an exact solution, it finds x₁ = 2, x₂ = 3, x₃ = −1 and a residual of 0. For the line in example 2, the residual is 21/5.
Test for compatibility
For finding out whether a system has solutions and how many, with the full rank analysis. Compatible means that the equations do not contradict each other.
The page reduces [A | b], counts the pivots, then compares rank(A), rank(A|b) and n using the Rouché–Capelli theorem. It then writes the solution or the general form, if there is one.
For x + y + 2z = 3, x + y + z = 1 and 2x + 2y + 2z = 5, rank(A) = 2 and rank(A|b) = 3, because one row reads 0 = 3: no solution. If the last right-hand side becomes 2, both ranks are 2 for n = 3: infinitely many solutions, with x₁ = −1 − x₂, x₃ = 2 and x₂ free.
Names and notation
- Linear: each unknown appears alone, to the power 1, with no x² and no product x·y. The word comes from the Latin linea, a line, because an equation in 2 unknowns draws a straight line.
- Unknown: the value you are looking for. The habit of writing unknowns as x, y and z goes back to Descartes, in La Géométrie, published in 1637.
- x₁, x₂: numbered unknowns, because letters run out quickly. x₁ replaces x, x₂ replaces y, and so on up to x₁₀.
- Coefficient: the number multiplying an unknown. The word comes from Latin and suggests something acting together with something else.
- Right-hand side b: what stays to the right of the equals sign, with the unknowns on the left. An equation has two sides, one on each side of that sign.
- Augmented matrix [A | b]: the matrix A enlarged with the column b. The bar only marks where the coefficients end.
- Free unknown: an unknown whose column has no pivot. No row fixes its value, hence the word free.
- Rank, rank(A): the number of pivots. The working lines write rank(A) in all three languages, from the English word.
- R₂ ← R₂ − 3·R₁: row 2 is replaced by row 2 minus 3 times row 1. The French and Arabic pages write L, for the French word ligne, and the English page writes R, for row.
- Gauss: Carl Friedrich Gauss, a German mathematician. The method is much older, though: the Chinese text The Nine Chapters on the Mathematical Art already describes it.
- Jordan: Wilhelm Jordan, a German geodesist, who used this full reduction in a handbook on surveying. Do not confuse him with Camille Jordan, of the Jordan form used for eigenvalues.
- Cramer: Gabriel Cramer, a mathematician from Geneva, who published his rule in 1750.
- Montante and Bareiss: René Mario Montante Pardo developed his method in Mexico, at the Autonomous University of Nuevo León, and Erwin Bareiss published a fraction-free elimination algorithm in 1968. Both rely on exact division by the previous pivot.
- Rouché and Capelli: the Frenchman Eugène Rouché and the Italian Alfredo Capelli. In some countries the theorem has other names, such as Kronecker–Capelli.
- Least squares: the sum of the squared gaps is as small as possible. Adrien-Marie Legendre published the method in 1805, then Gauss in 1809, saying he had used it for longer.
- Residual ‖b − A·x‖²: the double bars mean the length of a vector, and squaring gives the sum of the squared gaps.
Tips and limitations
- The Example button reloads the default system, which lets you see a filled grid.
- Try two methods on the same system: the intermediate rows can differ, but the answer stays the same.
- Switch Display to Decimals or Significant digits to read rounded values: only the display changes.
- You can paste a table from a spreadsheet, with b in the last column. Scientific notation such as 1.2e-4 is accepted.
- The limit is 10 equations and 10 unknowns, in real numbers. Complex numbers and letters such as a or k are not accepted: for a parameter, repeat the calculation for each value you choose.
Mistakes to avoid
- Forgetting the 0 for a missing unknown: with 3 unknowns, x + z = 4 is written 1, 0, 1 and then 4. If you shift the numbers to the left, you solve a different system.
- Getting a sign wrong: in −3x − y + 2z = −11, the coefficient of y is −1. First move all the unknowns to the left, changing the sign of anything that crosses the equals sign.
- Mixing up the order of the unknowns: y + 2x = 5 is written 2, 1 and then 5, because each column keeps the same unknown in every row.
- Taking a least squares answer for an exact solution: if the residual is not 0, some equations are not satisfied.
Frequently asked questions
How do I know if a system has a solution?
Compare the rank of A with the rank of the augmented matrix [A|b]. If they differ, there is no solution. If they both equal the number of unknowns, the solution is unique. If they are equal but smaller, there are infinitely many solutions. This is the Rouché–Capelli theorem, and the test for compatibility applies it in full.
Which method should I choose?
They all give the same answer whenever they apply. Gauss works almost every time. Gauss–Jordan avoids the back substitution at the end. Cramer is clear with 2 or 3 unknowns but gets heavy after that. Montante keeps whole numbers. Least squares is for when there are too many equations for an exact answer, such as fitting a line through measurements.
What is a free unknown?
It is an unknown that can take any value. The others are then written in terms of it, for example x₁ = 3 − 2x₂ with x₂ free. Each value you pick gives a different solution, which is why there are infinitely many. The calculator shows this general form.
What should I do when there are more equations than unknowns?
Start with the test for compatibility. If the equations agree, Gauss or Gauss–Jordan gives the answer. If the ranks show no solution, which is common with measurements, choose least squares. Cramer, the inverse and Montante need as many equations as unknowns, so the page says so and answers from the ranks.
Why does Cramer's rule fail when the determinant is 0?
It divides by det(A), and dividing by 0 is impossible. A zero determinant means the system has no unique solution: it has none or infinitely many. The page says that the rule does not apply, then answers from the ranks, with the label “Method not possible here: answer from the ranks”. The inverse and Montante do the same.
What does the residual mean?
It measures what is missing to satisfy every equation: it is the sum of the squares of the gaps between b and A·x. If it is 0, the answer is an exact solution. Otherwise, it is mainly useful for comparing fits on the same data, because its size depends on the units used.