Cache matrix inverse

Modified code to take a matrix as an input and to cache its inverse.
Added comments to explain how it works.