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



#(4)
C_hat := Vector([mx,my,mz,sx,sy,sz,phi,theta,psi]);

#(6)
F_tilde := Matrix([
[1-1/(4*f^2) , 0 , 0 , 0], 
[0,1-1/(4*f^2) , 0 , 0 ], 
[0,0, 1 , -1/(4*f) ], 
[0,0,  -1/(f),1 ]]);

#(5)
S_tilde := DiagonalMatrix(Vector([sx,sy,sz,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));

#(7)
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]]));

#(15)
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) ]
]);
#(16)
NablaC_hat_Pf := 
Matrix([
[ diff(P[1],C_hat[1]) ,diff(P[1],C_hat[2]), diff(P[1],C_hat[3]),
  diff(P[1],C_hat[4]) ,diff(P[1],C_hat[5]), diff(P[1],C_hat[6]),
  diff(P[1],C_hat[7]) ,diff(P[1],C_hat[8]), diff(P[1],C_hat[9])],
[ diff(P[2],C_hat[1]) ,diff(P[2],C_hat[2]), diff(P[2],C_hat[3]),
  diff(P[2],C_hat[4]) ,diff(P[2],C_hat[5]), diff(P[2],C_hat[6]),
  diff(P[2],C_hat[7]) ,diff(P[2],C_hat[8]), diff(P[2],C_hat[9])],
[ diff(P[3],C_hat[1]) ,diff(P[3],C_hat[2]), diff(P[3],C_hat[3]),
  diff(P[3],C_hat[4]) ,diff(P[3],C_hat[5]), diff(P[3],C_hat[6]),
  diff(P[3],C_hat[7]) ,diff(P[3],C_hat[8]), diff(P[3],C_hat[9])]
]);

#integrand of (18)
HM_hat := simplify(Multiply(Multiply(
Transpose(NablaC_hat_Pf),
Transpose(MatrixInverse(NablaX_P))),
Multiply(
MatrixInverse(NablaX_P),
NablaC_hat_Pf)));


#(18)
M_hat := Matrix(9,9):
for i from 1 by 1 to 9 do 
for j from 1 by 1 to 9 do 
M_hat[i,j] := simplify(int(int(int(HM_hat[i,j],x=-1/2..1/2),y=-1/2..1/2),z=-1/2..1/2)):
end do:
end do:

#output of (18): beware: it is a closed form but lengthy
simplify(M_hat);

