Implemented matrix inverse calculation caching in R