Caching the result of calculating the inverse of a matrix