Substituted the original solution with my own!

+ added an extra small feature to preserve your data when you use the function on an existing matrix. Try:
x <- makeCacheMatrix(x)

(Assuming x already is a valid invertible matrix and contains data)