Functions for creating and using inverted matrices with caching mechanism