code added to cachematrix.R. Testing confirms code works correctly.