implements matrix inverse