{
  "id": "inverse-matrix",
  "version": "656dd6f1d272",
  "status": "published",
  "name": "Inverse Matrix Calculator",
  "question": "How do I find an inverse matrix?",
  "summary": "Finds the inverse A⁻¹ of a square matrix (1 × 1 to 6 × 6) by Gauss-Jordan elimination in exact fractions, with the determinant and every row operation.",
  "category": "math",
  "subcategory": "linear-algebra",
  "url": "https://www.acalculator.org/math/inverse-matrix-calculator",
  "markdown": "https://www.acalculator.org/math/inverse-matrix-calculator.md",
  "kind": "function",
  "method": "Gauss-Jordan elimination: row-reduce the n × 2n matrix [A | I]. When the left half becomes I, the right half is A⁻¹. The determinant is the product of the pivots, times −1 for each row swap.",
  "assumptions": [
    "Every entry is read as an exact fraction: a decimal such as 0.1 is 1/10, so there is no rounding in the elimination.",
    "A matrix has an inverse exactly when its determinant is not 0. A singular matrix has no inverse, and the calculator says so.",
    "The pivot in each column is the first row, from the top of the rows not yet used, with a non-zero entry.",
    "The matrix is square, 1 × 1 to 6 × 6."
  ],
  "inputs": {
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "properties": {
      "a": {
        "title": "Matrix A",
        "description": "The square matrix to invert, 1 to 6 rows and the same number of columns.",
        "type": "array",
        "items": {
          "type": "array",
          "items": {
            "type": "number"
          }
        }
      }
    }
  },
  "outputs": {
    "inverse": {
      "label": "Inverse A⁻¹",
      "description": "The inverse matrix as exact fractions, rows separated by semicolons.",
      "format": "text"
    },
    "decimal": {
      "label": "A⁻¹ in decimals",
      "description": "The same matrix in decimals, each number rounded to 10 significant figures.",
      "format": "text"
    },
    "determinant": {
      "label": "Determinant",
      "description": "det(A) as an exact fraction. A matrix has an inverse exactly when it is not 0.",
      "format": "text"
    },
    "steps": {
      "label": "Row operations on [A | I]",
      "description": "The row operations that turn [A | I] into [I | A⁻¹], in order (the first 30).",
      "format": "text"
    }
  },
  "defaultAnswer": {
    "inputs": {
      "a": "1,2,3;2,5,3;1,0,8"
    },
    "outputs": {
      "inverse": "[-40, 16, 9; 13, -5, -3; 5, -2, -1]",
      "decimal": "[-40, 16, 9; 13, -5, -3; 5, -2, -1]",
      "determinant": "-1",
      "steps": "R2 → R2 − 2 × R1; R3 → R3 − R1; R1 → R1 − 2 × R2; R3 → R3 + 2 × R2; R3 → -1 × R3; R1 → R1 − 9 × R3; R2 → R2 + 3 × R3"
    },
    "text": "The inverse of the matrix is [-40, 16, 9; 13, -5, -3; 5, -2, -1], and its determinant is -1."
  },
  "examples": [
    {
      "given": {
        "a": [
          [
            1,
            2,
            3
          ],
          [
            2,
            5,
            3
          ],
          [
            1,
            0,
            8
          ]
        ]
      },
      "expect": {
        "inverse": "[-40, 16, 9; 13, -5, -3; 5, -2, -1]",
        "determinant": "-1"
      },
      "source": "hand calculation in content.mdx (Gauss-Jordan on [A | I], Strang section 2.5); Python fractions check"
    },
    {
      "given": {
        "a": [
          [
            4,
            7
          ],
          [
            2,
            6
          ]
        ]
      },
      "expect": {
        "inverse": "[3/5, -7/10; -1/5, 2/5]",
        "decimal": "[0.6, -0.7; -0.2, 0.4]",
        "determinant": "10"
      },
      "source": "hand calculation in content.mdx: the 2 × 2 formula, 1/(4 × 6 − 7 × 2) × [6, −7; −2, 4]"
    },
    {
      "given": {
        "a": [
          [
            0,
            1
          ],
          [
            1,
            0
          ]
        ]
      },
      "expect": {
        "inverse": "[0, 1; 1, 0]",
        "determinant": "-1",
        "steps": "R1 ↔ R2"
      },
      "source": "hand calculation in content.mdx: swapping two rows twice gives I, so the swap is its own inverse"
    },
    {
      "given": {
        "a": [
          [
            4
          ]
        ]
      },
      "expect": {
        "inverse": "[1/4]",
        "decimal": "[0.25]",
        "determinant": "4"
      },
      "source": "hand calculation in content.mdx: the inverse of a 1 × 1 matrix [a] is [1/a]"
    },
    {
      "given": {
        "a": [
          [
            0.5,
            0
          ],
          [
            0.1,
            0.25
          ]
        ]
      },
      "expect": {
        "inverse": "[2, 0; -4/5, 4]",
        "determinant": "1/8"
      },
      "source": "hand calculation in content.mdx: lower triangular, det = 0.5 × 0.25 = 1/8; decimals read exactly (0.1 is 1/10)"
    }
  ],
  "sources": [
    "NIST Digital Library of Mathematical Functions, §1.2(vi) Square Matrices, equation 1.2.60 (the inverse: AA⁻¹ = A⁻¹A = I; if det(A) ≠ 0, A has a unique inverse). https://dlmf.nist.gov/1.2",
    "Gilbert Strang, Introduction to Linear Algebra, 5th ed., §2.5 Inverse Matrices (Gauss-Jordan eliminates [A I] to [I A⁻¹]; the 2 by 2 inverse and ad − bc). https://math.mit.edu/~gs/linearalgebra/ila5/linearalgebra5_2-5.pdf"
  ],
  "related": [
    "matrix-multiplication",
    "slope-intercept"
  ],
  "changelog": []
}
