Matrix multiplication
For A of size m×n and B of size n×p, AB has size m×p. Each entry is a row-column dot product. Each column of AB is also a linear combination of the columns of A.
What you will learn
- Check dimensions
- Compute row-column products
- Explain why AB can differ from BA
Dimensions before arithmetic
- A=[[1,2,-1],[0,1,3],[2,-2,1]]
- B=[[2,0,1],[1,3,-1],[0,2,2]]
- Both are 3×3, so each row and column pair contains three entries. The result has nine entries.
Nine row-column calculations
- (AB)11 = 1×2 + 2×1 + (-1)×0 = 4
- (AB)12 = 1×0 + 2×3 + (-1)×2 = 4
- (AB)13 = 1×1 + 2×(-1) + (-1)×2 = -3
- (AB)21 = 0×2 + 1×1 + 3×0 = 1
- (AB)22 = 0×0 + 1×3 + 3×2 = 9
- (AB)23 = 0×1 + 1×(-1) + 3×2 = 5
- (AB)31 = 2×2 + (-2)×1 + 1×0 = 2
- (AB)32 = 2×0 + (-2)×3 + 1×2 = -4
- (AB)33 = 2×1 + (-2)×(-1) + 1×2 = 6
Read the same product by columns
- AB=[[4,4,-3],[1,9,5],[2,-4,6]]
- B has first column (2,1,0). Therefore (AB)[:,1]=2a₁+a₂=(4,1,2).
- Its second column is (0,3,2), so (AB)[:,2]=3a₂+2a₃=(4,9,−4).
- Its third column is (1,−1,2), so (AB)[:,3]=a₁−a₂+2a₃=(−3,5,6).
Why order matters
- (AB)₁₂=1×0 + 2×3 + (-1)×2=4. (BA)₁₂=2×2 + 0×1 + 1×(-2)=2. Therefore AB≠BA.
- For a column input x, ABx applies B first and A second. BAx reverses those operations.
- I commutes with every square matrix of the same size; some pairs do commute.
Fill in the reasoning
- A matrix is a rectangular table. In A=(aᵢⱼ), i chooses the row and j chooses the column. A 2×3 matrix has two rows and three columns.
- A 2×3 matrix times a 3×4 matrix gives a 2×4 matrix. A 2×3 matrix times a 2×4 matrix is undefined: 3≠2.
Objective 1: Check dimensions
- What is the size of (2×3)(3×4)?
- The shared dimension is 3; the output is 2×4.
Objective 2: Compute row-column products
- Compute (AB)₁₂ in the main example.
- Row 1 dotted with column 2 gives 1·0+2·3+(−1)·2=4.
Objective 3: Explain why AB can differ from BA
- Prove AB≠BA using one entry.
- (AB)₁₂=4 and (BA)₁₂=2, so the matrices differ.
A common mistake
AB usually differs from BA; this does not mean they can never be equal. Dimensions must be checked before either product.
Review first
Continue learning
Matrix operations and inverses · Inverse matrices and solving Ax=b
Interactive diagnosis and practice load in the learning app. You can read these lesson notes without JavaScript.