Implemented matrix that can cache its inverse.