inversematrix function implemented