Implemented inverse function for a matrix.