Cache matrix inverse

Revised code for assignment 2