# Order of matrix multiplication intuition

Let $A$, $B$ be linear transformations $\mathbb{R}^2 \to \mathbb{R}^2$, for example let $A$ be a rotation and $B$ a scale.

Let $\mathbf{v}$ be a 2 component column vector that I want to transform by the composition of these transformations, e.g. first rotate, then scale, $B(A(\mathbf{v}))$.

If I represent these transformations by matrices $\mathbf{A}$ and $\mathbf{B}$ I am never sure in what order to multiply them to get the composition $B(A)$ and not $A(B)$. I either have to look it up or derive it.

I understand what happens when a square matrix is multiplied by a column vector, the vector just gets transformed to the coordinate system defined by the columns of the matrix. Is there a way of thinking about matrix multiplication that would make it obvious that

$$B(A(\mathbf{v})) = (\mathbf{BA})\mathbf{v}$$

• $B(A(\mathbf{v})) = B(\mathbf{A}\,\mathbf{v}) = \mathbf{B}\,(\mathbf{A}\,\mathbf{v}) = (\mathbf{B}\,\mathbf{A})\,\mathbf{v}$? – Tavian Barnes Aug 9 '14 at 22:44

Indeed! The multiplication $BA$ scales each column vector of $A$. Thus the basis given in $A$ is transformed into a scaled basis in $BA$ so when carrying out the multiplication $(BA)v$ the vector $v$ will be represented in the new basis in $BA$ which has all its vectors scaled.

If you think about multiplying by a matrix on the left as applying a transformation, then the transformation $B(A(v))$ would be represented in multiplication notation as $BAv$. $v$ gets multiplied by $A$ first and then $B$, which is what you want. By associativity of multiplication, you could also multiply $BA$ first and then multiply this matrix with $v$.

Given a linear transformation $M:\mathbb R^n \to \mathbb R^m$, we can describe $M$ concisely by writing down the matrix $\mathbf M$ whose $i$th column is $M(e_i)$, where $e_i$ is the $i$th standard basis vector. The matrix $\mathbf M$ could be called the matrix description of $M$ (with respect to the standard bases of $\mathbb R^m$ and $\mathbb R^n$).

Conversely, given an $m \times n$ matrix $\mathbf M$, there is a corresponding linear transformation $M$ which is described by $\mathbf M$.

If $v$ is an $n \times 1$ column vector, we can define the matrix-vector product $\mathbf M v$ by \begin{equation*} \mathbf M v = M(v). \end{equation*} Note that if $v = v_1 e_1 + \cdots + v_n e_n$, then \begin{align*} M(v) &= M(v_1 e_1 + \cdots + v_n e_n) \\ &= v_1 M(e_1) + \cdots + v_n M(e_n) \\ &= v_1 \mathbf M_1 + \cdots + v_n \mathbf M_n. \end{align*} So $\mathbf M v$ is a linear combination of the columns of $\mathbf M$, which is a very useful way to think about matrix-vector multiplication.

If $\mathbf B$ and $\mathbf A$ are matrices, I think it's nice to define the matrix product $\mathbf B \mathbf A$ to be the matrix such that \begin{equation*} (B \circ A)(v) = (\mathbf B \mathbf A)v \end{equation*} for all $v$.

The formula for the entries of $\mathbf B \mathbf A$ can then be discovered by choosing $v = e_i$, the $i$th standard basis vector.

The $i$th column of $\mathbf B \mathbf A$ is \begin{align} (\mathbf B \mathbf A)_i &= (B \circ A)(e_i) \\ &= B(A(e_i)) \\ &= B(\mathbf A_i) \\ &= \mathbf B \mathbf A_i \end{align} where $\mathbf A_i$ is the $i$th column of $\mathbf A$. This is the standard formula for matrix multiplication.

• It might be worth picturing $A$ as being partitioned into columns. – user14972 Aug 9 '14 at 22:38

A different way to think about it is that coordinate representation of linear transformations and vectors, along with their arithmetic is defined precisely so that we have an equation

$$[B(A(v))] = [B][A][v]$$

where I've used $[Q]$ to denote the coordinate representation of $Q$. If this equation were not true, we would have thrown everything away and picked a new way to represent coordinates.

This equation follows, incidentally, from the corresponding fact for just multiplying a matrix by a vector (along with associativity):

$$[B(A(v))] = [B] [A(v)] = [B][A][v]$$

If we also use the facts $[B(A(v))] = [(B \circ A)(v)] = [B \circ A][v]$ and that if $Cw = Dw$ for all vectors $w$ then $C = D$, then we obtain $[B \circ A] = [B][A]$.