Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I'm using the Quaternion package:

<< Quaternions`

Very simply, I would like to be able to get the individual components of the quaternions by themselves.

My problem is, if I try

Re[FromQuaternion[Quaternion[1,2,3,4]]]

I get

1+Re[3J+4K]

I would like to isolate the components instead. Then I could get

1

... or 2 or 3 or 4. How can I do this?

ALSO

Is it possible to convert quaternions into a vector?

share|improve this question

2 Answers 2

up vote 3 down vote accepted

See if this helps...

q = Quaternion[21, 22, 23, 24];
q[[2]]
FromQuaternion[q] // FullForm

Quaternion[21,22,23,24]
22
Plus[Complex[21,22],Times[23,J],Times[24,K]]

Now this...

q[[1]]
FromQuaternion[q][[1]]
Re[FromQuaternion[q][[1]]]
Im[FromQuaternion[q][[1]]]
List @@ q

21
21+22 I
21
22
{21,22,23,24}

share|improve this answer
   p = FromQuaternion[Quaternion[1, 2, 3, 4]]

 p/.List[Complex[a_,b_],Times[c_,J],Times[d_,K]]->{a,b,c,d}

{1,2,3,4}

To convert it to a vector remove a from list. And since the pattern always stays same, rather give it a name, like

  quaternion = List[Complex[a_,b_],Times[c_,J],Times[d_,K]]

and call it as p/.quaternion->{a,b,c,d}

This approach is helpful when you don't know the parameters with which the Quaternion was created

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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