Inverts matrices using R's caching functions