Modified getInverse to handle singular systems.