Matrix Calculator — Multiply, Invert, Solve AX = B
A complete matrix calculator for students and professionals: addition, subtraction, multiplication, transpose, determinant, inverse, adjoint, rank, trace, RREF, matrix powers, scalar multiplication, and solving linear systems AX = B. Enter your own values — everything calculates instantly in your browser.
Every Operation Has a Shape Rule
Matrix arithmetic fails more often than it succeeds for people learning it, and almost never because the numbers were wrong. It fails because the two matrices were the wrong shapes for the operation requested. Dimensions are not a formality here — they are the first thing to check and the reason most error messages appear.
| Operation | Requirement | Shape of the result |
|---|---|---|
| A + B, A − B | Identical dimensions | Same as the inputs |
| A × B | Columns of A must equal rows of B | Rows of A × columns of B |
| Determinant, Inverse, Adjoint, Trace, Power | Square only | A single number, or a square matrix |
| Transpose | None — works on any matrix | Dimensions swapped |
| Rank, Scalar multiplication | None | A number, or the same shape |
| RREF (row reduced echelon form) | None | Same shape as the input |
| Solve AX = B | A square and non-singular; rows of B must match A | Same rows as A, same columns as B |
Two rows in that table cause nearly all the confusion, and both are worth understanding rather than memorising.
Multiplication: the Inner Dimensions Must Meet
Addition works elementwise, which is why it demands identical shapes. Multiplication does something quite different: each entry of the result is a row of A paired against a column of B. That pairing only works if the row and the column have the same length.
A is m × n, B is n × p → AB is m × p The two inner numbers must match; the outer two become the result
Multiplying a 2 × 3 by a 3 × 2 works, because the inner pair is 3 and 3, and the answer is 2 × 2:
A = [1 2 3; 4 5 6] B = [7 8; 9 10; 11 12] AB[1][1] = 1×7 + 2×9 + 3×11 = 58 AB[1][2] = 1×8 + 2×10 + 3×12 = 64 AB[2][1] = 4×7 + 5×9 + 6×11 = 139 AB[2][2] = 4×8 + 5×10 + 6×12 = 154 AB = [58 64; 139 154]
Reverse the order and BA is also valid — the inner pair is 2 and 2 — but the result is 3 × 3. Same two matrices, different operation, a different-sized answer. This is the concrete version of the rule that matrix multiplication is not commutative: AB and BA are usually different, and are frequently not even the same shape.
One consequence worth carrying: order reverses when you transpose or invert a product. (AB)ᵀ equals BᵀAᵀ, and (AB)⁻¹ equals B⁻¹A⁻¹. Writing them in the original order is a common and silent error, because the dimensions often still work out.
Determinant and Inverse: Square Only, and the Zero Wall
The determinant is defined only for square matrices, because it describes how the matrix scales space — a question that has no meaning when the input and output dimensions differ.
For a 2 × 2 [a b; c d]: det = ad − bc
For [3 8; 4 6] the determinant is (3 × 6) − (8 × 4) = 18 − 32 = −14. Once you have it, the 2 × 2 inverse is mechanical: swap the diagonal entries, negate the other two, and divide everything by the determinant.
A⁻¹ = (1 ÷ det) × [d −b; −c a] For [3 8; 4 6]: (1 ÷ −14) × [6 −8; −4 3] = [−3/7 4/7; 2/7 −3/14]
The division is where inverses fail. If the determinant is zero there is nothing to divide by, and the matrix has no inverse — it is called singular. This is not a computational limitation to work around; it means the matrix genuinely cannot be undone, because it has collapsed space rather than merely reshaping it.
You can often spot it before calculating. In [1 2; 2 4] the second row is exactly twice the first, so the rows carry no independent information and the determinant is 4 − 4 = 0. Any matrix with a repeated row, a row of zeros, or one row that is a combination of others is singular for the same reason.
Rank measures precisely this. It counts how many rows are genuinely independent, so a square matrix is invertible exactly when its rank equals its size. Rank works on any shape, which makes it a useful check when the determinant is unavailable.
Solving AX = B Without Inverting Anything
A system of linear equations can be written as one matrix equation, with A holding the coefficients, X the unknowns, and B the right-hand sides.
2x + 3y = 8 5x + 4y = 13 becomes A = [2 3; 5 4], B = [8; 13], solve for X Here the solution is x = 1, y = 2
Algebraically the solution is X = A⁻¹B, and that is how it is usually introduced. In practice it is solved directly by elimination rather than by computing the inverse first — the answer is the same and the direct route is faster and numerically better behaved. Either way the condition is identical: A must be square and non-singular.
When A is singular, the system does not have one unique solution. It either has none, because the equations contradict each other, or infinitely many, because one equation adds nothing the others did not already say. An error at this point is telling you something about the equations rather than about the arithmetic.
What Each Error Message Is Telling You
| What happened | What it means | What to do |
|---|---|---|
| Dimensions must match | You tried to add or subtract different shapes | Check both row and column counts |
| Columns of A must match rows of B | The inner dimensions do not meet | Try the other order, or check the matrix was entered transposed |
| Matrix must be square | Determinant, inverse, trace and power need equal rows and columns | Verify the size selector matches your data |
| Matrix is singular | The determinant is zero — no inverse exists | Look for a duplicated row, a zero row, or one row that is a multiple of another |
| No unique solution | The coefficient matrix is singular | The system has no solution or infinitely many — re-read the equations |
The second row is the one worth pausing on. A dimension error on multiplication is often not a mistake in the operation but a matrix entered the wrong way round, and transposing it makes the product valid. Whether that is the product you actually wanted is a separate question.
Checking a Result Without Redoing It
Machine output is worth spot-checking, and a few properties make that quick.
- Verify an inverse by multiplying. A × A⁻¹ should give the identity matrix — ones down the diagonal, zeros elsewhere. Small floating-point residues near zero are normal.
- Check one entry of a product by hand. The top-left entry is the first row of A against the first column of B. If that matches, the shape and method are almost certainly right.
- Check the result shape first. Before reading any numbers, confirm the answer has the dimensions the rule predicts. A wrong shape means the wrong operation ran.
- Watch for a determinant very close to zero. A matrix that is nearly singular produces an inverse with very large entries, and small input errors get amplified enormously. Treat such results with suspicion rather than confidence.
For statistics rather than linear algebra, our mean, median and mode calculator handles descriptive measures, and the matrix operations guide works through each operation step by step.
Matrix Operation Questions
Why does my matrix multiplication give a dimension error?
Is matrix multiplication commutative?
Why can I only take a determinant of a square matrix?
What does it mean when a matrix is singular?
How do I find the inverse of a 2 × 2 matrix by hand?
What does the rank of a matrix tell me?
How does solving AX = B work?
Why does solving my system say there is no unique solution?
How can I check a matrix result quickly?
My inverse has huge numbers in it. Is that wrong?
Last updated
