wrote functions to calculate inverse of matrix