Invariant functions of the elements of the powers of a square matrix