solving the matrix equation