second commit, with cached matrix inversion functions  and test for matrix invertibility