Calculate and cache inverse of a matrix