Matrix Calculator
Add, scalar-multiply, multiply, or find the determinant of matrices up to 4x4, with step-by-step validated results.
How It's Calculated
Formula
(A+B)_{ij} = A_{ij}+B_{ij} \qquad (kA)_{ij} = k\,A_{ij} \qquad (AB)_{ij} = \sum_k A_{ik}B_{kj} \qquad \det(A) = \sum_j (-1)^{j}A_{1j}\,M_{1j}This calculator supports four matrix operations on matrices up to 4x4: addition, scalar multiplication, matrix product, and determinant. Addition and subtraction-style operations require both matrices to have identical dimensions — each entry is added to the entry in the same position. Scalar multiplication multiplies every entry of Matrix A by a single number k. Matrix product (A × B) requires Matrix A's column count to equal Matrix B's row count; the result has Matrix A's row count and Matrix B's column count, with each entry computed as the dot product of a row of A and a column of B. The determinant is only defined for a square matrix (equal rows and columns) and is computed here by cofactor (Laplace) expansion along the first row, recursively reducing to 2x2 and 1x1 sub-matrices — an exact method well suited to this calculator's bounded 4x4 size. Matrix A and Matrix B each use a "columns" selector because the underlying input table always shows 4 columns; only the selected number of columns is treated as part of the matrix, and unused cells are ignored.
Worked Examples
Matrix addition (2x2)
- A = [[1,2],[3,4]], B = [[5,6],[7,8]]
- Same dimensions (2x2), so addition is defined
- (A+B) = [[1+5, 2+6],[3+7, 4+8]] = [[6,8],[10,12]]
Matrix product (2x3 by 3x2)
- A is 2x3, B is 3x2 — A's columns (3) equal B's rows (3), so the product is defined
- Result is 2x2 (A's rows x B's columns)
- Each result entry is the dot product of the matching row of A and column of B
3x3 determinant by cofactor expansion
- A = [[6,1,1],[4,-2,5],[2,8,7]]
- Expand along the first row: det = 6·M11 − 1·M12 + 1·M13
- M11 = det[[-2,5],[8,7]] = -14-40 = -54; M12 = det[[4,5],[2,7]] = 28-10 = 18; M13 = det[[4,-2],[2,8]] = 32+4 = 36
- det = 6(-54) - 1(18) + 1(36) = -324 - 18 + 36 = -306
Frequently Asked Questions
Why do I need to set a separate 'columns' value for each matrix?
The input table always displays 4 columns so it can represent any matrix up to 4x4 without changing shape as you work. The "columns" selector tells the calculator how many of those columns actually belong to your matrix — for a 2x2 matrix, set it to 2 and ignore columns 3 and 4.
Why is there no subtraction, inverse, or transpose?
This calculator implements exactly the operations its specification calls for: addition, scalar multiplication, matrix product, and determinant. A general-purpose matrix inverse in particular requires careful numerical handling of near-singular matrices that is out of scope here.
What happens if I try to add matrices with different dimensions?
The calculation is not performed, and a message explains that both matrices' dimensions must match exactly for addition.
What happens if I try to find the determinant of a non-square matrix?
The determinant is only defined for square matrices (equal rows and columns), so the calculation is not performed and a message explains that Matrix A must be square.
What is the largest matrix this calculator supports?
4x4. This keeps input and computation fast and reliable in the browser; larger matrices are out of scope for this tool.