Invert and solve a matrix