Functions to calculate inverse of matrix