Matrix Multiplication Calculator
Multiply two matrices AB where A is m x n and B is n x p. Result dimensions, m * n * p operation count, identity detection, and a step-by-step expansion of result[0][0].
Frequently Asked Questions about the Matrix Multiplication Calculator
Why is matrix multiplication not commutative (AB is not BA)?
Because the two products compute different things. Each entry of AB is a dot product of a row of A with a column of B, while each entry of BA is a dot product of a row of B with a column of A. There is no reason those should agree. The dimensions alone usually rule commutativity out: if A is 2x3 and B is 3x2, then AB is 2x2 but BA is 3x3, so the two products are not even the same shape. Even when A and B are both square and the same size, AB is almost never equal to BA. A concrete example: with A = [[1, 1], [0, 1]] and B = [[1, 0], [1, 1]], AB = [[2, 1], [1, 1]] but BA = [[1, 1], [1, 2]]. AB equals BA only in special cases: one operand is the identity, A and B are mutual inverses, both are diagonal, one is a scalar multiple of the identity, or A and B happen to share an eigenbasis.
What are the dimension compatibility rules for matrix multiplication?
If A is m x n (m rows, n columns) and B is n x p (n rows, p columns), then AB is defined and has dimensions m x p. The inner dimensions (the n in m x n and n x p) must match, and the outer dimensions (m and p) become the shape of the result. If the inner dimensions do not match, the product is undefined and you cannot multiply. For example, a 2x3 matrix can multiply a 3x4 matrix to give a 2x4 result, but a 2x3 matrix cannot multiply a 4x3 matrix because the inner dimensions (3 and 4) do not match. This calculator caps each dimension at 6, which is plenty for hand-checkable examples; for large numerical work, dedicated linear-algebra libraries handle the same operation more efficiently.
Why must the inner dimensions match?
Because each entry of the product is a dot product, and a dot product is only defined when the two vectors have the same length. To compute entry (i, j) of AB you take row i of A and column j of B and multiply them element by element, then sum. Row i of A has n entries (one per column of A); column j of B has bRows entries (one per row of B). The sum sum_k A[i][k] * B[k][j] only makes sense when the index k can range over the same set in both sides, which requires aCols = bRows. If the lengths differ, there is no consistent way to pair the entries, so the product is undefined. This is the same reason you cannot add a 2D vector to a 3D vector; matrix multiplication just packs many such dot products into one operation.
What is special about the identity matrix in multiplication?
The identity matrix I_n is the n x n square matrix with 1s on the main diagonal and 0s everywhere else. It is the multiplicative identity for matrix multiplication: for any matrix A with compatible dimensions, AI = A and IA = A. This mirrors how 1 behaves for ordinary number multiplication, where 1 * x = x * 1 = x. The proof is direct: in AI, entry (i, j) is sum_k A[i][k] * I[k][j], and I[k][j] is 1 only when k = j and 0 otherwise, so the sum collapses to A[i][j]. The identity is one of the few cases where multiplication is genuinely commutative for any A, because both AI and IA give back A unchanged.
Where does matrix multiplication show up in graphics and neural networks?
Everywhere. In 3D graphics, every model-view-projection transform is a chain of 4x4 matrix multiplications applied to vertex positions; rotating, translating, and projecting a vertex is one matmul per stage. In neural networks, a fully connected (dense) layer is literally one matrix multiplication: outputs = inputs @ weights + bias, where inputs is a batch of vectors and weights is the layer matrix. Transformers run dozens of these per token, plus the attention mechanism itself is three back-to-back matmuls (Q @ K^T, then softmax, then @ V). Convolutional layers can also be expressed as a single matrix multiplication via the im2col trick. Modern GPUs (and TPUs) are essentially purpose-built matrix-multiply engines, which is why the same hardware accelerates both rendering and deep learning.
Related Calculators
More calculators in "Math"
Double Discount Calculator (Stacked %)Nth Root CalculatorSector Area CalculatorSemicircle Area CalculatorLog Calculator (log, ln, antilog)Factor Calculator
See all 202 calculators in "Math"