Phimat(1,1) =cos(psi)*cos(theta); 
Phimat(1,2) =sin(psi)*cos(phi)+cos(psi)*sin(theta)*sin(phi); 
Phimat(1,3) =sin(psi)*sin(phi)-cos(psi)*sin(theta)*cos(phi); 
Phimat(2,1) =-sin(psi)*cos(theta); 
Phimat(2,2) =cos(psi)*cos(phi)-sin(psi)*sin(theta)*sin(phi); 
Phimat(2,3) =cos(psi)*sin(phi)+sin(psi)*sin(theta)*cos(phi); 
Phimat(3,1) =sin(theta); 
Phimat(3,2) =-cos(theta)*sin(phi); 
Phimat(3,3) =cos(theta)*cos(phi); 
