Matrix Multiplication
calculator.
Multiply two matrices, with each entry of AB worked out as a row times a column.
- Multiplications
- 12
- Additions
- 8
- AB = BA?
- Sizes differ
A is 2×3 and B is 3×2, so the inner sizes match and AB is 2×2. Each entry takes 3 multiplications. BA exists too, but it is 3×3 and AB is 2×2, so they cannot be equal.
Follow one entry
B sits above AB and A to its left. Row 1 of A, (2, 3, 4), and column 2 of B, (1,000, 100, 10), are shaded. They meet at entry c₁₂ of AB, which is 2,340.
Working
- 1Check the sizes(2×3) times (3×2): the inner sizes are both 3, so AB is 2×2.
- 2Row 1 of A times column 1 of Bc₁₁ =(2)(0)+(3)(1)+(4)(0)=0+(3)+(0)=3
- 3Row 1 of A times column 2 of Bc₁₂ =(2)(1,000)+(3)(100)+(4)(10)=2,000+(300)+(40)=2,340
- 4Row 2 of A times column 1 of Bc₂₁ =(1)(0)+(0)(1)+(0)(0)=0+(0)+(0)=0
- 5Row 2 of A times column 2 of Bc₂₂ =(1)(1,000)+(0)(100)+(0)(10)=1,000+(0)+(0)=1,000
- 6Check: the column sums of A times the row sums of B give the total of AB(3)(1,000)+(3)(101)+(4)(10)=3,343and the entries of AB add up to3,343
The other order, BA
BA is 3×3 and AB is 2×2, so they cannot be equal.
Type or paste the matrices
How it's worked out
To multiply A by B, the number of columns of A must equal the number of rows of B. An m by k matrix times a k by p matrix gives an m by p matrix. The two inner sizes must match, and the two outer sizes give the size of the answer.
The row-column rule. The entry in row i and column j of AB is row i of A times column j of B. Multiply the two lists entry by entry and add the products. Interactive Linear Algebra gives the same rule.
Column by column. The same book defines AB one column at a time: column j of AB is A times column j of B. That view helps when B holds vectors you want to transform, such as points to rotate.
The work. Each entry needs k multiplications and k − 1 additions, and AB has m times p entries. Two 5 by 5 matrices take 125 multiplications and 100 additions.
A quick check. Add up each column of A and each row of B. The first list times the second, entry by entry and summed, equals the total of every entry in AB. A single wrong entry breaks that match, so the steps end with it.
Worked examples
Dana totals sales for two stores
Dana runs two stores that sell three products. Each row of A is a store and each column is a product, with the units sold. Each row of B is a product, with its price and its cost per unit in dollars.
A is 2 by 3 and B is 3 by 2, so AB is 2 by 2. Row 1 of A times column 1 of B is 10 × 2.50 + 4 × 4 + 6 × 1.50, which is $50.00 of revenue for store 1. Its cost is $23.50. Store 2 brings in $47.00 at a cost of $22.25.
The check holds: the four totals add up to 142.75, and so do the column sums of A times the row sums of B. The product needs 12 multiplications in all.
Turning a point a quarter turn
The matrix below turns the plane 90 degrees counterclockwise about the origin. To move the point (3, 1), write it as a column and multiply.
The point lands at (−1, 3). Multiply again and it lands at (−3, −1), a half turn from where it began. A 2 by 2 matrix times a 2 by 1 column is a 2 by 1 column, so the answer is a point again.
Swapping the order changes the answer
Both are 2 by 2, but no entry matches. The top left of AB is 1 × 5 + 2 × 7 = 19, while the top left of BA is 5 × 1 + 6 × 3 = 23. Order matters for almost every pair of matrices, so always multiply in the order the problem gives.
Reading your result
Read the size first. If the inner sizes differ, there is no product. A 2 by 3 matrix cannot be multiplied by another 2 by 3, though it can be multiplied by a 3 by 2 or a 3 by 5.
A row times a column is one number. The 1 by 3 row (1, 2, 3) times the column (4, 5, 6) gives the 1 by 1 matrix 32, the dot product. The other way round, a column times a row gives a full grid: (4, 5) as a column times (1, 2) as a row has rows 4, 8 and 5, 10.
The laws that still hold. (AB)C = A(BC), so a chain of products can be grouped either way. A(B + C) = AB + AC as well. The transpose of AB is the transpose of B times the transpose of A, with the order reversed.
Common mistakes
- Multiplying entry by entry. AB is not the grid of a₁₁b₁₁, a₁₂b₁₂ and so on. Each entry uses a whole row of A and a whole column of B.
- Using a column of A. The rule is always row of the first matrix, column of the second. Mixing them up gives the product in the other order.
- Cancelling a matrix. AB = AC does not mean B = C. Two nonzero matrices can even multiply to zero: the matrix of all 1s times the one with rows 1, −1 and −1, 1 gives rows 0, 0 and 0, 0.
- Expanding (A + B)² as A² + 2AB + B². The middle is AB + BA, and those two are usually different.