Matrix Multiplication Calculator
Calculate matrix products with automatic dimension validation
Calculate the product of two matrices with automatic dimension validation and detailed step-by-step results.
—
Send feedback
💡 Share your idea or report a problem
✓ Thanks! We'll take a look.
Learn more
How It Works
The formula, explained simply
Matrix multiplication works like a systematic handshake between rows and columns. Each row from the first matrix meets each column from the second matrix, multiplies corresponding elements, and adds them up to create one number in the result. This process resembles calculating weighted averages, where each row represents weights and each column represents values to be weighted. The mathematical requirement that columns in A equal rows in B ensures each handshake has the same number of terms.
The calculation follows a precise pattern: result[i][j] equals row i from matrix A dotted with column j from matrix B. This dot product operation multiplies each pair of corresponding elements and sums the products. For a 3×2 matrix multiplied by a 2×4 matrix, you perform 24 individual multiplications to fill the 12 positions in the resulting 3×4 matrix.
Unlike regular multiplication, matrix multiplication is not commutative - A×B rarely equals B×A. The order matters because you are applying transformations in sequence, much like putting on socks then shoes versus shoes then socks. This property makes matrix multiplication perfect for representing sequential operations in computer graphics, engineering transformations, and economic modeling.
When To Use This
Right tool, right situation
Use matrix multiplication when you need to compose transformations or apply linear operations sequentially. In computer graphics, multiplying rotation matrices applies multiple rotations in the correct order. In engineering, multiplying a stiffness matrix by a displacement vector calculates resulting forces throughout a structure.
Matrix multiplication is essential for solving systems of linear equations using techniques like Gaussian elimination or finding eigenvalues. Economic input-output models use matrix multiplication to trace how changes in one sector ripple through an entire economy. Machine learning algorithms rely heavily on matrix multiplication for neural network forward passes and gradient calculations.
Avoid using matrix multiplication when you need element-wise operations or when the matrices represent independent datasets rather than related transformations. If you need to scale each element by a corresponding factor, use element-wise multiplication instead. Matrix multiplication is also inappropriate when the relationship between datasets is not linear or when the dimension requirements cannot be naturally satisfied.
Common Mistakes
Why results sometimes look wrong
The most common mistake is attempting to multiply incompatible matrices without checking dimensions first. Students often assume that if two matrices have the same total number of elements, they can be multiplied in any order. This leads to confusion when a 2×6 matrix cannot multiply with a 3×4 matrix, even though both contain 12 elements.
Another frequent error involves assuming matrix multiplication is commutative like regular number multiplication. Many students calculate A×B and expect B×A to yield the same result. In reality, B×A might not even be possible if the dimensions do not align properly, and when both orders are valid, they typically produce different results with different dimensions.
Misunderstanding the pattern of calculation leads to incorrect dot products. Some students multiply corresponding elements position by position, like adding matrices, rather than taking proper dot products of rows with columns. This mistake compounds when working with larger matrices, producing completely incorrect results that may not be immediately obvious as wrong.
The Math
Worked examples and deeper derivation
The mathematical foundation rests on linear combinations and the associative property of real number multiplication. When you multiply matrices A and B to get C, each element C[i][j] represents the inner product of row i from A with column j from B. This operation preserves the linear structure of transformations represented by the matrices.
Matrix multiplication satisfies associativity: (AB)C = A(BC), which means you can group multiplications differently without changing the result. This property enables efficient computation of multiple matrix products and ensures consistent results in complex calculations. The operation also satisfies the distributive property: A(B+C) = AB + AC.
The dimension requirement stems from the need for each dot product to have matching vector lengths. When multiplying an m×n matrix by a p×q matrix, the operation is only defined when n equals p. The resulting matrix has dimensions m×q, effectively combining the outer dimensions while the inner dimensions cancel out through the multiplication process.
Expert Unlock
The thing most explanations skip
Professional applications often involve sparse matrices where most entries are zero, enabling significant computational optimizations. Many engineering and scientific computations can skip multiplying by zero entries, reducing calculation time from hours to minutes for large systems. GPU acceleration excels at matrix multiplication because the operation naturally parallelizes across thousands of cores simultaneously.
How does matrix dimension compatibility work?
Need something this doesn't cover?
Suggest a tool — we'll build it →