On finding the characteristic equation of a square matrix