implementation of lexical scope and caching function

updated the script with the implementation of cache inverse matrix by
applying lexical scope concepts.