Function for matrix inverse

Generate matrix Inverse for a square matrix and if the matrix has no
changed, return the inverse from a cached value