The various quaternion functions in the Aerospace Toolbox (see <http://www.mathworks.com/help/aerotbx/flight-parameters-1.html>) all indicate that an input quaternion q should have "its scalar number as the first column" (i.e., [w x y z] ordering rather than [x y z w]). However, this convention doesn't always seem to produce the expected result.
For example, the quaternion:
[cos(pi/2) + 0i + 0j + sin(pi/2)] = [1/sqrt(2) + 0i + 0j + 1/sqrt(2)k]
represents a rotation about the Z-axis ([0 0 1]) by 90 degrees. Accordingly, if this quaternion is used to rotate the vector [1 1 1] in a right-handed coordinate system, the result should be [-1 1 1].
If MATLAB's "quatrotate" function is used to perform this rotation, the result is the following:
>> quatrotate([1/sqrt(2) 0 0 1/sqrt(2)], [1 1 1])
1.0000 -1.0000 1.0000
This result corresponds to a rotation about the Z-axis by -90 degrees, not 90 as expected.
Another example: rotating [0 0 1] by the quaternion [1/sqrt(2) 1/sqrt(2) 0 0] (which represents a 90 degree rotation about the x axis) yields the following:
>> quatrotate([1/sqrt(2) 1/sqrt(2) 0 0],[0 0 1])
0 1.0000 0
when the expected result is [0 -1 0].
The result from quatrotate (at least for these two examples) seems to be determined using a left-handed coordinate system, yet the documentation for the Aerospace Toolbox explicitly states that "[t]he Aerospace Toolbox software uses right-handed (RH) Cartesian coordinate systems" (see <http://www.mathworks.com/help/aerotbx/ug/defining-coordinate-systems.html#bqsgj4j-5>). Other quaternion functions exhibit similar behaviour (e.g., using the quaternion from the first example, quat2dcm produces a matrix that performs a -90 degree rotation about the z axis).
Have I missed a part of the documentation that explains this behavior, or am I using these functions incorrectly? Any assistance would be appreciated.