Understanding the matrix multiplication and addition calculator — concept and principle
This calculator multiplies, adds and subtracts two matrices and also gives the transpose of A. Matrix products appear whenever several linear steps are chained: combining rotations and scalings in computer graphics, applying a transition matrix twice in a Markov chain, computing weighted totals in spreadsheets, or passing data through the layers of a neural network. Enter each matrix row by row, numbers separated by spaces and rows by semicolons.
How it is calculated
- Product: (AB)ᵢⱼ = Σₖ Aᵢₖ·Bₖⱼ. Entry (i, j) is the dot product of row i of A with column j of B. It requires the number of columns of A to equal the number of rows of B; an m×n matrix times an n×p matrix gives an m×p matrix.
- Sum and difference: (A ± B)ᵢⱼ = Aᵢⱼ ± Bᵢⱼ, entry by entry. Both matrices must have exactly the same size.
- Transpose: (Aᵀ)ᵢⱼ = Aⱼᵢ, so rows become columns.
If the sizes do not fit, the calculator says "columns of A ≠ rows of B" or "sizes differ" instead of a result.
The principle
A matrix represents a linear map: it tells you where each basis vector goes. Multiplying AB means "apply B first, then A". Column j of AB is A applied to column j of B, and each entry collects contributions through every intermediate index k, which is why a sum over k appears. Because the order of operations matters, matrix multiplication is associative, (AB)C = A(BC), but generally not commutative: AB and BA usually differ. Addition, by contrast, is just adding two maps output by output, so it works entrywise and is commutative.
Worked example
- Defaults: A = [1 2; 3 4], B = [5 6; 7 8].
- Row 1 of A with column 1 of B: 1·5 + 2·7 = 19; with column 2: 1·6 + 2·8 = 22.
- Row 2 of A: 3·5 + 4·7 = 43 and 3·6 + 4·8 = 50, so A × B = [19 22; 43 50].
- Entrywise: A + B = [6 8; 10 12] and A − B = [−4 −4; −4 −4].
- Transpose: Aᵀ = [1 3; 2 4].
How to read the result
Check the shape first: the product of m×n and n×p is m×p. A useful sanity check is that det(AB) = det(A)·det(B); here det(A) = −2, det(B) = −2 and det(AB) = 19·50 − 22·43 = 4. If you swap the order, BA = [23 34; 31 46], which is different, so always confirm which matrix should act first in your application.
Common mistakes
- Multiplying entry by entry (that is the Hadamard product, not the matrix product).
- Assuming AB = BA.
- Mixing up rows and columns when entering data, which silently transposes a matrix.
Frequently asked questions
Can I multiply a 2×3 matrix by a 3×2 matrix?
Yes. The inner sizes match (3 and 3), and the result is 2×2. The reverse order gives a 3×3 matrix.
How do I multiply a matrix by a vector?
Enter the vector as a single column, for example "1; 2" for a 2×1 column vector, as matrix B.
What is (AB)ᵀ?
It equals BᵀAᵀ, with the order reversed.
Sources: Gilbert Strang, Introduction to Linear Algebra, Wellesley-Cambridge Press — matrix multiplication · David C. Lay, Linear Algebra and Its Applications, Pearson