Solving constrained matrix equations and Cramer rule