Implementation of the matrix with cached inverse