🔢 Matrix Calculator

🔧 Operation

📝 Matrix A

Up to 8 × 8.

📝 Matrix B

Up to 8 × 8.

🔢 Scalar

🔢 Identity size (n)

📤 Result

{{ resultPretty }}
Enter values and the result will appear here.

JSON form

{{ resultJson }}
⚠️

ℹ️ About Matrix Calculator

What does this matrix calculator do?

This is an online matrix calculator that runs entirely in your browser. Enter any pair of matrices up to 8×8 and compute matrix addition, matrix subtraction, matrix multiplication, scalar multiplication, transpose, determinant, or inverse on demand. The tool also generates an identity matrix of any size in [1, 8] for use as a starting template.

Every operation uses the same TypeScript logic module on the server through the API endpoint below, so a curl call against the JSON API returns the same numbers as the interactive interface.

Operations and algorithms

  • Add / Subtract — element-wise C[i][j] = A[i][j] ± B[i][j]. A and B must share the same dimensions.
  • Multiply — classical row-by-column product C[i][j] = ∑k A[i][k] × B[k][j]. Requires cols(A) = rows(B).
  • Scalar multiply — multiply every entry of A by the scalar s.
  • Transpose — AT[i][j] = A[j][i]. Rows become columns.
  • Determinant — Sarrus / cofactor expansion for n ≤ 3; LU decomposition with partial pivoting for n ≥ 4. The determinant is the product of the upper-triangular diagonal multiplied by the sign of the row swaps.
  • Inverse — Gauss-Jordan elimination on the augmented matrix [A | I] with partial pivoting. The right half becomes A-1 when the left half reduces to I.
  • Identity — square matrix with 1 on the diagonal and 0 elsewhere.

Common use cases

  • Linear algebra coursework — verify hand calculations for Gauss-Jordan inverses, cofactor determinants, and basic matrix arithmetic.
  • Graphics and game development — quick sanity checks on rotation, scaling, and composite 4×4 transformation matrices.
  • Engineering and physics — solve small linear systems Ax = b by computing A-1b for design or simulation work.
  • Data analysis prototypes — confirm a covariance, projection, or rotation matrix before pasting it into a notebook.
  • API consumers — call the /api/tools/math/matrix-calculator endpoint from a script to get matrix arithmetic without pulling in a heavy linear-algebra dependency.

Worked example

With A = [[1, 2], [3, 4]] and B = [[5, 6], [7, 8]]:

  • A + B = [[6, 8], [10, 12]]
  • A × B = [[19, 22], [43, 50]]
  • AT = [[1, 3], [2, 4]]
  • det(A) = 1·4 - 2·3 = -2
  • A-1 = [[-2, 1], [1.5, -0.5]]

Limitations and edge cases

  • Matrices are restricted to at most 8×8 entries to keep the in-browser arithmetic fast and the API endpoint within the Node bridge's 5 second timeout.
  • All entries must be finite numbers. NaN, Infinity, blank cells, and non-numeric strings are rejected up front.
  • Determinant requires a square matrix; non-square inputs throw an explicit error.
  • Inverse requires a square, non-singular matrix. A pivot magnitude under 1e-12 during Gauss-Jordan elimination is treated as singular and throws "Matrix is singular (or nearly so); cannot invert".
  • Multiplication requires cols(A) = rows(B). The error message reports both dimensions to help spot mistakes.
  • Numerical results use double-precision floats. Expect tiny rounding error (~1e-15) on inverse round-trips of non-integer matrices.

Source references

API Usage Example:

POST /api/tools/math/matrix-calculator
Content-Type: application/json

{
    "operation": "add",
    "a": [
        [
            1,
            2
        ],
        [
            3,
            4
        ]
    ],
    "b": [
        [
            5,
            6
        ],
        [
            7,
            8
        ]
    ]
}
Ready