edit the add method of matrix class