1
$\begingroup$

I am really new to mathematica and the syntax sometimes is a bit hard for me. I come from Matlab environment. I think this question is really easy for the most of you.

I am trying to use quaternions in Mathematica and I wrote the following code:

ClearAll["Global`*"]
<< Quaternions`
q1 = Quaternion[q_t, q_x, q_y, q_z];
q2 = Conjugate[q1];
A = Quaternion[0, A_x, A_y, A_z];
totQuat1 = Simplify[q1 ** A ** q2]

Everything seems right to me and I get:

Quaternion[0,A_x (q_t^2+q_x^2-q_y^2-q_z^2)+2 (A_y (q_x q_y-q_t q_z)+A_z (q_t q_y+q_x q_z)),A_y (q_t^2-q_x^2+q_y^2-q_z^2)+2 (A_x (q_x q_y+q_t q_z)+A_z (-q_t q_x+q_y q_z)),A_z (q_t^2-q_x^2-q_y^2+q_z^2)+2 (A_x (-q_t q_y+q_x q_z)+A_y (q_t q_x+q_y q_z))]

But now I would like to take the second element of the quaternion and set A_x to 0.

I am trying to do:

A_x=0
totQuat1[[2]]

But what I get is the second component of the quaternion and the A_x is not set to 0.

A_x (q_t^2 + q_x^2 - q_y^2 - q_z^2) + 
 2 (A_y (q_x q_y - q_t q_z) + A_z (q_t q_y + q_x q_z))

How can I do that?

Thanks a lot.

$\endgroup$

closed as off-topic by Jens, MarcoB, m_goldberg, corey979, Kuba Feb 7 '17 at 9:09

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Jens, MarcoB, m_goldberg, corey979, Kuba
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    $\begingroup$ You cannot have underscores in variable names in Mathematica. _, i.e. Blank has a special meaning used in pattern matching. Try without them and see if your code works differently. $\endgroup$ – MarcoB Feb 6 '17 at 14:40
  • $\begingroup$ Yeah it was that. I did not know this rule. Thanks. $\endgroup$ – kalmanIsAGameChanger Feb 6 '17 at 15:05

Browse other questions tagged or ask your own question.