calculate inverse of square matrix with caching support - PA2 for rprog-005