#Maple proof that the Matrix M_bar in (22) has a closed-form solution (23)
restart;
with(LinearAlgebra):

#(19)
C_bar := Vector([mx,my,mz,s,phi,theta,psi]);

#(6)
F_tilde := IdentityMatrix(4);

#(5)
S_tilde  := DiagonalMatrix(Vector([s,s,s,1]));

#(8)
Rx := Matrix([
[1,        0,         0 ], 
[0, cos(phi), -sin(phi) ],
[0, sin(phi),  cos(phi) ]
]);
Ry := Matrix([
[ cos(theta),0,sin(theta) ], 
[        0,1, 0 ],
[-sin(theta),0,cos(theta) ]
]);
Rz := Matrix([
[ cos(psi),-sin(psi), 0 ], 
[ sin(psi), cos(psi), 0 ],
[ 0       ,        0, 1 ]
]);
R := simplify(Multiply(Multiply(Rz,Ry),Rx));

#(5)
R_tilde := Matrix([
[R[1,1], R[1,2],R[1,3],0 ], 
[R[2,1], R[2,2],R[2,3],0 ], 
[R[3,1], R[3,2],R[3,3],0 ], 
[0,0,0,1 ]
]);

#(5)
T_tilde :=  Matrix([
[1,0,0,mx ], 
[0,1,0,my ], 
[0,0,1,mz ], 
[0,0,0,1 ]
]);

#(10)
PM_tilde := Multiply(Multiply(T_tilde, R_tilde) , Multiply( S_tilde, F_tilde));

#(11)
X_tilde := Vector([x,y,z,1]);
P_tilde := Multiply( PM_tilde, X_tilde);

#(12)
P := simplify(Vector([ P_tilde[1]/P_tilde[4] , P_tilde[2]/P_tilde[4] , P_tilde[3]/P_tilde[4]]));

#integrand of (20)
NablaX_P := 
Matrix([
[ diff(P[1],x) ,diff(P[1],y), diff(P[1],z) ], 
[ diff(P[2],x) ,diff(P[2],y), diff(P[2],z) ], 
[ diff(P[3],x) ,diff(P[3],y), diff(P[3],z) ]
]);
NablaC_bar_Pf := 
Matrix([
[ diff(P[1],C_bar[1]) ,diff(P[1],C_bar[2]), diff(P[1],C_bar[3]),
  diff(P[1],C_bar[4]) ,diff(P[1],C_bar[5]), diff(P[1],C_bar[6]),
  diff(P[1],C_bar[7]) ],
[ diff(P[2],C_bar[1]) ,diff(P[2],C_bar[2]), diff(P[2],C_bar[3]),
  diff(P[2],C_bar[4]) ,diff(P[2],C_bar[5]), diff(P[2],C_bar[6]),
  diff(P[2],C_bar[7]) ],
[ diff(P[3],C_bar[1]) ,diff(P[3],C_bar[2]), diff(P[3],C_bar[3]),
  diff(P[3],C_bar[4]) ,diff(P[3],C_bar[5]), diff(P[3],C_bar[6]),
  diff(P[3],C_bar[7]) ]
]);

#integrand of (21)
HM_bar := simplify(
Multiply(Multiply(
Transpose(NablaC_bar_Pf)
,
simplify(MatrixInverse(Multiply(NablaX_P, Transpose(NablaX_P))))
),
NablaC_bar_Pf));

#(21)
M_bar := Matrix(7,7):
for i from 1 by 1 to 7 do 
for j from 1 by 1 to 7 do 
M_bar[i,j] := simplify(int(int(int(HM_bar[i,j],x=-1/2..1/2),y=-1/2..1/2),z=-1/2..1/2)):
end do:
end do:

#output of (21), if correct then showing (22)
simplify(M_bar);

