solution to matrix inverse caching