creating matrix and caching inverse results