Computing and caching inverse of matrix