Creating functions for matrix caching. Assingment #2