Implemented cachematrix functions