System of linear equations solver

Solve 2 to 5 simultaneous linear equations exactly by Gauss–Jordan elimination, with every row operation shown, and detect no-solution or infinite cases.

Drafted with AI writing toolsUpdated Checked examples: 5

One equation per line: the coefficients, then the constant. 2 1 -1 8 means 2x + y − z = 8. A | or = before the constant is fine; fractions like 1/2 work.
Try
Solution
x = 2, y = 3, z = −1
Solution: x = 2, y = 3, z = −1
Type of system
Unique solution
x₁ (x)
2
x₂ (y)
3
x₃ (z)
−1
Determinant of the coefficients
−1
Condition number (∞-norm)
60

The 3 equations meet at exactly one point: x = 2, y = 3, z = −1. The determinant is −1, which is non-zero, so the solution is unique.

Solution values

x2y3z−1
How it's calculated S
  1. Augmented matrix

    [A∣b]=[21−18−3−12−11−212−3]\left[A \mid \mathbf b\right] = \left[\begin{array}{ccc|c}2 & 1 & -1 & 8 \\ -3 & -1 & 2 & -11 \\ -2 & 1 & 2 & -3\end{array}\right]

    Unknowns: x, y, z.

  2. Column 1: make the pivot 1 and clear the rest of the column

    R1←12 R1, R2←R2+3R1, R3←R3+2R1  ⟶  [112−1240121210215]R_{1} \leftarrow \frac{1}{2}\,R_{1},\ R_{2} \leftarrow R_{2} + 3R_{1},\ R_{3} \leftarrow R_{3} + 2R_{1} \;\longrightarrow\; \left[\begin{array}{ccc|c}1 & \frac{1}{2} & -\frac{1}{2} & 4 \\ 0 & \frac{1}{2} & \frac{1}{2} & 1 \\ 0 & 2 & 1 & 5\end{array}\right]
  3. Column 2: make the pivot 1 and clear the rest of the column

    R2←2 R2, R1←R1−12R2, R3←R3−2R2  ⟶  [10−13011200−11]R_{2} \leftarrow 2\,R_{2},\ R_{1} \leftarrow R_{1} - \frac{1}{2}R_{2},\ R_{3} \leftarrow R_{3} - 2R_{2} \;\longrightarrow\; \left[\begin{array}{ccc|c}1 & 0 & -1 & 3 \\ 0 & 1 & 1 & 2 \\ 0 & 0 & -1 & 1\end{array}\right]
  4. Column 3: make the pivot 1 and clear the rest of the column

    R3←−R3, R1←R1+R3, R2←R2−R3  ⟶  [10020103001−1]R_{3} \leftarrow -R_{3},\ R_{1} \leftarrow R_{1} + R_{3},\ R_{2} \leftarrow R_{2} - R_{3} \;\longrightarrow\; \left[\begin{array}{ccc|c}1 & 0 & 0 & 2 \\ 0 & 1 & 0 & 3 \\ 0 & 0 & 1 & -1\end{array}\right]
  5. Read off the solution

    x=2,y=3,z=−1x = 2,\quad y = 3,\quad z = -1

About the system of linear equations solver

A system of linear equations is written as an augmented matrix [A | b], one row per equation. Gauss–Jordan elimination scales each pivot row so the pivot is 1 and subtracts multiples of it from every other row until the coefficients form the identity matrix, leaving the solution in the last column. The arithmetic uses exact fractions, so 2x + 3y = 7, 4x − y = 1 gives x = 5/7 and y = 13/7 rather than rounded decimals.

Simultaneous equations come up in circuit analysis, mixture and pricing problems, and algebra courses. The default is the 3 × 3 example from Wikipedia's Gaussian elimination article, 2x + y − z = 8, −3x − y + 2z = −11, −2x + y + 2z = −3, with the unique solution x = 2, y = 3, z = −1.

By the Rouché–Capelli theorem the system has one solution when the rank of A equals the number of unknowns, infinitely many when A and [A | b] share a smaller rank, and none when their ranks differ.

How to solve a system of linear equations

Write the unknowns in the same order in every equation, then eliminate them one at a time. For 2x + 3y = 7 and 4x − y = 1, the solution is x = 5/7 and y = 13/7. Systems of 2 to 5 equations in as many unknowns are solved by Gauss–Jordan elimination in exact fractions.

Solving by elimination, step by step

  1. Multiply 4x − y = 1 by 3 to get 12x − 3y = 3.
  2. Add it to 2x + 3y = 7. The y terms cancel, leaving 14x = 10, so x = 5/7.
  3. Substitute back: y = 4x − 1 = 20/7 − 7/7 = 13/7.
  4. Check both equations: 2(5/7) + 3(13/7) = 49/7 = 7, and 4(5/7) − 13/7 = 7/7 = 1.

Gauss–Jordan elimination does the same with rows of numbers. Swapping rows, multiplying a row by a nonzero number and adding a multiple of one row to another all keep the solutions, until each row reads off one unknown.

OpenStax's elimination lesson works through this augmented-matrix method.

How to write equations as rows of numbers

Each equation becomes one row: its coefficients in a fixed order, then the constant. Move the terms first, so 2x = 7 − 3y becomes 2x + 3y = 7, written 2 3 7. With 4x − y = 1 as the second row:

2 3 7
4 -1 1
  • Separate entries with spaces or commas; 2 3 | 7 and 2 3 = 7 also work.
  • A missing unknown gets a 0, so n unknowns need n + 1 numbers on each of n rows.
  • Fractions such as 1/2 are kept exact.
  • Answers name the unknowns x, y and z for up to three, and x₁ to x₅ for four or five.

One solution, no solution or infinitely many

EquationsTypeSolution
x + y = 2; x − y = 0Unique solutionx = 1, y = 1
2x + 3y = 7; 4x − y = 1Unique solutionx = 5/7, y = 13/7
x + y = 1; 2x + 2y = 3No solutionThe equations contradict each other
x + y = 2; 2x + 2y = 4Infinitely many solutionsx = 2 − t, y = t

A unique solution gives one value to every unknown. For a square system, that happens exactly when the determinant of the coefficients is not zero.

In the third row, doubling x + y = 1 gives 2x + 2y = 2, which contradicts 2x + 2y = 3. Elimination exposes this as a row reading 0 = 1. The two lines are parallel and never meet.

In the fourth row, the second equation is the first one doubled, so only one restriction remains. Setting y = t gives x = 2 − t for any real t, and both equations draw the same line.

A zero determinant alone cannot tell these last two cases apart; the reduced rows can.

Determinant and condition number

The determinant belongs to the coefficient matrix only. Scaling an equation scales the determinant but leaves the solutions unchanged, so its size alone says little about accuracy.

The condition number κ = ‖A‖∞ × ‖A⁻¹‖∞, where each norm is the largest absolute row sum, measures how much input errors can grow. For 2x + y − z = 8, −3x − y + 2z = −11 and −2x + y + 2z = −3, the solution is x = 2, y = 3, z = −1, and κ = 60.

Nearly parallel equations have a large κ. x + y = 2 and x + 1.0001y = 2.0001 give x = 1, y = 1, with κ ≈ 40,004. Raising the last constant to 2.0002 moves the answer to x = 0, y = 2.

Above κ = 10¹², the inputs need many exact digits to give a meaningful answer. Exact fractions avoid rounding during elimination, but they cannot restore precision missing from measured coefficients.

Type one third as 1/3. With 0.333 instead, (1/3)x + y = 2 and x + y = 1 give x ≈ −1.49925, not −3/2.

Which solver fits your equations

Products of unknowns, squares and functions such as sin(x) make an equation nonlinear, so it cannot be written as a row of coefficients. For one quadratic, use the quadratic calculator, and for one polynomial up to degree 6, the polynomial root finder.

For matrix operations themselves, use the matrix calculator. A system needs as many equations as unknowns here; for more equations than unknowns, such as noisy measurements, a least-squares fit is the usual method.

Worked examples

Wikipedia 3×3 example

Equations as rows of numbers
2 1 -1 8 -3 -1 2 -11 -2 1 2 -3
Solution
x = 2, y = 3, z = −1
x₁ (x)
2
x₂ (y)
3
x₃ (z)
-1
Determinant of the coefficients
-1
Condition number (∞-norm)
60

Checked against: Wikipedia “Gaussian elimination” example; with exact fractions: det = −1, ‖A‖∞ = 6, ‖A⁻¹‖∞ = 10

Fractional answer: 2x + 3y = 7, 4x − y = 1

Equations as rows of numbers
2 3 7 4 -1 1
Solution
x = 5/7, y = 13/7
x₁ (x)
0.7142857143
Determinant of the coefficients
-14

Checked against: x = 10/14, y = 4x − 1 = 13/7

Inconsistent: x + y = 1, 2x + 2y = 3

Equations as rows of numbers
1 1 1 2 2 3
Type of system
No solution: the equations are inconsistent
Solution
No solution

Checked against: 2 × (first) gives 2x + 2y = 2 ≠ 3

Dependent equations (edge case)

Equations as rows of numbers
1 1 1 6 2 2 2 12 1 -1 0 0
Type of system
Infinitely many solutions
Solution
x = 3 − t/2, y = 3 − t/2, z = t
Determinant of the coefficients
0

Checked against: Row 2 = 2 × row 1; x = y and 2y + z = 6 (hand elimination)

Questions

How do you solve a system of three equations with three unknowns?

Eliminate one variable at a time. Gauss–Jordan elimination writes the equations as a matrix, turns the first coefficient into 1, subtracts multiples of that row to clear x from the other equations, then repeats for y and z. For the default system three rounds of row operations leave x = 2, y = 3, z = −1; substituting into 2x + y − z = 8 gives 4 + 3 + 1 = 8.

How can you tell if a system has no solution or infinitely many?

Row-reduce it and look at rows whose coefficients all become 0. A row reading 0 = 1, or 0 equal to any non-zero number, means no solution: x + y = 1 and 2x + 2y = 3 are parallel lines. A row reading 0 = 0 means one equation repeats another, leaving a free variable and infinitely many solutions. With as many equations as unknowns, a determinant of 0 signals one of these two cases.

What is Cramer's rule?

Cramer's rule gives each unknown as a ratio of determinants: x = det(Aₓ)/det(A), where Aₓ is A with its x column replaced by the constants. For 2x + 3y = 7, 4x − y = 1, det(A) = 2 × (−1) − 3 × 4 = −14 and det(Aₓ) = 7 × (−1) − 3 × 1 = −10, so x = 10/14 = 5/7. It needs det(A) ≠ 0 and much more arithmetic than elimination beyond 3 × 3.

What is the difference between Gaussian and Gauss–Jordan elimination?

Gaussian elimination stops at row echelon form, a triangular matrix, and finds the unknowns by back-substitution from the last equation upward. Gauss–Jordan continues until the coefficients form the identity matrix, so each row reads off one unknown directly. Gauss–Jordan takes about n³ arithmetic operations for n equations against about 2n³/3, in exchange for skipping the substitution step.

What does the condition number of a system mean?

It bounds how much a small relative change in the coefficients or constants can grow in the solution. The ∞-norm version is κ = ‖A‖∞ × ‖A⁻¹‖∞; for the default system ‖A‖∞ = 6 and ‖A⁻¹‖∞ = 10, so κ = 60. As a rule of thumb about log₁₀ κ significant digits are lost, here about 2, and a value near 10¹² means the equations are nearly dependent.

About this calculator

[A∣b]⟶[I∣x]κ∞(A)=∥A∥∞ ∥A−1∥∞\begin{gathered} [A \mid \mathbf b] \longrightarrow [I \mid \mathbf x] \\[10pt] \kappa_\infty(A) = \|A\|_\infty \, \|A^{-1}\|_\infty \end{gathered}

Sources

  1. Wikipedia — Gaussian elimination (worked 3×3 example)
  2. Wolfram MathWorld — Linear System of Equations: consistent iff rank(A) = rank[A|b]

Checked against references

This calculator includes 5 worked examples with independently sourced answers. They run in the test suite, and you can run them here too.

Put this calculator on your site

Paste this where you want the calculator to appear. It is free to use, it stays in step with corrections made here, and the credit line below it links back so your readers can find the full version.

Height
Preview the embed

Keep the credit line. It is the only condition, and it is what keeps these calculators free.