Matrix functions worked out & commented for programming assignment 2