# Why does the order matter in multiplication of matrixes?

I stumbled on this question because I had the same problem with my camera, and changing the multiplication order worked.

I ran into a similar problem when scaling a model. This code produced the wrong result:

// world is an existing Matrix
var scale = world * Matrix.CreateScale(3.2f);


whereas this worked perfectly (scaled a model to 3.2x it's size):

var scale = Matrix.CreateScale(3.2f) * world;


I don't understand why the order matters though - in "normal" math (that is, 5*3 vs 3*5), swapping the factors yields the same result. I understand differences if there are more than 2 factors (like in this question), but I don't see the issue here?

I don't know much about how Matrices really work and so I don't know if that's an XNA quirk or if it would happen in OpenGL as well?

• This isn't a game dev question, it's a math question. Go teach yourself how to manually multiply matrices, you'll quickly learn why the order matters. Sep 11, 2013 at 5:50
• Matrix multiplication is not commutative, unlike "normal" multiplication. In this sense it's more like "normal" division - would you expect 5 / 3 to be the same as 3 / 5? Sep 11, 2013 at 7:03
• Just by definition Sep 11, 2013 at 9:09
• Walk five steps then rotate 90 degrees. Now, rotate 90 degrees then walk five steps. Are you in the same place? Please, Don't do this test near a cliff.
– Zhen
Sep 11, 2013 at 10:53
• @MichaelStum, another way to think about it. You mean scale matrix but in reality [in a more accurate way] this matrix should be called scale using (0,0,0) as center. So if world move the mesh from the (0,0,0), the scale result will be different.
– Zhen
Sep 12, 2013 at 7:25