I have this function I need to build a Jacobian matrix for:

<br />
F = R\left(\bar{q}\right) . p<br />

where p is a position vectors (x,y,z) and R(q) is the function converting a quaternion to a rotation matrix.
Note that in the function F, the rotation matrix is obtained from the conjugate of q, i.e. (q0, -q1, -q2, -q3).

<br />
R(q) = \left(<br />
\begin{array}{ccc}<br />
{q0}^2+{q1}^2-{q2}^2-{q3}^2 & 2 ({q1} {q2}-{q0} {q3}) & 2 ({q0} {q2}+{q1} {q3}) \\<br />
2 ({q1} {q2}+{q0} {q3}) & {q0}^2-{q1}^2+{q2}^2-{q3}^2 & 2 (-{q0} {q1}+{q2} {q3}) \\<br />
2 (-{q0} {q2}+{q1} {q3}) & 2 ({q0} {q1}+{q2} {q3}) & {q0}^2-{q1}^2-{q2}^2+{q3}^2<br />
\end{array}<br />
\right)<br />

The jacobian matrix I obtain for dH/dq is as follows: err.. can't post it here, the latex parser doesn't like it. Let's just say it's

<br />
\frac{\partial F}{\partial q}=\frac{\partial R(\text{q0},-\text{q1},-\text{q3},-\text{q3}) . p}{\partial (\text{q0},\text{q1},\text{q3},\text{q3})}<br />



However, I saw someone obtaining this jacobian by separating dF/dq into
<br />
\frac{\partial F}{\partial q}=\frac{\partial R\left(\bar{q}\right) . p}{\partial \bar{q}}.\frac{\partial \bar{q}}{\partial q}=\frac{\partial R(\text{q0},\text{q1},\text{q3},\text{q3}) . p}{\partial (\text{q0},\text{q1},\text{q3},\text{q3})}.\frac{\  partial \bar{q}}{\partial q}<br />
where
<br />
\frac{\partial \bar{q}}{\partial q}=\left(<br />
\begin{array}{cccc}<br />
1 & 0 & 0 & 0 \\<br />
0 & -1 & 0 & 0 \\<br />
0 & 0 & -1 & 0 \\<br />
0 & 0 & 0 & -1<br />
\end{array}<br />
\right)<br />

The resulting jacobian is not the same as mine... it seems that
<br />
\frac{\partial F}{\partial q}=\frac{\partial R(\text{q0},-\text{q1},-\text{q3},-\text{q3}) . p}{\partial (\text{q0},\text{q1},\text{q3},\text{q3})}\neq \frac{\partial R(\text{q0},\text{q1},\text{q3},\text{q3}) . p}{\partial (\text{q0},\text{q1},\text{q3},\text{q3})}.\frac{\  partial \bar{q}}{\partial q}<br />

so which is right? i'm quite confused now. Either Mathematica is wrong, or that other guy has put some screwy math in his source code.

thanks,

Lwi