Functions for work with a matrix and cache its inverse