working code to invert a matrix and store it