completed version of cachematrix.R for assignment 2 grading