MATLAB: Doesn’t A*P produce the right answer

matrix manipulationmatrix multiplication

Doing a simple matrix multiplication in MatLab seems to be giving me the incorrect answer. If
A = [ 1 2 3 4; 5 6 7 8; 9 10 11 12; 13 14 15 16 ];
and
P = [ 0 0 0 1; 1 0 0 0; 0 0 1 0; 0 1 0 0 ];
then
A*P = [ 4 1 3 2; 8 5 7 6; 12 9 11 10; 16 13 15 14 ];
However, when I do A*P in MatLab, I get the following answer:
A*P = [ 2 4 3 1; 6 8 7 5; 10 12 11 9; 14 16 15 13 ];
Can someone please explain to me what is happening?

Best Answer

MATLAB is producing the correct answer. Your understanding of matrix multiplication is not correct. The operation that gives the result you were expecting is actually
A*P.'
Also, you have a typo in your post. I assume the P you meant is:
P = [ 0 0 0 1; 1 0 0 0; 0 0 1 0; 0 1 0 0 ];