# Matrix multiplication: interpreting and understanding the process

I have just watched the first half of the 3rd lecture of Gilbert Strang on the open course ware with link:

http://ocw.mit.edu/courses/mathematics/18-06-linear-algebra-spring-2010/video-lectures/

It seems that with a matrix multiplication $AB=C$, that the entries as scalars, are formed from the dot product computations of the rows of $A$ with the columns of $B$. Visual interpretations from mechanics of overlpaing forces come to mind immediately because that is the source for the dot product (inner product).

I see the rows of $C$ as being the dot product of the rows of $B$, with the dot product of a particular row of $A$. Similar to the above and it is easy to see this from the individual entries in the matrix $C$ as to which elements change to give which dot products.

For understanding matrix multiplication there is the geometrical interpretation, that the matrix multiplication is a change in the reference system since matrix $B$ can be seen as a transormation operator for rotation, scalling, reflection and skew. It is easy to see this by constructing example $B$ matrices with these effects on $A$. This decomposition is a strong argument and is strongly convincing of its generality. This interpreation is strong but not smooth because I would find smoother an explanation which would be an interpretation begining from the dot product of vectors and using this to explain the process and the interpretation of the results (one which is a bit easier to see without many examples of the putting numbers in and seeing what comes out which students go through).

I can hope that sticking to dot products throughout the explanation and THEN seeing how these can be seen to produce scalings, rotations, and skewings would be better. But, after some simple graphical examples I saw this doesn’t work as the order of the columns in matrix $B$ are important and don’t show in the graphical representation.

The best explanation I can find is at Yahoo Answers. It is convincing but a bit disappointing (explains why this approach preserves the “composition of linear transformations”; thanks @Arturo Magidin). So the question is: Why does matrix multiplication happen as it does, and are there good practical examples to support it? Preferably not via rotations/scalings/skews (thanks @lhf).

Some comments first. There are several serious confusions in what you write. For example, in the third paragraph, having seen that the entries of $$ABAB$$ are obtained by taking the dot product of the corresponding row of $$AA$$ with column of $$BB$$, you write that you view $$ABAB$$ as a dot product of rows of $$BB$$ and rows of $$AA$$. It’s not.

For another example, you talk about matrix multiplication “happening”. Matrices aren’t running wild in the hidden jungles of the Amazon, where things “happen” without human beings. Matrix multiplication is defined a certain way, and then the definition is why matrix multiplication is done the way it is done. You may very well ask why matrix multiplication is defined the way it is defined, and whether there are other ways of defining a “multiplication” on matrices (yes, there are; read further), but that’s a completely separate question. “Why does matrix multiplication happen the way it does?” is pretty incoherent on its face.

Another example of confusion is that not every matrix corresponds to a “change in reference system”. This is only true, viewed from the correct angle, for invertible matrices.

Standard matrix multiplication. Matrix multiplication is defined the way it is because it corresponds to composition of linear transformations. Though this is valid in extremely great generality, let’s focus on linear transformations $$T:Rn→RmT\colon \mathbb{R}^n\to\mathbb{R}^m$$. Since linear transformations satisfy $$T(αx+βy)=αT(x)+βT(y)T(\alpha\mathbf{x}+\beta\mathbf{y}) = \alpha T(\mathbf{x})+\beta T(\mathbf{y})$$, if you know the value of $$TT$$ at each of $$e1,…,en\mathbf{e}_1,\ldots,\mathbf{e}_n$$, where $$eni\mathbf{e}^n_i$$ is the (column) $$nn$$-vector that has $$00$$s in each coordinate except the $$ii$$th coordinate where it has a $$11$$, then you know the value of $$TT$$ at every single vector of $$Rn\mathbb{R}^n$$.

So in order to describe the value of $$TT$$, I just need to tell you what $$T(ei)T(\mathbf{e}_i)$$ is. For example, we can take
$$T(ei)=(a1ia2i⋮ami).T(\mathbf{e}_i) = \left(\begin{array}{c}a_{1i}\\a_{2i}\\ \vdots\\ a_{mi}\end{array}\right).$$
Then, since
$$(k1k2⋮kn)=k1e1+⋯+knen,\left(\begin{array}{c}k_1\\k_2\\ \vdots\\k_n\end{array}\right) = k_1\mathbf{e}_1 + \cdots +k_n\mathbf{e}_n,$$ we have
$$T(k1k2⋮kn)=k1T(e1)+⋯+knT(en)=k1(a11a21⋮am1)+⋯+kn(a1na2n⋮amn).T\left(\begin{array}{c}k_1\\k_2\\ \vdots\\ k_n\end{array}\right) = k_1T(\mathbf{e}_1) + \cdots +k_nT(\mathbf{e}_n) = k_1\left(\begin{array}{c}a_{11}\\a_{21}\\ \vdots\\a_{m1}\end{array}\right) + \cdots + k_n\left(\begin{array}{c}a_{1n}\\a_{2n}\\ \vdots\\ a_{mn}\end{array}\right).$$

It is very fruitful, then to keep track of the $$aija_{ij}$$ in some way, and given the expression above, we keep track of them in a matrix, which is just a rectangular array of real numbers. We then think of $$TT$$ as being “given” by the matrix
$$(a11a12⋯a1na21a22⋯a2n⋮⋮⋱⋮am1am2⋯amn).\left(\begin{array}{cccc} a_{11} & a_{12} & \cdots & a_{1n}\\ a_{21} & a_{22} & \cdots & a_{2n}\\ \vdots & \vdots & \ddots & \vdots\\ a_{m1} & a_{m2} & \cdots & a_{mn} \end{array}\right).$$
If we want to keep track of $$TT$$ this way, then for an arbitrary vector $$x=(x1,…,xn)t\mathbf{x} = (x_1,\ldots,x_n)^t$$ (the $$t{}^t$$ means “transpose”; turn every rown into a column, every column into a row), then we have that $$T(x)T(\mathbf{x})$$ corresponds to:
$$(a11a12⋯a1na21a22⋯a2n⋮⋮⋱⋮am1am2⋯amn)(x1x2⋮xn)=(a11x1+a12x2+⋯+a1nxna21x1+a22x2+⋯+a2nxn⋮am1x1+am2x2+⋯+amnxn).\left(\begin{array}{cccc} a_{11} & a_{12} & \cdots & a_{1n}\\ a_{21} & a_{22} & \cdots & a_{2n}\\ \vdots & \vdots & \ddots & \vdots\\ a_{m1} & a_{m2} & \cdots & a_{mn} \end{array}\right) \left(\begin{array}{c} x_1\\x_2\\ \vdots\\ x_n\end{array}\right) = \left(\begin{array}{c} a_{11}x_1 + a_{12}x_2 + \cdots + a_{1n}x_n\\ a_{21}x_1 + a_{22}x_2 + \cdots + a_{2n}x_n\\ \vdots\\ a_{m1}x_1 + a_{m2}x_2 + \cdots + a_{mn}x_n \end{array}\right).$$

What happens when we have two linear transformations, $$T:Rn→RmT\colon \mathbb{R}^n\to\mathbb{R}^m$$ and $$S:Rp→RnS\colon\mathbb{R}^p\to\mathbb{R}^n$$? If $$TT$$ corresponds as above to a certain $$m×nm\times n$$ matrix, then $$SS$$ will likewise correspond to a certain $$n×pn\times p$$ matrix, say
$$(b11b12⋯b1pb21b22⋯b2p⋮⋮⋱⋮bn1bn2⋯bnp).\left(\begin{array}{cccc} b_{11} & b_{12} & \cdots & b_{1p}\\ b_{21} & b_{22} & \cdots & b_{2p}\\ \vdots & \vdots & \ddots & \vdots\\ b_{n1} & b_{n2} & \cdots & b_{np} \end{array}\right).$$
What is $$T∘ST\circ S$$? First, it is a linear transformation because composition of linear transformations yields a linear transformation. Second, it goes from $$Rp\mathbb{R}^p$$ to $$Rm\mathbb{R}^m$$, so it should correspond to an $$m×pm\times p$$ matrix. Which matrix? If we let $$f1,…,fp\mathbf{f}_1,\ldots,\mathbf{f}_p$$ be the (column) $$pp$$-vectors given by letting $$fj\mathbf{f}_j$$ have $$00$$s everywhere and a $$11$$ in the $$jj$$th entry, then the matrix above tells us that
$$S(fj)=(b1jb2j⋮bnj)=b1je1+⋯+bnjen.S(\mathbf{f}_j) = \left(\begin{array}{c}b_{1j}\\b_{2j}\\ \vdots \\b_{nj}\end{array}\right) = b_{1j}\mathbf{e}_1+\cdots + b_{nj}\mathbf{e}_n.$$

So, what is $$T∘S(fj)T\circ S(\mathbf{f}_j)$$? This is what goes in the $$jj$$th column of the matrix that corresponds to $$T∘ST\circ S$$. Evaluating, we have:
T∘S(fj)=T(S(fj)) =T(b1je1+⋯+bnjen) =b1jT(e1)+⋯+bnjT(en) =b1j(a11 a21 ⋮ am1)+⋯+bnj(a1na2n ⋮ amn) =(a11b1j+a12b2j+⋯+a1nbnj a21b1j+a22b2j+⋯+a2nbnj ⋮ am1b1j+am2b2j+⋯+amnbnj).\begin{align*} T\circ S(\mathbf{f}_j) &= T\Bigl( S(\mathbf{f}_j)\Bigr)\\\ &= T\Bigl( b_{1j}\mathbf{e}_1 + \cdots + b_{nj}\mathbf{e}_n\Bigr)\\\ &= b_{1j} T(\mathbf{e}_1) + \cdots + b_{nj}T(\mathbf{e}_n)\\\ &= b_{1j}\left(\begin{array}{c} a_{11}\\\ a_{21}\\\ \vdots\\\ a_{m1}\end{array}\right) + \cdots + b_{nj}\left(\begin{array}{c} a_{1n}\\a_{2n}\\\ \vdots\\\ a_{mn}\end{array}\right)\\\ &= \left(\begin{array}{c} a_{11}b_{1j} + a_{12}b_{2j} + \cdots + a_{1n}b_{nj}\\\ a_{21}b_{1j} + a_{22}b_{2j} + \cdots + a_{2n}b_{nj}\\\ \vdots\\\ a_{m1}b_{1j} + a_{m2}b_{2j} + \cdots + a_{mn}b_{nj} \end{array}\right). \end{align*}
So if we want to write down the matrix that corresponds to $$T∘ST\circ S$$, then the $$(i,j)(i,j)$$th entry will be
$$ai1b1j+ai2b2j+⋯+ainbnj.a_{i1}b_{1j} + a_{i2}b_{2j} + \cdots + a_{in}b_{nj}.$$
So we define the “composition” or product of the matrix of $$TT$$ with the matrix of $$SS$$ to be precisely the matrix of $$T∘ST\circ S$$. We can make this definition without reference to the linear transformations that gave it birth: if the matrix of $$TT$$ is $$m×nm\times n$$ with entries $$aija_{ij}$$ (let’s call it $$AA$$); and the matrix of $$SS$$ is $$n×pn\times p$$ with entries $$brsb_{rs}$$ (let’s call it $$BB$$), then the matrix of $$T∘ST\circ S$$ (let’s call it $$A∘BA\circ B$$ or $$ABAB$$) is $$m×pm\times p$$ and with entries $$ckℓc_{k\ell}$$, where
$$ckℓ=ak1b1ℓ+ak2b2ℓ+⋯+aknbnℓc_{k\ell} = a_{k1}b_{1\ell} + a_{k2}b_{2\ell} + \cdots + a_{kn}b_{n\ell}$$
by definition. Why? Because then the matrix of the composition of two functions is precisely the product of the matrices of the two functions. We can work with the matrices directly without having to think about the functions.

In point of fact, there is nothing about the dot product which is at play in this definition. It is essentially by happenstance that the $$(i,j)(i,j)$$ entry can be obtained as a dot product of something. In fact, the $$(i,j)(i,j)$$th entry is obtained as the matrix product of the $$1×n1\times n$$ matrix consisting of the $$ii$$th row of $$AA$$, with the $$n×1n\times 1$$ matrix consisting of the $$jj$$th column of $$BB$$. Only if you transpose this column can you try to interpret this as a dot product. (In fact, the modern view is the other way around: we define the dot product of two vectors as a special case of a more general inner product, called the Frobenius inner product, which is defined in terms of matrix multiplication, $$⟨x,y⟩=trace(¯ytx)\langle\mathbf{x},\mathbf{y}\rangle =\mathrm{trace}(\overline{\mathbf{y}^t}\mathbf{x})$$).

And because product of matrices corresponds to composition of linear transformations, all the nice properties that composition of linear functions has will automatically also be true for product of matrices, because products of matrices is nothing more than a book-keeping device for keeping track of the composition of linear transformations. So $$(AB)C=A(BC)(AB)C = A(BC)$$, because composition of functions is associative. $$A(B+C)=AB+ACA(B+C) = AB + AC$$ because composition of linear transformations distributes over sums of linear transformations (sums of matrices are defined entry-by-entry because that agrees precisely with the sum of linear transformations). $$A(αB)=α(AB)=(αA)BA(\alpha B) = \alpha(AB) = (\alpha A)B$$, because composition of linear transformations behaves that way with scalar multiplication (products of matrices by scalar are defined the way they are precisely so that they will correspond to the operation with linear transformations).

So we define product of matrices explicitly so that it will match up composition of linear transformations. There really is no deeper hidden reason. It seems a bit incongruous, perhaps, that such a simple reason results in such a complicated formula, but such is life.

Another reason why it is somewhat misguided to try to understand matrix product in terms of dot product is that the matrix product keeps track of all the information lying around about the two compositions, but the dot product loses a lot of information about the two vectors in question. Knowing that $$x⋅y=0\mathbf{x}\cdot\mathbf{y}=0$$ only tells you that $$x\mathbf{x}$$ and $$y\mathbf{y}$$ are perpendicular, it doesn’t really tell you anything else. There is a lot of informational loss in the dot product, and trying to explain matrix product in terms of the dot product requires that we “recover” all of this lost information in some way. In practice, it means keeping track of all the original information, which makes trying to shoehorn the dot product into the explanation unnecessary, because you will already have all the information to get the product directly.

Examples that are not just “changes in reference system”. Note that any linear transformation corresponds to a matrix. But the only linear transformations that can be thought of as “changes in perspective” are the linear transformations that map $$Rn\mathbb{R}^n$$ to itself, and which are one-to-one and onto. There are lots of linear transformations that aren’t like that. For example, the linear transformation $$TT$$ from $$R3\mathbb{R}^3$$ to $$R2\mathbb{R}^2$$ defined by
$$T(abc)=(b2c)T\left(\begin{array}{c} a\\b\\c\end{array}\right) = \left(\begin{array}{c}b\\2c\end{array}\right)$$
is not a “change in reference system” (because lots of nonzero vectors go to zero, but there is no way to just “change your perspective” and start seeing a nonzero vector as zero) but is a linear transformation nonetheless. The corresponding matrix is $$2×32\times 3$$, and is
$$(010002).\left(\begin{array}{cc} 0 & 1 & 0\\ 0 & 0 & 2 \end{array}\right).$$
Now consider the linear transformation $$U:R2→R2U\colon\mathbb{R}^2\to\mathbb{R}^2$$ given by
$$U(xy)=(3x+2y9x+6y).U\left(\begin{array}{c}x\\y\end{array}\right) = \left(\begin{array}{c}3x+2y\\ 9x + 6y\end{array}\right).$$
Again, this is not a “change in perspective”, because the vector $$\binom{2}{-3}\binom{2}{-3}$$ is mapped to $$\binom{0}{0}\binom{0}{0}$$. It has a matrix, $$2\times 22\times 2$$, which is
$$\left(\begin{array}{cc} 3 & 2\\ 9 & 6 \end{array}\right).\left(\begin{array}{cc} 3 & 2\\ 9 & 6 \end{array}\right).$$
So the composition $$U\circ TU\circ T$$ has matrix:
$$\left(\begin{array}{cc} 3 & 2\\ 9 & 6 \end{array}\right) \left(\begin{array}{ccc} 0 & 1 & 0\\ 0 & 0 & 2 \end{array}\right) = \left(\begin{array}{ccc} 0 & 3 & 4\\ 0 & 9 & 12 \end{array}\right),\left(\begin{array}{cc} 3 & 2\\ 9 & 6 \end{array}\right) \left(\begin{array}{ccc} 0 & 1 & 0\\ 0 & 0 & 2 \end{array}\right) = \left(\begin{array}{ccc} 0 & 3 & 4\\ 0 & 9 & 12 \end{array}\right),$$
which tells me that
$$U\circ T\left(\begin{array}{c}x\\y\\z\end{array}\right) = \left(\begin{array}{c} 3y + 4z\\ 9y+12z\end{array}\right).U\circ T\left(\begin{array}{c}x\\y\\z\end{array}\right) = \left(\begin{array}{c} 3y + 4z\\ 9y+12z\end{array}\right).$$

Other matrix products. Are there other ways to define the product of two matrices? Sure. There’s the Hadamard product, which is the “obvious” thing to try: you can multiply two matrices of the same size (and only of the same size), and you do it entry by entry, just the same way that you add two matrices. This has some nice properties, but it has nothing to do with linear transformations. There’s the Kronecker product, which takes an $$m\times nm\times n$$ matrix times a $$p\times qp\times q$$ matrix and gives an $$mp\times nqmp\times nq$$ matrix. This one is associated to the tensor product of linear transformations. They are defined differently because they are meant to model other operations that one does with matrices or vectors.