introduction of rotation with quaternions (part 3),version  1.0
peter.vlasschaert@gmail.com, 03/11/2018

see:introduction of rotation with quaternions (part 2),version  1.0 
use M :matrix. => 

load packages.
=============

kill(all)$
load(vect)$
load(lrats)$
load(functs)$

Matrix of angles to a quaternion.
===========================

M:matrix(
        [2*q2^2+2*q1^2-1,   2*q2*q3-2*q1*q4,    2*q2*q4+2*q1*q3],
        [2*q1*q4+2*q2*q3,   2*q3^2+2*q1^2-1,    2*q3*q4-2*q1*q2],
        [2*q2*q4-2*q1*q3,   2*q3*q4+2*q1*q2,    2*q4^2+2*q1^2-1]
    );
	

rem :see part 2: final matrix : MM = M
-------------------------------------------------------

TM1:tracematrix(M);

p1:q1^2+q2^2+q3^2+q4^2=1;

find q1 ?  => |q1|     from   TM
========================

 TM = M[1,1] +M[2,2]+M[3,3]

p2: TM=sum(M[i,i],i,1,length(M));
p2a:lhs(p2) =sum('M[i,i],i,1,length(M));

use : 'p1'

p3:p1-q1^2;

p3a:lratsubst([p3],p2);

choose : pos. root, why |q1|
-----------------------------

p3b:solve(p3a,q1);
p3c:p3b[2];

find q2 ?  => |q2|     from   M[1,1]
==========================

p4:'M[1,1]=M[1,1];

p4a:subst([p3c],p4);

p4b:solve(p4a,q2);

p4c:p4b[2];

find q3 ?  => |q3|     from   M[2,2]
==========================

p5:'M[2,2]=M[2,2];
p5a:subst([p3c],p5);
p5b:solve(p5a,q3);
p5c:p5b[2];

find q4 ?  => |q4|     from   M[3,3]
==========================

p6:'M[3,3]=M[3,3];
p6a:subst([p3c],p6);
p6b:solve(p6a,q4);
p6c:p6b[2];

'--------------------------------------------------------------------------------------------------------------------'