🔢 Matrices A and B
Matrix Size:
Matrix A
Matrix B

What the matrix calculator does

This calculator works on two square matrices, A and B, of size 2×2, 3×3 or 4×4. It adds, subtracts and multiplies them, and it finds the transpose, determinant and inverse of A. Each result can be copied, and a step-by-step panel shows the working: every element sum or dot product for the arithmetic operations, and the cofactor expansion, cofactor matrix and adjugate for the determinant and inverse. That makes it handy for checking linear-algebra homework by hand, verifying a transformation matrix, or reminding yourself how an inverse is built.

How to use it

  1. Pick a size with the 2 × 2, 3 × 3 or 4 × 4 buttons. Changing size rebuilds both grids with zeros.
  2. Type the entries of Matrix A and Matrix B. Negative numbers and decimals are fine; an empty cell counts as 0.
  3. Optional shortcuts: Random A / Random B fill a matrix with whole numbers from −9 to 9, Identity A / Identity B load the identity matrix, Swap A↔B exchanges the two, and Clear All resets both to zero.
  4. Click an operation: A + B, A - B, A × B, AT, det(A) or A-1.
  5. Tick Show step-by-step calculation to see the working, or press Copy Result to copy the answer as tab-separated rows that paste neatly into a spreadsheet.

Methods and precision

Addition and subtraction work element by element. Multiplication uses the row-by-column rule R[i][j] = Σ A[i][k] × B[k][j]. The transpose swaps rows and columns. The determinant is found by cofactor (Laplace) expansion along the first row, applied recursively to the minors until they are 2×2. The inverse is computed as the adjugate divided by the determinant: A−1 = adj(A) / det(A), where the adjugate is the transpose of the cofactor matrix. If |det(A)| is below 10−12, the matrix is treated as singular and no inverse is shown.

A quick worked example: for A = [[1, 2], [3, 4]], det(A) = 1×4 − 2×3 = −2, the adjugate is [[4, −2], [−3, 1]], and dividing by −2 gives A−1 = [[−2, 1], [1.5, −0.5]].

All arithmetic uses standard 64-bit floating-point numbers. Results are rounded to six decimal places for display, and anything smaller in size than 10−10 is shown as 0 so that rounding noise does not appear as tiny non-zero entries. Fractions therefore appear as decimals: 1/3 is shown as 0.333333. Everything is calculated in your browser and nothing you enter is saved or sent anywhere; the clipboard is only touched when you press Copy Result.

Frequently asked questions

How do I find the determinant or inverse of B?

Transpose, determinant and inverse always act on Matrix A. Press Swap A↔B to move B into the A slot, run the operation, then swap back if needed.

Why is A × B different from B × A?

Matrix multiplication is not commutative: each entry combines a row of the first matrix with a column of the second, so reversing the order combines different numbers. Try it with Swap A↔B — the two products usually differ unless one matrix is the identity or the two happen to commute.

Why am I told my matrix is singular when I expected an inverse?

Either the rows are genuinely linearly dependent (one row is a combination of others), or all entries are so small that the determinant falls below the 10−12 threshold. In the second case, multiply the matrix by a constant k first; the inverse of kA is the inverse of A divided by k.

Can I use non-square or larger matrices?

No. Both matrices are always square and the same size, from 2×2 up to 4×4. For larger systems or rectangular matrices, a numerical package such as NumPy or a computer algebra system is a better fit.

Related tools