functions now calculate and cache matrix inversion