# Is there a quick/easy way to determine which order you should multiply matrices to combine two transformations?

For example you are given two matrices. One which transforms Shape 1 to Shape 2 and the other which transforms Shape 2 to Shape 3. You are asked to find the matrix which transforms Shape 1 to Shape 3. Multiplying both matrices in different orders will give different results, only one result is correct. Rather than checking through your results to find out the correct order, is there a quick/easy way to find out?

If this makes no sense, please tell me what makes no sense. Regards Tom

• In many situations we represent the linear transformation by multiplying the coordinates of points as if the coordinates were columns and the matrix multiplies them on their left, eg. $Av$. The result of applying first transformation represented by $A$ and then transformation represented by $B$ would be $BAv$. However your application may have the opposite convention. Check the documentation to see if matrices multiply vectors on the left or on the right. – hardmath Feb 8 '15 at 15:07
• A matrix represents a transformation with respect to some conventions. There are linear transformations and a larger class, affine transformations, which can be represented by matrices in a way that lends itself to applying matrix multiplication to implement the transformation. – hardmath Feb 8 '15 at 20:02

You look how a single matrix Transformation acts on a vector: If a vector $v$ transforms as $v \rightarrow Av$ under a matrix $A$ then, for some other matrices $A_1,A_2,...$ you have the transformations $v \rightarrow ...A_2 A_1 A v$ (last Transformation first!). If the vector transforms as $v \rightarrow vA$ then by Iteration it follows: $v \rightarrow vAA_1A_2...$ (first Transformation first!).

• While it is important to clarify what convention is used to represent transformations by matrix multiplication, I'm not sure this alone is enough to answer the question the OP has in mind. He seems to have some "shapes" and wants to determine which order the transformations are to be applied to achieve a particular result. – hardmath Feb 8 '15 at 15:11
• @hardmath No, I want to determine which order the transformations should be multiplied (because that is how you combine transformations, right?). Knowing which order they should be multiplied gives only 1 mark on this exam so I assumed there is an easy way to know which order. No need for the sarcasm. – Thomas Winkworth Feb 8 '15 at 15:37
• No sarcasm is intended. Your Question uses the notion of "shapes" without illustration or detail, so only you can appreciate if the correct solution depends on seeing them. Knowing that a transformation maps a Square to itself does determine the transformation or its matrix representation. – hardmath Feb 8 '15 at 15:45
• Further note that my Comment states the same point in kryomaxim's Answer, that order of multiplication depends on a convention of representation. – hardmath Feb 8 '15 at 15:49
• In which scenario would the correct solution depend on illustration and detail of the shape? Are you suggesting that the location and size of Shape 1 has an effect on the order in which you should multiply the transformations to get Shape 3? – Thomas Winkworth Feb 8 '15 at 16:06

A matrix does not transform some shape into another shape but a full plane (or space) to some other plane (or space). The usual convention is the following (check your manual whether it applies in your case):

Points are coordinate $n$-tuples $x=(x_1,x_2,\ldots x_n)$. In matrix language these $n$-tuples are written as column vectors $$[x]:=\left[\matrix{x_1\cr x_2\cr \vdots\cr x_n\cr}\right]\ .$$ A linear map $A:\>{\Bbb R}^n\to{\Bbb R}^m$ throwing points $x\in{\mathbb R}^n$ to image points $y:=Ax\in{\mathbb R}^m$ is encoded in an $(m\times n)$-matrix $[A]$, and the coordinates $(y_1,\ldots, y_m)$ of the image point $y=Ax$, written as a column vector $[y]$, are computed by means of a matrix product: $$[y]=[A][x]\ .\tag{1}$$ When a second linear map $B:\>{\Bbb R}^m\to{\Bbb R}^d$ is given, throwing points $y\in{\mathbb R}^m$ to image points $z:=By\in{\mathbb R}^d$, then $B$ is encoded in an $(d\times m)$-matrix $[B]$, and in analogy to $(1)$ one has $$[z]=[B][y]\ .\tag{2}$$ If you want to perform the two maps $$x\mapsto y=Ax \mapsto z=By=B(Ax)$$ in one step then from $(1)$ and $(2)$ and the associativity of maps (resp., matrix multiplication) it follows that $$[z]=[B]\bigl([A][x]\bigr)=\bigl([B][A]\bigr)[x]=[C][x]$$ with $$[C]:=[B][A]\ .$$

Multiply the matrix which transforms Shape 2 to Shape 3 first. Note: I haven't thoroughly tested it however 99% sure it'll work in all scenarios concerning 2D transformations. I imagine with a 4th shape you would multiply S3-S4 first followed by S2-S3 and S1-S2.