MATLAB: Quaternions, Transformation Matrix

quaternionstransformation matrix

Hello.
As you see in the figure, my C matrix depends on q1, q2, q3 and q4 quaternions. I caculated all the q1(i),q2(i),q3(i),q4(i) values when i = 0:1:54000. Namely for 54000 iteration, I have 54000 different q1, q2, q3, q4 values. Right now, I want to calculate C matrix for i = 0:1:54000. As a result, I need 54000 different C matrices. For i = 1, q1(1), q2(1), q3(1) and q4(1) should be used and so on i need to reach i = 54000. As i say above, i have the code to calculate all q1,q2,q3 and q4. Just i need to insert these values to matrix respectively. I guess for matrices, i can't use the same plan as I calculated quternions.
Thanks for the help already.

Best Answer

Such thing is straight forward in MATLAB
q1 = reshape(q1,1,1,[]);
q2 = reshape(q2,1,1,[]);
q3 = reshape(q3,1,1,[]);
q4 = reshape(q4,1,1,[]);
% The matrix is i C(:,:,i) for i=1,..., 54000
C = [q1.^2-q2.^2-q3.^2+q4.^2, 2*(q1.*q2+q3.*q4), 2*(q1.*q3-q2.*q4);
2*(q1.*q2-q3.*q4), -q1.^2+q2.^2-q3.^2+q4.^2, 2*(q2.*q3-q1.*q4);
2*(q1.*q3+q2.*q4), 2*(q2.*q3-q1.*q4), -q1.^2-q2.^2+q3.^2+q4.^2]
Related Question