Functions to calculate and cache inverse of matrix