Necessary and Sufficient Condition for a Set of Matrices to Commute