Matrix inverse with cache implemented