5

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?

Matt Groff
  • 1,141
  • 1
  • 10
  • 15

2 Answers2

6

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}

DavidC
  • 16,724
  • 1
  • 42
  • 94
1
   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

Pankaj Sejwal
  • 2,063
  • 14
  • 23