Calculating and caching inverse matrix operation