Solution to speed up inverse matrix calculation via caching