On matrix equivalence and matrix equations