implement matrix inverse with caching - ProgAssignment 2