Implemented matrix inverse caching using R scoping rules