code for square matrix

cached matrix, calculate invers