{
  "id": "system-of-equations",
  "version": "783ef7fe1cb8",
  "status": "published",
  "name": "System of Equations Calculator",
  "question": "How do I solve a system of equations?",
  "summary": "Solves a system of up to 4 linear equations in up to 4 unknowns (x, y, z, w) by Gauss-Jordan elimination in exact fractions: one solution, infinitely many, or none.",
  "category": "math",
  "subcategory": "algebra",
  "url": "https://www.acalculator.org/math/system-of-equations-calculator",
  "markdown": "https://www.acalculator.org/math/system-of-equations-calculator.md",
  "kind": "function",
  "method": "Gauss-Jordan elimination on the augmented matrix [A | b] to reduced row echelon form; a pivot in the constant column means no solution, a pivot in every unknown column one solution, and fewer pivots infinitely many.",
  "assumptions": [
    "Every coefficient and constant is read as an exact fraction (1/3 is 1/3, 0.1 is 1/10), so the solution has no rounding error.",
    "The unknowns are x, y, z, w in that order, one column each; the last column holds the constants.",
    "The pivot in each column is the first row, from the top of the rows not yet used, with a non-zero entry."
  ],
  "inputs": {
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "properties": {
      "m": {
        "title": "Equations",
        "description": "One row per equation: the coefficients of x, y, z, w in order, then the constant on the right of the equals sign in the last column.",
        "type": "array",
        "items": {
          "type": "array",
          "items": {
            "type": "number"
          }
        }
      }
    }
  },
  "outputs": {
    "solution": {
      "label": "Solution",
      "description": "The values of the unknowns as exact fractions, the general solution, or No solution.",
      "format": "text"
    },
    "decimal": {
      "label": "Solution in decimals",
      "description": "A single solution in decimals, each rounded half up to 10 significant figures.",
      "format": "text"
    },
    "kind": {
      "label": "Number of solutions",
      "description": "One solution, Infinitely many solutions, or No solution.",
      "format": "text"
    },
    "equations": {
      "label": "Your equations",
      "description": "The system as read from the grid, one equation per row.",
      "format": "text"
    },
    "steps": {
      "label": "Row operations",
      "description": "The Gauss-Jordan row operations on the augmented matrix, in order.",
      "format": "text"
    }
  },
  "defaultAnswer": {
    "inputs": {
      "m": "1,1,1,6;0,2,5,-4;2,5,-1,27"
    },
    "outputs": {
      "solution": "x = 5, y = 3, z = -2",
      "decimal": "x = 5, y = 3, z = -2",
      "kind": "One solution",
      "equations": "x + y + z = 6; 2y + 5z = -4; 2x + 5y - z = 27",
      "steps": "R3 → R3 − 2 × R1; R2 → 1/2 × R2; R1 → R1 − R2; R3 → R3 − 3 × R2; R3 → -2/21 × R3; R1 → R1 + 3/2 × R3; R2 → R2 − 5/2 × R3"
    },
    "text": "Solving x + y + z = 6; 2y + 5z = -4; 2x + 5y - z = 27 gives: x = 5, y = 3, z = -2."
  },
  "examples": [
    {
      "given": {
        "m": [
          [
            1,
            1,
            1,
            6
          ],
          [
            0,
            2,
            5,
            -4
          ],
          [
            2,
            5,
            -1,
            27
          ]
        ]
      },
      "expect": {
        "solution": "x = 5, y = 3, z = -2",
        "decimal": "x = 5, y = 3, z = -2",
        "kind": "One solution",
        "equations": "x + y + z = 6; 2y + 5z = -4; 2x + 5y - z = 27"
      },
      "source": "OpenStax, College Algebra 2e, §7.1 and §7.2, systems of linear equations (https://openstax.org/books/college-algebra-2e/pages/7-1-systems-of-linear-equations-two-variables); hand calculation in content.mdx: elimination; check 5 + 3 − 2 = 6, 6 − 10 = −4, 10 + 15 + 2 = 27"
    },
    {
      "given": {
        "m": [
          [
            2,
            3,
            7
          ],
          [
            1,
            -1,
            1
          ]
        ]
      },
      "expect": {
        "solution": "x = 2, y = 1",
        "kind": "One solution",
        "steps": "R1 → 1/2 × R1; R2 → R2 − R1; R2 → -2/5 × R2; R1 → R1 − 3/2 × R2"
      },
      "source": "hand calculation in content.mdx: from x − y = 1, x = 1 + y; 2(1 + y) + 3y = 7, y = 1, x = 2 (OpenStax College Algebra 2e §7.1)"
    },
    {
      "given": {
        "m": [
          [
            1,
            2,
            4
          ],
          [
            3,
            -1,
            2
          ]
        ]
      },
      "expect": {
        "solution": "x = 8/7, y = 10/7",
        "decimal": "x = 1.142857143, y = 1.428571429"
      },
      "source": "hand calculation in content.mdx: Cramer, det = −1 − 6 = −7, x = (−4 − 4) ÷ −7 = 8/7, y = (2 − 12) ÷ −7 = 10/7"
    },
    {
      "given": {
        "m": [
          [
            1,
            1,
            2
          ],
          [
            2,
            2,
            5
          ]
        ]
      },
      "expect": {
        "solution": "No solution",
        "kind": "No solution"
      },
      "source": "hand calculation in content.mdx: 2 × (x + y) = 4 cannot also be 5"
    },
    {
      "given": {
        "m": [
          [
            1,
            2,
            -1,
            3
          ],
          [
            2,
            4,
            -2,
            6
          ],
          [
            1,
            0,
            1,
            1
          ]
        ]
      },
      "expect": {
        "solution": "x = 1 - z, y = 1 + z, z is any number",
        "kind": "Infinitely many solutions"
      },
      "source": "hand calculation in content.mdx: row 2 is twice row 1; x = 1 − z, then 2y = 3 − x + z = 2 + 2z"
    },
    {
      "given": {
        "m": [
          [
            0.5,
            0.3333333333333333,
            1
          ],
          [
            0.25,
            -1,
            2
          ]
        ]
      },
      "expect": {
        "solution": "x = 20/7, y = -9/7"
      },
      "source": "hand calculation in content.mdx: cells read exactly (1/3 is 1/3), x = 8 + 4y, 7y/3 = −3; SymPy solve (progress log)"
    },
    {
      "given": {
        "m": [
          [
            1,
            1,
            1,
            1,
            10
          ],
          [
            1,
            -1,
            0,
            0,
            -1
          ],
          [
            0,
            1,
            -1,
            0,
            -1
          ],
          [
            0,
            0,
            1,
            -1,
            -1
          ]
        ]
      },
      "expect": {
        "solution": "x = 1, y = 2, z = 3, w = 4"
      },
      "source": "hand calculation in content.mdx: y = x + 1, z = y + 1, w = z + 1, and 4x + 6 = 10"
    }
  ],
  "sources": [
    "OpenStax, College Algebra 2e, §7.1 Systems of Linear Equations: Two Variables and §7.2 Systems of Linear Equations: Three Variables. https://openstax.org/books/college-algebra-2e/pages/7-1-systems-of-linear-equations-two-variables",
    "OpenStax, College Algebra 2e, §7.6 Solving Systems with Gaussian Elimination (augmented matrices, row operations). https://openstax.org/books/college-algebra-2e/pages/7-6-solving-systems-with-gaussian-elimination",
    "Gilbert Strang, Introduction to Linear Algebra, 5th edition (2016), §3.3 The Complete Solution to Ax = b."
  ],
  "related": [
    "matrix",
    "determinant",
    "rref",
    "inverse-matrix",
    "slope-intercept"
  ],
  "changelog": []
}
