MatrixCalc

Matrix multiplication calculator

Multiply two matrices and see the dot product behind every entry — plus addition, subtraction, scalar multiplication, transpose and integer powers, all up to 50×50.

Matrix A
rows: 3
cols: 3
Matrix B
rows: 3
cols: 3
Operations
Result
Pick an operation to see the result here. Errors will show up in this area.

Tips: adjust sizes (max 50×50). For A×B, cols(A)=rows(B). det/inverse/trace/power require square matrices.

React, Tailwind & shadcn/ui. No external math deps. — English

Fill in matrices A and B above and press A × B. The button is disabled when the sizes do not fit, with a note telling you which dimensions must match. Open the steps to see each entry expanded as a sum of products, which is exactly how you would write it out by hand. The same tab also holds addition, subtraction and transpose, and the Scalars and Power tabs cover k·A and Aⁿ — all of them explained below.

The dimension rule

To multiply an m×n matrix by an n×p matrix, the inner numbers must be equal: columns of A must match rows of B. The result is m×p — the outer numbers. This is why A × B can be perfectly valid while B × A is not even defined.

The row-by-column rule

Entry (i, j) of the product is the dot product of row i of A with column j of B:

c(i,j) = a(i,1)·b(1,j) + a(i,2)·b(2,j) + … + a(i,n)·b(n,j)

12
34
×
56
78
=
1922
4350

Check the first entry: 1·5 + 2·7 = 19. Each of the four entries is its own little dot product, and the calculator prints all four expansions in the steps panel.

AB is not BA

Matrix multiplication is not commutative. Often BA is not even defined, and when both products exist they are usually different matrices. Reversing the order of a product of transformations genuinely changes what happens — rotate then reflect is not reflect then rotate. Try both buttons on the same pair and compare.

One more warning: A·B = 0 does not imply that A or B is zero. Matrices have zero divisors, unlike ordinary numbers.

What does hold

  • Associative: (A·B)·C = A·(B·C)
  • Distributive: A·(B + C) = A·B + A·C
  • Identity: I·A = A·I = A
  • Transpose reverses: (A·B)ᵀ = Bᵀ·Aᵀ
  • Determinants multiply: det(A·B) = det(A)·det(B)
  • Rank cannot grow: rank(A·B) ≤ min(rank(A), rank(B))

Addition, subtraction and scaling

Addition and subtraction are the operations that behave exactly as you would hope: entry by entry, no surprises. Both matrices must have the same dimensions — a 2×3 can be added to another 2×3 and to nothing else — and the result keeps those dimensions.

12
34
+
56
78
=
68
1012

Because it works positionally, addition inherits the arithmetic you already know: A + B = B + A, and the grouping of a three-way sum does not matter. That is a genuine contrast with multiplication. Subtraction is addition of the negative, so A − B is A + (−1)·B and the order matters in the ordinary way that 5 − 3 differs from 3 − 5.

Scalar multiplication scales every entry by the same number, with no shape requirement at all. One consequence surprises almost everyone: scaling a matrix does not scale its determinant by k. For an n×n matrix, det(k·A) = kⁿ·det(A), because each of the n rows is scaled and the determinant is multiplied once for each. Doubling a 3×3 matrix multiplies its determinant by eight. The trace, being a plain sum, behaves as expected: tr(k·A) = k·tr(A).

Transpose

Transposing reflects a matrix across its main diagonal: the entry at row i, column j moves to row j, column i. An m×n matrix becomes n×m, so the operation is defined for every shape. A column vector becomes a row vector, which is why xᵀy is the standard way to write a dot product.

123
456
ᵀ =
14
25
36

Three identities are worth memorising. Transposing twice returns the original: (Aᵀ)ᵀ = A. Transposing a sum distributes: (A + B)ᵀ = Aᵀ + Bᵀ. But transposing a product reverses it: (A·B)ᵀ = Bᵀ·Aᵀ, not Aᵀ·Bᵀ. The reversal is forced by the shapes — if A is 2×3 and B is 3×4, then Aᵀ is 3×2 and Bᵀ is 4×3, and only Bᵀ·Aᵀ has dimensions that agree. A matrix equal to its own transpose is called symmetric, and symmetric matrices are unusually well behaved: their eigenvalues are always real, and they are the ones Cholesky decomposition applies to.

Powers

Aⁿ means multiplying A by itself n times, and only makes sense for square matrices.A⁰ is the identity, not a matrix of zeros, and is A itself.

11
01
² =
12
01
, and generally Aⁿ =
1n
01

Squaring is not entrywise: the top-right entry is 1·1 + 1·1 = 2, not 1² = 1. The calculator uses exponentiation by squaring, so A¹⁶ costs four multiplications rather than fifteen. Powers show up wherever a process repeats: in a Markov chain, if P holds the transition probabilities for one step, Pⁿ holds them for n steps. In an adjacency matrix, entry (i, j) of Aⁿ counts the walks of length n from vertex i to vertex j. For very large exponents, diagonalise instead — if A = P·D·P⁻¹ with D diagonal then Aⁿ = P·Dⁿ·P⁻¹, which starts from the eigenvalues.

Common mistakes

  • Multiplying entry by entry. Matrix multiplication is not a(i,j)·b(i,j). That operation exists — the Hadamard product — but it is not what A × B means.
  • Assuming AB = BA. Matrix multiplication is not commutative.
  • Concluding a factor is zero. A·B = 0 does not mean A or B is zero.
  • Writing (A·B)ᵀ = Aᵀ·Bᵀ. The order reverses. This is the most common slip involving transposes.
  • Raising each entry to the power. A² is A·A, not the matrix of squared entries. The two agree only for diagonal matrices.
  • Adding a scalar to a matrix. A + 3 has no meaning. To add 3 along the diagonal, add 3·I.

Frequently asked questions

Why is the A × B button greyed out?
The number of columns of A does not equal the number of rows of B, so the product is undefined. Adjust the sizes with the plus and minus controls.
Is AB the same as BA?
Almost never. Often only one of the two is even defined, and when both exist they are usually different matrices.
How do I multiply a matrix by a number?
That is scalar multiplication — use the Scalars tab, where you can type any value of k, including negatives and decimals.
Can I add matrices of different sizes?
No. Addition and subtraction require identical dimensions, because they work position by position and every position must exist in both matrices.
Can I transpose or add a non-square matrix?
Yes to both. Transposition turns an m×n matrix into an n×m one, and addition only needs the two matrices to have the same shape. Only multiplication, powers and the determinant impose squareness.
What is the largest size supported?
50×50 for the numeric result. The step-by-step expansion is limited to 8×8, past which it would print thousands of terms.

Other calculators