Matrix Multiplication

Strang, Introduction to Linear Algebra (6th Edition), Section 1.4

Last Updated

18 October 2026

Draft

Key Ideas

Suppose a matrix \(B\) acts on a vector and a matrix \(A\) then acts on the result. The question of which single matrix does both steps at once is what forces the definition of the product.

Definition 1 (Matrix Product) If \(A\) is \(m \times n\) and \(B\) is \(n \times p\), then \(AB\) is the \(m \times p\) matrix with entries \[ (AB)_{ij} = \sum_{k=1}^{n} a_{ik}\, b_{kj}. \]

Column View. Column \(j\) of \(AB\) is \(A\) times column \(j\) of \(B\), so \(AB = \begin{bmatrix} A\mathbf b_1 & \cdots & A\mathbf b_p \end{bmatrix}\). Every column of \(AB\) is a combination of the columns of \(A\).

Composition View. \((AB)\mathbf x = A(B\mathbf x)\), so the matrix nearest \(\mathbf x\) acts first. The product \(AB\) means “apply \(B\), then \(A\)”.

Theorem 1 (Grouping and Order) For matrices of compatible sizes, \((AB)C = A(BC)\). In general, however, \(AB \neq BA\).

Example 1 (Swapping Columns and Rows) With \(A = \begin{bmatrix} 1 & 2 \\ 3 & 4 \end{bmatrix}\) and \(B = \begin{bmatrix} 0 & 1 \\ 1 & 0 \end{bmatrix}\), \[ AB = \begin{bmatrix} 2 & 1 \\ 4 & 3 \end{bmatrix}, \qquad BA = \begin{bmatrix} 3 & 4 \\ 1 & 2 \end{bmatrix}. \] Multiplying by \(B\) on the right swaps the columns of \(A\), and multiplying on the left swaps its rows.

Visualization

Choose a transformation for \(A\) and for \(B\). Each panel applies the two in a different order to the letter F. The dashed outline is the starting shape, the thin outline is the shape after the first matrix, and the solid outline is the result. Hover over a panel to bring the middle step forward.

Real-World Application

Two banks share a market of customers. Each month a share of Bank A’s customers moves to Bank B and a share of Bank B’s customers moves to Bank A. If \(a_k\) and \(b_k\) are the two market shares after \(k\) months, one month is one multiplication by a matrix \(P\):

\[ \begin{bmatrix} a_{k+1} \\ b_{k+1} \end{bmatrix} = \begin{bmatrix} 1 - p & q \\ p & 1 - q \end{bmatrix} \begin{bmatrix} a_k \\ b_k \end{bmatrix}, \]

where \(p\) is the share of Bank A’s customers who leave each month and \(q\) is the share of Bank B’s. Two months is \(P(P x_0) = P^2 x_0\), so a single multiplication by \(P^2\) replaces two monthly steps. With the starting rates below, 10% for Bank A and 20% for Bank B, the shares settle where \(Px = x\), at two thirds for Bank A and one third for Bank B. The rates are illustrative.

Formula Bank

Rule Statement Holds when
Size \((m \times n)(n \times p)\) gives \(m \times p\) The inner sizes agree
Entry \((AB)_{ij} = \sum_k a_{ik} b_{kj}\) Always
Columns Column \(j\) of \(AB\) is \(A\) times column \(j\) of \(B\) Always
Rows Row \(i\) of \(AB\) is row \(i\) of \(A\) times \(B\) Always
Associative \((AB)C = A(BC)\) Always
Transpose \((AB)^{\mathsf T} = B^{\mathsf T} A^{\mathsf T}\) Always
Order \(AB = BA\) Only for special pairs, not in general
Zero product \(AB = 0\) forces \(A = 0\) or \(B = 0\) Never in general

Key Notes and Nuances

  1. Order Matters. In general \(AB \neq BA\). In the example above, \(AB\) swaps the columns of \(A\) while \(BA\) swaps its rows.
  2. A Product Can Exist in One Order Only. If \(A\) is 2 by 3 and \(B\) is 3 by 4, then \(AB\) exists but \(BA\) does not.
  3. A Zero Product Does Not Need a Zero Factor. For \(A = \begin{bmatrix} 0 & 1 \\ 0 & 0 \end{bmatrix}\) and \(B = \begin{bmatrix} 1 & 0 \\ 0 & 0 \end{bmatrix}\), \(AB = 0\) while \(BA = \begin{bmatrix} 0 & 1 \\ 0 & 0 \end{bmatrix}\).
  4. Cancellation Can Fail. With the same \(A\), the matrices \(B = \begin{bmatrix} 1 & 2 \\ 0 & 0 \end{bmatrix}\) and \(C = \begin{bmatrix} 3 & 4 \\ 0 & 0 \end{bmatrix}\) give \(AB = AC = 0\) although \(B \neq C\). Cancelling \(A\) requires \(A\) to be invertible.
  5. The Binomial Formula Needs Commuting Matrices. \((A + B)^2 = A^2 + AB + BA + B^2\), which equals \(A^2 + 2AB + B^2\) only when \(AB = BA\).
  6. Reading Direction. In \((AB)\mathbf x = A(B\mathbf x)\) the matrix nearest \(\mathbf x\) acts first, so \(AB\) applies \(B\) before \(A\). I misread this at first (sample note).

Questions and Answers

Question 1 \(A\) is 2 by 3 and \(B\) is 3 by 4. What size is \(AB\), and is \(BA\) defined?

Tests the size rule. ● Solved Alone

Hint

The inner sizes must agree, and the outer sizes give the size of the product.

Answer

\(AB\) is 2 by 4. \(BA\) is not defined.

Solution

For \(AB\) the inner sizes are 3 and 3, which agree, so the product exists and has the outer sizes, 2 by 4. For \(BA\) the inner sizes are 4 and 2, which do not agree, so \(BA\) is not defined.

Question 2 Compute \(AB\) for \(A = \begin{bmatrix} 2 & 1 \\ 1 & 3 \end{bmatrix}\) and \(B = \begin{bmatrix} 1 & 0 \\ 2 & 1 \end{bmatrix}\), then check the first column with the column view.

Tests the entry rule and the column view. ● Solved Alone

Hint

Entry \((i, j)\) is row \(i\) of \(A\) multiplied by column \(j\) of \(B\).

Answer

\(AB = \begin{bmatrix} 4 & 1 \\ 7 & 3 \end{bmatrix}\)

Solution

Row 1 of \(A\) is \((2, 1)\), which gives \(2 \cdot 1 + 1 \cdot 2 = 4\) and \(2 \cdot 0 + 1 \cdot 1 = 1\). Row 2 of \(A\) is \((1, 3)\), which gives \(1 + 6 = 7\) and \(0 + 3 = 3\).

As a check, column 1 of \(AB\) should be \(A\) times \((1, 2)\), which is \((2 + 2, 1 + 6) = (4, 7)\).

Question 3 Let \(A = \begin{bmatrix} 1 & 2 & 0 \\ 0 & 1 & 1 \end{bmatrix}\) and \(B = \begin{bmatrix} 3 & 1 \\ 0 & 0 \\ 1 & 2 \end{bmatrix}\). Find the second column of \(AB\) without computing the first.

Tests the column view. ◐ Solved with a Hint

Hint

Column 2 of \(AB\) depends only on column 2 of \(B\).

Answer

\((1, 2)\)

Solution

Column 2 of \(B\) is \((1, 0, 2)\), so column 2 of \(AB\) is \(1 \cdot (1, 0) + 0 \cdot (2, 1) + 2 \cdot (0, 1) = (1, 2)\).

Question 4 \(R\) rotates the plane 90 degrees counterclockwise and \(F\) reflects it across the \(x\)-axis. Find the matrix for “reflect, then rotate” and apply it to \((1, 0)\).

Tests the composition view. ◐ Solved with a Hint

Hint

The step that happens first sits nearest the vector, so the product is \(RF\), not \(FR\).

Answer

\(RF = \begin{bmatrix} 0 & 1 \\ 1 & 0 \end{bmatrix}\), which sends \((1, 0)\) to \((0, 1)\).

Solution

\(R = \begin{bmatrix} 0 & -1 \\ 1 & 0 \end{bmatrix}\) and \(F = \begin{bmatrix} 1 & 0 \\ 0 & -1 \end{bmatrix}\). Reflecting first means \(F\) acts first, so the matrix is \(RF = \begin{bmatrix} 0 & 1 \\ 1 & 0 \end{bmatrix}\).

As a check, reflecting \((1, 0)\) leaves it at \((1, 0)\), and rotating then gives \((0, 1)\). The other order, \(FR\), sends \((1, 0)\) to \((0, -1)\).

Question 5 Prove that \((AB)^{\mathsf T} = B^{\mathsf T} A^{\mathsf T}\).

Tests the entry rule in a proof. ○ Solved after Reading the Solution

Hint

Compare entry \((i, j)\) of each side.

Solution

Entry \((i, j)\) of \((AB)^{\mathsf T}\) is entry \((j, i)\) of \(AB\), which is \(\sum_k a_{jk} b_{ki}\). Entry \((i, j)\) of \(B^{\mathsf T} A^{\mathsf T}\) is \(\sum_k (B^{\mathsf T})_{ik} (A^{\mathsf T})_{kj} = \sum_k b_{ki}\, a_{jk}\). The two sums have the same terms, so the matrices are equal.

Sample record. I learnt this section with the tutor asking questions, took one hint each on Questions 3 and 4, and re-solved Question 5 the day after reading its solution.