Matrix Multiplication Calculator
Multiply two matrices using the row-by-column dot product rule. The number of columns in the first matrix must equal the number of rows in the second, and the resulting matrix has the outer dimensions of the two operands.
A
B
Learn About Matrix Multiplication
Definition and Row-by-Column Dot Product Rule
Matrix multiplication combines two matrices using the row-by-column inner product rule. If matrix $\mathbf{A}$ has dimension $m \times p$ and matrix $\mathbf{B}$ has dimension $p \times n$, their product $\mathbf{C} = \mathbf{A}\mathbf{B}$ is an $m \times n$ matrix whose entry $c_{ij}$ in row $i$ and column $j$ is the dot product of the $i$-th row of $\mathbf{A}$ and the $j$-th column of $\mathbf{B}$:
Dimension Compatibility Requirement
Matrix multiplication is defined if and only if the number of columns in the first matrix equals the number of rows in the second matrix:
The resulting product adopts the "outer" dimensions:
If this inner dimension condition is violated, multiplication is mathematically impossible, and the calculator reports an invalid dimension error.
Fundamental Algebraic Properties
- Associativity: $(\mathbf{A}\mathbf{B})\mathbf{C} = \mathbf{A}(\mathbf{B}\mathbf{C})$
- Distributivity: $\mathbf{A}(\mathbf{B} + \mathbf{C}) = \mathbf{A}\mathbf{B} + \mathbf{A}\mathbf{C}$ and $(\mathbf{A} + \mathbf{B})\mathbf{C} = \mathbf{A}\mathbf{C} + \mathbf{B}\mathbf{C}$
- Identity Element: $\mathbf{A}\mathbf{I}_p = \mathbf{A}$ and $\mathbf{I}_m\mathbf{A} = \mathbf{A}$
- Transpose Reversal: $(\mathbf{A}\mathbf{B})^T = \mathbf{B}^T \mathbf{A}^T$
- Determinant Product: $\det(\mathbf{A}\mathbf{B}) = \det(\mathbf{A})\det(\mathbf{B})$ (for square matrices)
Critical Algebraic Warnings
Even when both products exist and have identical square sizes, $\mathbf{A}\mathbf{B}$ and $\mathbf{B}\mathbf{A}$ generally produce entirely different matrices.
Unlike real numbers, $\mathbf{A}\mathbf{B} = \mathbf{0}$ does not imply that $\mathbf{A} = \mathbf{0}$ or $\mathbf{B} = \mathbf{0}$. Two non-zero matrices can multiply to yield the zero matrix if the column space of $\mathbf{B}$ lies in the null space of $\mathbf{A}$.
- Non-Commutativity ($\mathbf{A}\mathbf{B} \ne \mathbf{B}\mathbf{A}$):
- Existence of Zero Divisors:
- No Cancellation Law:
If $\mathbf{A}\mathbf{B} = \mathbf{A}\mathbf{C}$, one cannot cancel $\mathbf{A}$ unless $\mathbf{A}$ is proven to be invertible.
Worked Numerical Example
Multiply $\mathbf{A}_{(2 \times 3)}$ by $\mathbf{B}_{(3 \times 2)}$ to produce $\mathbf{C}_{(2 \times 2)}$:
Calculate each entry via dot products:
- $c_{11} = (1)(2) + (2)(1) + (3)(0) = 2 + 2 + 0 = 4$
- $c_{12} = (1)(-1) + (2)(3) + (3)(2) = -1 + 6 + 6 = 11$
- $c_{21} = (4)(2) + (0)(1) + (-1)(0) = 8 + 0 + 0 = 8$
- $c_{22} = (4)(-1) + (0)(3) + (-1)(2) = -4 + 0 - 2 = -6$
1. Why do the inner dimensions have to match?
Matrix multiplication represents the composition of linear transformations. If $\mathbf{B}$ maps from $\mathbb{R}^n$ to $\mathbb{R}^p$ and $\mathbf{A}$ maps from $\mathbb{R}^p$ to $\mathbb{R}^m$, the output dimension of the first transformation ($p$) must match the input dimension of the second. When computing the dot product of row $i$ with column $j$, both vectors must contain the exact same number of elements ($p$).
2. Can matrix multiplication ever be commutative?
Yes, in specific algebraic subsets. Two square matrices commute ($\mathbf{A}\mathbf{B} = \mathbf{B}\mathbf{A}$) when:
- One matrix is a scalar multiple of the identity ($\mathbf{A} = c\mathbf{I}$).
- Both matrices are diagonal.
- $\mathbf{B}$ is a power or the inverse of $\mathbf{A}$ ($\mathbf{A}\mathbf{A}^{-1} = \mathbf{A}^{-1}\mathbf{A} = \mathbf{I}$).
- Both matrices are simultaneously diagonalizable by the same eigenvector basis.
3. What is the difference between matrix multiplication and the Hadamard product?
Standard matrix multiplication uses row-by-column dot products ($\sum a_{ik}b_{kj}$) and requires inner dimensions to match ($m \times p$ and $p \times n$). The Hadamard product (denoted $\mathbf{A} \circ \mathbf{B}$) performs simple element-wise multiplication ($a_{ij} \cdot b_{ij}$) and strictly requires both matrices to have identical dimensions ($m \times n$).
1. Cayley and the Composition of Transformations
Arthur Cayley introduced matrix multiplication in 1858 not as an arbitrary arithmetic puzzle, but to represent the composition of linear substitutions. If variable vector $\mathbf{y}$ is transformed to $\mathbf{z}$ by $\mathbf{z} = \mathbf{A}\mathbf{y}$, and $\mathbf{x}$ is transformed to $\mathbf{y}$ by $\mathbf{y} = \mathbf{B}\mathbf{x}$, substitution yields $\mathbf{z} = \mathbf{A}(\mathbf{B}\mathbf{x}) = (\mathbf{A}\mathbf{B})\mathbf{x}$. The row-by-column formula is the algebraic requirement for function composition.
2. Fast Matrix Multiplication: Strassen's Breakthrough
For over a century, mathematicians believed multiplying two $n \times n$ matrices fundamentally required $O(n^3)$ operations ($8$ scalar multiplications for a $2 \times 2$). In 1969, Volker Strassen discovered an algorithm using only $7$ multiplications for a $2 \times 2$, reducing the computational complexity to $O(n^{\log_2 7}) \approx O(n^{2.807})$. Modern theoretical algorithms have reduced this exponent to approximately $O(n^{2.371})$.