Matrix Multiplication

4 min read#linear-algebra

Multiplying matrices composes their transformations — do one, then the other — and the order matters.

Contents

Matrix Multiplication

To multiply two matrices is to compose their transformations: AB is the single Linear Transformation you get by first applying B, then applying A. The strange-looking arithmetic — each entry of the product is a row of A dotted with a column of B — is exactly what is forced on you once you demand that (AB)\vec v = A(B\vec v) for every Vector \vec v.

The rule, and why it looks that way

For 2\times2 matrices,

\begin{bmatrix} a & b \\ c & d \end{bmatrix} \begin{bmatrix} e & f \\ g & h \end{bmatrix} = \begin{bmatrix} ae+bg & af+bh \\ ce+dg & cf+dh \end{bmatrix}.
(1)

The clean way to see it: the columns of B are where B sends the basis vectors. Pushing each of those columns through A gives the columns of AB. So the product's first column is A acting on B's first column — composition, column by column. For the shapes to line up, the number of columns of A must equal the number of rows of B.

Order matters

Composition is generally non-commutative: AB \neq BA. Rotating a shape and then stretching it is not the same as stretching and then rotating. The picture below applies a rotation R and a horizontal shear S to the same letter in both orders; the results disagree.

The same F under RS (rotate then shear, blue) versus SR (shear then rotate, amber). Different orders, different results — matrix multiplication does not commute.

Associative, not commutative

See also