Cachematrix functions for programming assignment 2