Math Runs locally Ready to use Built-in examples No tracking

Linear System Solver

Enter coefficients row by row and solve a 2x2 or 3x3 linear system with exact rational (BigInt) Gaussian elimination: unique solutions come as both fractions and decimals, with determinant and back-substitution verification.

Two equations, two unknowns is the model behind a great many word problems — mixing two solutions, tickets at two prices, a total count and a total cost. Enter the coefficients and the constant term of each equation row by row and the solution comes back immediately: integers where they are integers, and exact fractions with decimal approximations where they are not.

The elimination runs on exact rational arithmetic (BigInt) rather than floating point, so coefficients such as 1/2 or 0.5 do not accumulate rounding error and the answer stays exact. The determinant is shown, and the solution is substituted back into every original equation as a verification. If the equations contradict each other the tool reports no solution; if they are proportional it reports infinitely many, with the number of independent constraints.

How to use

  1. Enter the coefficients and the constant term of each equation, one row per equation.
  2. Read the solution, in fraction and in decimal form.
  3. Check the determinant and the back-substitution verification.
  4. Read the no-solution or infinitely-many verdict when the rows are inconsistent or proportional.

How it works

Exact Gaussian elimination with BigInt

Gaussian elimination works column by column: use the first row to zero the x-coefficients below, the second row to zero the next, until an echelon form remains; back-substitute from the last row to read off every unknown. This tool implements each add, subtract, multiply and divide with BigInt rationals — no floating-point rounding anywhere, so a solution like 1/5 comes out as the exact fraction rather than 0.20000001.

How the three solution types are decided

Unique, none or infinitely many solutions is decided from the reduction: a nonzero coefficient determinant guarantees a unique solution; a contradiction row of the form "0 = nonzero" means no solution (conflicting constraints, like x+y=1 and x+y=2); insufficient rank without contradiction means infinitely many (several equations expressing the same constraint). The tool states the verdict and the reason rather than forcing a fake solution.

Back-substitution checks and classic uses

Back-substitution verification is the final safeguard: the solution is plugged into every original equation and both sides recomputed with exact fractions to confirm strict equality. Pedagogically this is the step students are taught — solve, then substitute back to check. Classic problems like the chickens-and-rabbits cage (x+y=35 with 2x+4y=94) resolve to 23 chickens and 12 rabbits within a second.

Code example

JavaScript Cramer's rule for two unknowns, Gaussian elimination beyond

// 2x2 system a1x + b1y = c1 / a2x + b2y = c2: a zero determinant means no or infinite solutions
function solve2(a1, b1, c1, a2, b2, c2) {
  const det = a1 * b2 - a2 * b1;
  if (det === 0) { return null; }
  return { x: (c1 * b2 - c2 * b1) / det, y: (a1 * c2 - a2 * c1) / det };
}

// three or more unknowns: Gaussian elimination with back substitution (partial pivoting)
function solveGauss(m) {
  const n = m.length;
  for (let i = 0; i < n; i++) {
    let p = i;
    for (let r = i + 1; r < n; r++) { if (Math.abs(m[r][i]) > Math.abs(m[p][i])) { p = r; } }
    [m[i], m[p]] = [m[p], m[i]];                 // swap in the pivot row
    for (let r = i + 1; r < n; r++) {
      const f = m[r][i] / m[i][i];
      for (let c = i; c <= n; c++) { m[r][c] -= f * m[i][c]; }
    }
  }
  const x = new Array(n).fill(0);
  for (let i = n - 1; i >= 0; i--) {
    let s = m[i][n];
    for (let c = i + 1; c < n; c++) { s -= m[i][c] * x[c]; }
    x[i] = s / m[i][i];
  }
  return x;
}

Python Let numpy do it

import numpy as np

# coefficient matrix A and constant vector b: A @ x = b
A = np.array([[2.0, 1.0, -1.0],
              [-3.0, -1.0, 2.0],
              [-2.0, 1.0, 2.0]])
b = np.array([8.0, -11.0, -3.0])

x = np.linalg.solve(A, b)                 # raises LinAlgError for a singular matrix
print(x)                                  # [ 2.  3. -1.]

# to tell "no solution" from "infinite solutions", check the determinant first
print(np.linalg.det(A))

FAQ

When does a system have no solution?

When reduction produces a row of the form "0 = nonzero": the constraints contradict each other, like x+y=1 and x+y=2. Geometrically the lines are parallel with no intersection. The tool explains this instead of forcing a number.

When are there infinitely many solutions?

When the coefficient determinant is 0 and the equations are consistent: x+y=1 with 2x+2y=2, where the second is just double the first — one constraint in disguise. The lines coincide and every point on them is a solution. The tool reports how many independent constraints remain.

Can coefficients be fractions?

Yes. Fractions like 1/2 participate exactly as rationals — more accurate than pre-converting to 0.5. Integers, decimals and fractions can be mixed, with the minus sign written directly before the number.

What is the coefficient determinant for?

A nonzero determinant is sufficient for a unique solution; in Cramer's rule each unknown equals a column-replaced determinant over the coefficient determinant. A zero determinant means no solution or infinitely many — the branch point for the tool's verdict.

What is back-substitution verification?

The computed solution is substituted into every original equation, both sides recomputed with exact fractions and compared for strict equality. It's a correctness self-check: seeing "verified" means this solution truly satisfies every equation simultaneously.

Can it solve three-variable systems?

Yes. Switch to the three-variable mode and enter four numbers per row — the x, y, z coefficients and the constant — across three rows. The same exact Gaussian elimination runs, delivering fractional and decimal values for x, y and z.

Where do the decimal approximations come from?

Directly converted from the exact fractions (1/5 is exactly 0.2), not from floating-point iteration. Need more digits? Expand the fractions yourself — no error accumulates.