how to solve matrix equations