Completed fuctions to calculate and cache inverse for a matrix