HP Forums
Quaternions: Convert to a 2 x 2 matrix form - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Software Libraries (/forum-10.html)
+--- Forum: HP Prime Software Library (/forum-15.html)
+--- Thread: Quaternions: Convert to a 2 x 2 matrix form (/thread-4223.html)



Quaternions: Convert to a 2 x 2 matrix form - Eddie W. Shore - 06-25-2015 02:55 AM

Code:
QTM(A,B,C,D)
BEGIN
RETURN [[A+B*i, C+D*i],
[-C+D*i, A-B*i]];
END;

For more details, please visit my blog at: http://edspi31415.blogspot.com/2015/06/hp-prime-and-hp-50g-quaternions.html


RE: Quaternions: Convert to a 2 x 2 matrix form - salvomic - 04-25-2016 05:57 PM

hi Eddie,
after your blog, a modified version with some extensions inside...

Salvo

Code:

// Quaternion by Eddie W. Shore

EXPORT QTM(A,B,C,D)
BEGIN
RETURN [[A+B*i, C+D*i],
[-C+D*i, A-B*i]];
END;

// Norm
EXPORT QTM_norm(A,B,C,D)
BEGIN
RETURN sqrt(A^2+B^2+C^2+D^2);
END;

// Unit Quaternion matrix
EXPORT QTM_Unit(A,B,C,D)
BEGIN
LOCAL mat, n;
mat:= QTM(A,B,C,D);
n:= QTM_norm(A,B,C,D);
RETURN mat/n;
END;

// Conjugate of Q. matrix
EXPORT QTM_conj(A,B,C,D)
BEGIN
RETURN (QTM(A,B,C,D))^(-1) * QTM_norm(A,B,C,D)^2;
END;