Sample function edited to inverse a matrix