Linear Algebra · Matrix multiplication

Matrix multiplication

The product AB of two matrices is the matrix of the composition “first B, then A”: (AB)x = A(Bx) for every vector x. Its j-th column is A applied to the j-th column of B, a combination of A’s columns with B’s numbers as the amounts, and the familiar row × column rule is that combination written in coordinates. Because the second map works on what the first one produced, the order matters: in general AB ≠ BA.

Matrix multiplication in this visualization

A 2 × 2 matrix is a linear map of the plane, and its columns are where it sends ı^=(1,0)\hat\imath = (1, 0) and ȷ^=(0,1)\hat\jmath = (0, 1). The product ABAB is the matrix of doing two maps in a row, first BB and then AA: (AB)x=A(Bx)(AB)x = A(Bx) for every vector xx. The matrix next to xx acts first, so a product is read from right to left.

The page’s default: first B, then A
AB=(1102)(2−111)=(3022)AB = \begin{pmatrix} 1 & 1 \\ 0 & 2 \end{pmatrix} \begin{pmatrix} 2 & -1 \\ 1 & 1 \end{pmatrix} = \begin{pmatrix} 3 & 0 \\ 2 & 2 \end{pmatrix}

In the order ABAB, the left picture shows BB on the standard grid: ı^\hat\imath and ȷ^\hat\jmath as faint dashed arrows, and their images b1b_1 and b2b_2, the columns of BB, in blue. The right picture shows AA: the grid it makes of the standard grid, its columns a1a_1 and a2a_2 in ink, and the columns of the product, Ab1Ab_1 and Ab2Ab_2, in blue. The flag shows the same two steps on a shape. Each picture has its own scale, because a product can reach far beyond its factors.

Where does a column of ABAB come from? BB sends ı^\hat\imath to b1=(b11,b21)b_1 = (b_{11}, b_{21}), which is b11b_{11} steps of ı^\hat\imath and b21b_{21} steps of ȷ^\hat\jmath. AA is linear, so it sends that point to the same steps of its own columns: b11b_{11} of a1a_1 followed by b21b_{21} of a2a_2. It only reads the two numbers of b1b_1, not how b1b_1 was made. On the right the selected product column is drawn as this recipe, two thin legs along a1a_1 and a2a_2 that end at the blue arrow. Drag b1b_1 on the left and the legs stretch and shrink with its numbers.

Each column of AB is A applied to the same column of B
(AB)j=A bj=b1j a1+b2j a2Ab1=2(10)+1(12)=(32)\begin{gathered} (AB)_j = A\,b_j = b_{1j}\,a_1 + b_{2j}\,a_2 \\[0.6ex] Ab_1 = 2\begin{pmatrix} 1 \\ 0 \end{pmatrix} + 1\begin{pmatrix} 1 \\ 2 \end{pmatrix} = \begin{pmatrix} 3 \\ 2 \end{pmatrix} \end{gathered}

The rule taught as row times column is this recipe written in coordinates. The x-coordinate of AbjAb_j adds up the horizontal parts of its two legs, a11b1j+a12b2ja_{11}b_{1j} + a_{12}b_{2j}: row 1 of AA against column jj of BB. The y-coordinate comes from row 2 in the same way. Row × column draws these parts along the axes, each labelled with its product.

Row × column, in general and for the default’s first column
(AB)ij=ai1b1j+ai2b2j(AB)1=(1⋅2+1⋅1, 0⋅2+2⋅1)=(3, 2)\begin{gathered} (AB)_{ij} = a_{i1}b_{1j} + a_{i2}b_{2j} \\[0.6ex] (AB)_1 = (1\cdot 2 + 1\cdot 1,\ 0\cdot 2 + 2\cdot 1) = (3,\ 2) \end{gathered}

Order matters because the second map works on what the first one produced. Turn by a quarter and then shear: ı^\hat\imath goes to (0,1)(0, 1) and then to (1,1)(1, 1). Shear first and then turn: ı^\hat\imath stays at (1,0)(1, 0) and then goes to (0,1)(0, 1). Once the other order has been composed too, its result appears on the right as dashed blue arrows, until A or B changes. Some pairs do commute. Two turns of the plane about the origin add their angles in either order.

Area factors multiply. BB turns the unit square into a parallelogram of area ∣det⁡B∣|\det B|, and AA then multiplies every area by ∣det⁡A∣|\det A|. With signs, det⁡(AB)=det⁡A⋅det⁡B\det(AB) = \det A\cdot\det B, and because numbers commute, det⁡(AB)=det⁡(BA)\det(AB) = \det(BA) even when AB≠BAAB \ne BA. In the default, det⁡A=2\det A = 2 and det⁡B=3\det B = 3, so both products have determinant 6.

Signed area factors multiply, in either order
det⁡(AB)=det⁡A⋅det⁡B=det⁡(BA)\det(AB) = \det A \cdot \det B = \det(BA)

Things to notice

  • In the order ABAB, Compose moves ı^\hat\imath to b1b_1 along a straight line. The path only shows where ı^\hat\imath ends up, not how BB moves the plane.
  • A negative area factor is not a negative area. It says that the map flips the plane over, and areas are multiplied by its absolute value.

Controls

  • In the order ABAB, pointing at pp on the left marks ApAp on the right with a small cyan ring.

Related

Further reading: Wikipedia: Matrix multiplication; OpenStax, College Algebra 2e, 7.5 Matrices and Matrix Operations.