🔢 Matrix Calculator

Enter two matrices (rows separated by newlines, values by commas or spaces) to add, subtract or multiply them, or find the determinant and inverse of matrix A.

The three rules behind the six operations

Addition and subtraction work element by element. Multiplication is a row-by-column dot product, and the 2×2 inverse falls out of the determinant:

(AB) ij = Σ k A ik B kj

det [a b; c d] = ad − bc
inv [a b; c d] = (1/det) × [ d −b ; −c  a ]

With the defaults A = [1 2; 3 4] and B = [5 6; 7 8], A × B is [19 22; 43 50] - the top-left 19 is 1×5 + 2×7. The determinant of A is 1×4 − 2×3 = −2, so its inverse is [−2 1; 1.5 −0.5].

Entering matrices and the size rules

A singular matrix has a determinant of zero and no inverse. The check is a magnitude below 1e-12 rather than exactly zero, so a nearly singular matrix is refused too - its inverse would be numerical noise.

Frequently asked questions

How do you find the inverse of a 2x2 matrix?

Swap the diagonal entries, flip the sign on the other two, then divide by the determinant. For [1 2; 3 4] that is [4 -2; -3 1] over -2, giving [-2 1; 1.5 -0.5].

Why does my matrix have no inverse?

Its determinant is zero, meaning one row is a multiple of another. [1 2; 2 4] is the usual example: 1 times 4 minus 2 times 2 is 0.

Is A times B the same as B times A?

Almost never. With the defaults A times B is [19 22; 43 50] but B times A is [23 34; 31 46]. Order matters.