adds matrix functionality (with inverse caching)