Is quaternion multiplication associative?

Hi,
I know that quaternions hold associative property,
which is A.(B.C) = (A.B).C
But, have a look at the code below
%%
t1 = sym('t1/2','real');
t2 = sym('t2/2','real');
t3 = sym('t3/2','real');
Q01 = [cos(t1) 0 0 sin(t1)];
Q12 = quatmultiply([cosd(45) sind(45) 0 0],[cos(t2) 0 0 sin(t2)]);
Q23 = quatmultiply([cosd(-45) sind(-45) 0 0],[cos(t3) 0 0 sin(t3)]);
X = quatmultiply(Q01,quatmultiply(Q12,Q23));
Y = quatmultiply(quatmultiply(Q01,Q12),Q23);
X-Y
%%
but there's a difference between 'X-Y'. How come?
can someone help me with this.
Thanks.

Answers (1)

You just need to simplify it to see that the result is in fact 0's. E.g., running your code gives this for X-Y:
ans =
[ cos(t1/2)*cos(t2/2)*cos(t3/2) - cos(t2/2)*sin(t1/2)*sin(t3/2) - (2^(1/2)*cos(t3/2)*((2^(1/2)*cos(t1/2)*cos(t2/2))/2 - (2^(1/2)*sin(t1/2)*sin(t2/2))/2))/2 - (2^(1/2)*cos(t3/2)*((2^(1/2)*cos(t1/2)*cos(t2/2))/2 + (2^(1/2)*sin(t1/2)*sin(t2/2))/2))/2 - (2^(1/2)*sin(t3/2)*((2^(1/2)*cos(t1/2)*sin(t2/2))/2 - (2^(1/2)*cos(t2/2)*sin(t1/2))/2))/2 + (2^(1/2)*sin(t3/2)*((2^(1/2)*cos(t1/2)*sin(t2/2))/2 + (2^(1/2)*cos(t2/2)*sin(t1/2))/2))/2, cos(t3/2)*sin(t1/2)*sin(t2/2) - cos(t1/2)*sin(t2/2)*sin(t3/2) + (2^(1/2)*cos(t3/2)*((2^(1/2)*cos(t1/2)*cos(t2/2))/2 - (2^(1/2)*sin(t1/2)*sin(t2/2))/2))/2 - (2^(1/2)*cos(t3/2)*((2^(1/2)*cos(t1/2)*cos(t2/2))/2 + (2^(1/2)*sin(t1/2)*sin(t2/2))/2))/2 + (2^(1/2)*sin(t3/2)*((2^(1/2)*cos(t1/2)*sin(t2/2))/2 - (2^(1/2)*cos(t2/2)*sin(t1/2))/2))/2 + (2^(1/2)*sin(t3/2)*((2^(1/2)*cos(t1/2)*sin(t2/2))/2 + (2^(1/2)*cos(t2/2)*sin(t1/2))/2))/2, (2^(1/2)*cos(t3/2)*((2^(1/2)*cos(t1/2)*sin(t2/2))/2 - (2^(1/2)*cos(t2/2)*sin(t1/2))/2))/2 - sin(t1/2)*sin(t2/2)*sin(t3/2) - cos(t1/2)*cos(t3/2)*sin(t2/2) + (2^(1/2)*cos(t3/2)*((2^(1/2)*cos(t1/2)*sin(t2/2))/2 + (2^(1/2)*cos(t2/2)*sin(t1/2))/2))/2 - (2^(1/2)*sin(t3/2)*((2^(1/2)*cos(t1/2)*cos(t2/2))/2 - (2^(1/2)*sin(t1/2)*sin(t2/2))/2))/2 + (2^(1/2)*sin(t3/2)*((2^(1/2)*cos(t1/2)*cos(t2/2))/2 + (2^(1/2)*sin(t1/2)*sin(t2/2))/2))/2, cos(t1/2)*cos(t2/2)*sin(t3/2) + cos(t2/2)*cos(t3/2)*sin(t1/2) + (2^(1/2)*cos(t3/2)*((2^(1/2)*cos(t1/2)*sin(t2/2))/2 - (2^(1/2)*cos(t2/2)*sin(t1/2))/2))/2 - (2^(1/2)*cos(t3/2)*((2^(1/2)*cos(t1/2)*sin(t2/2))/2 + (2^(1/2)*cos(t2/2)*sin(t1/2))/2))/2 - (2^(1/2)*sin(t3/2)*((2^(1/2)*cos(t1/2)*cos(t2/2))/2 - (2^(1/2)*sin(t1/2)*sin(t2/2))/2))/2 - (2^(1/2)*sin(t3/2)*((2^(1/2)*cos(t1/2)*cos(t2/2))/2 + (2^(1/2)*sin(t1/2)*sin(t2/2))/2))/2]
>> simplify(ans)
ans =
[ 0, 0, 0, 0]

Products

Answered:

on 8 May 2020

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!