Calculate the inverse of a matrix and cache it.