edited cachematrix.R providing my solution