If I have the following instructions:

enter image description here

How will it be the output/how will it appears in Mathematica? something like this:

enter image description here

I can't recognize the output in mathematica... How can I do to appear the matrix? because it doesn't appear...

  • 2
    $\begingroup$ This question is ill posed. We expect those who ask questions here to be familiar with the basics of Mathematica. You really aren't not ready to work with quaternions in Mathematica if you don't understand lists and how matrices are represented as lists of lists. I'll add this piece of advice: be cautious about using MatrixForm. It is a formatting function intended for pretty printing output. You can't compute with quantities wrapped in MatrixForm. $\endgroup$ – m_goldberg Jun 28 '14 at 19:14
  • $\begingroup$ Can you give me solution for my question. I really need an answer for this question. thanks $\endgroup$ – danciulian Jun 28 '14 at 19:15
  • $\begingroup$ It is easy to say that I don't know how to manipulate with quaternions, but do help me with something? You can give me some information and materials... but you have just told me I don't know... Do you think it is helpful? $\endgroup$ – danciulian Jun 28 '14 at 19:24
  • 2
    $\begingroup$ Your question, as it now appears, is too vague. I can not determine from it what kind of an answer would satisfy you. You need to do more work up front before asking. A potential answerer needs to know what you already know about the problem, what exactly is giving you trouble, and what kind of an answer will work for you. $\endgroup$ – m_goldberg Jun 28 '14 at 19:29
  • $\begingroup$ I don't think you are right... I need for some instruction which can help me to transform a quaternion in a matrix. Also, I asked if these instructions which I have written, are OK? Thanks! $\endgroup$ – danciulian Jun 28 '14 at 19:31

according to http://en.wikipedia.org/wiki/Quaternion

QuaternionToMatrix[Quaternion[a_, b_, c_, d_]] := 
  {{a, b, c, d}, {-b, a, -d, c}, {-c, d, a, -b}, {-d, -c, b, a}}  

is this what you want?

| improve this answer | |
  • $\begingroup$ Yes. I want to obtain something which looks like a matrix. How can I write in Mathematica to obtain a matrix from a quaternion? Thanks! $\endgroup$ – danciulian Jun 28 '14 at 18:12
  • 2
    $\begingroup$ @danciulian It looks like you should first familiarize yourself with the basics of the language Mathematica. The questions you're asking smell like homework problems, and of course the purpose of such problems is to get you to think about the solution yourself. First look through the documentation for all the keywords in the code you pasted in your question. $\endgroup$ – Jens Jun 28 '14 at 18:27
  • $\begingroup$ yes, you are right. I search for that keywords, but nothing. This is the reason I asked this question. I will be happy if you can help me. wag.caltech.edu/home/meulbroek/QuaternionExtentions Thanks. $\endgroup$ – danciulian Jun 28 '14 at 18:30

Acknowleding the comments re: 'homework', I post this just to illustrate an alternative matrix representation of quaternions to the Wouter.

qf[a_, b_, c_, d_] := Module[{mat1 = {{0, 1}, {-1, 0}},
   mat2 = {{0, 1}, {1, 0}},
   mat3 = {{1, 0}, {0, -1}}, q1, qi, qj, qk},
  q1 = IdentityMatrix[4];
  qi = ArrayFlatten[{{mat1, 0}, {0, mat1}}];
  qj = ArrayFlatten[{{0, -mat2}, {mat2, 0}}];
  qk = ArrayFlatten[{{0, -mat3}, {mat3, 0}}];
  a q1 + b qi + c qj + d qk]
qm[mat_] := mat[[3]][[{3, 4, 2, 1}]]

qf converts quaternion to matrix representation and qm matrix to quaternion (the latter in this case a 4 vector).

Comparison of representations Wouter and qf:

enter image description here

The unit quaternion representations:

     MatrixForm[qf @@ #]} & /@ (RotateLeft[{1, 0, 0, 0}, #] & /@ 
     Range[0, 3]), {"Quaternion", "Matrix Representation"}], 
 Frame -> All]

enter image description here

Confirmation of the multiplicative properties:

Grid[{MatrixForm[#[[1]]], MatrixForm[#[[2]]], 
    MatrixForm[#[[1]].#[[2]]]} & /@ 
  Tuples[qf @@ # & /@ (RotateLeft[{1, 0, 0, 0}, #] & /@ Range[0, 3]), 
   2], Dividers -> {{True, False, True, True}, {{True}}}]

enter image description here

Rotation using this matrix representation:

rot[v_, u_, a_] := Module[{qv, qt},
  qv = PadLeft[v, 4, 0];
  qt = PadLeft[Sin[a/2] (Normalize@u), 4, Cos[a/2]];
  N@Rest@qm[Fold[#2.#1 &, Inverse[qf @@ qt], qf @@@ {qv, qt}]]

v is vector to rotated, u is axis, a is angle and the function returns vector.

Trivial test cases:

  Table[{j, rot[{1, 0, 0}, {0, 0, 1}, j]}, {j, 0, Pi, 
    Pi/6}], {"Angle", "Rotated Vector"}], Frame -> All]

enter image description here

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.