MATLAB Answers

Commands for Simulations using Quaternions

1 view (last 30 days)
Zaid Ahmad
Zaid Ahmad on 22 Feb 2020
Commented: Zaid Ahmad on 8 May 2020
Hi MathWorks Team,
I am intersted to buy MATLAB Student Version for my PhD research. But I need a few specific commands related to quaternions. While going through vairous toolbox search, I doubt the commands are split across multiple toolbox. Please guide what is the cheapest way to buy MATLAB with following options:
  1. quaternion
  2. quatmultiply
  3. quatconj
  4. quatinv
Please guide so that I can buy at the earliest.


Sign in to comment.

Answers (1)

James Tursa
James Tursa on 7 May 2020
Edited: James Tursa on 7 May 2020
Not to be flippant, but the cheapest way is to not buy a toolbox just for the functions you need, but simply write your own functions.
Represent quaternion as a simple double variable Nx4, where N = number of quaternions in the variable. Same as MATLAB.
Then the quatmultiply, quatconj, and quatinv functions would be trivial to write. E.g., if we assume scalar-vector order and right-handed Hamilton convention as MATLAB toolboxes do, then assuming you have a later version of MATLAB that uses implicit expansion:
function qc = quatconj(q)
qc = [q(:,1),-q(:,2:4)];
function qi = quatinv(q)
qi = quatconj(q) ./ sum(q.*q,2);
function r = quatmultiply(q,p)
qs = q(:,1);
ps = p(:,1);
qv = q(:,2:4);
pv = p(:,2:4);
r = [qs.*ps - dot(qv,pv,2), qs.*pv + ps.*qv + cross(qv,pv,2)];
If you wanted to use the (evil) left-handed JPL quaternion convention (which does not match MATLAB), then you would change the + cross(etc) to - cross(etc) in the quatmultiply( ) function.
If you do decide to get a toolbox, keep in mind that the quaternion convention used by the Aerospace Toolbox is different from the quaternion convention used by the Robotics Toolbox. The Aerospace Toolbox seems to be geared towards coordinate system transformation quaternions, and the Robotics Toolbox seems to be geared towards vector rotations within the same frame.

  1 Comment

Zaid Ahmad
Zaid Ahmad on 8 May 2020
Thank you very much for your detailed answer, James. It was really helpful.

Sign in to comment.


Translated by