5
$\begingroup$

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?

$\endgroup$
5
$\begingroup$

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}

$\endgroup$
1
$\begingroup$
   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

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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