Calculate the inverse of a matrix and cache the results.