Matrix inversion/caching

Modified the function to perform matrix inversion as mentioned in the
assignment