$A^2X = X$ show that $AX = X$, if $A_{ij} > 0$ and $x_{i} > 0$ 
Let $A$ and $X$ be matrices $n \times n$ and $n \times 1$, respectively, with all entries real and strictly positive. Assume that $A^2 X = X$. Show that $A X = X$.

What I thought:
(i) $A^2 X = X \Rightarrow A (A^2 X) = A (X)$ for distributive law $ A(A^2 X) = A A (Ax) = AX \Rightarrow A^2(AX) = (AX)$, i.e., $A^2 Y = Y$ for $Y=AX$.
(ii) $A^2 X = X \Rightarrow (A^2-I)X = 0$. Be $X = (x_1,x_2,\ldots,x_n)^t$. So, $x_i > 0 \quad\forall i \in \{1,2,\ldots,n\}$. So, $det(A^2 - I) = 0 \Rightarrow det(A-I) = 0$ or $det(A+I) = 0$.
But, if $det(A+I) = 0 \Rightarrow (A+I)Y = 0 \Rightarrow AY = -Y$. 
So $Y\neq X$ because if $A_{ij}>0 \quad and \quad x_i > 0 \Rightarrow AX \neq -X$
So, $det(A-I) = 0 \Rightarrow$ There is a vector Z that  $(A-I)Z = 0 \Rightarrow AZ = Z$.
So, I need conclude that Z = X. 
 A: More generally, let $A$ be a primitive matrix ($A$ is non-negative and some power of $A$ is a positive matrix) with spectral radius $r$ and $k\in\mathbb{N}$. If there is $x>0$ s.t. $A^kx=sx$, then $s=r^k$ and $Ax=rx$. 
Proof. Note that $A^k$ is also primitive and then $\not=0$; thus, necessarily $s>0$ and we may assume that $s=1$. Using the Perron theorem, cf. https://en.wikipedia.org/wiki/Perron%E2%80%93Frobenius_theorem , since $x>0$, necessarily $1=\rho(A^k)=(\rho(A))^k$ and $r=1$. Note that $x\in \ker(A^k-I)=\ker(A-I)\bigoplus_{\omega;\omega^k=1,\omega\not=1} \ker(A-\omega I)$. Yet, $A$ is aperiodic ($1$ is the sole eigenvalue of $A$ with modulus $1$); thus  $\ker(A^k-I)=\ker(A-I)$ and $Ax=x$.
A: Here is the outline of an elementary proof. Let $\mathbf 1$ be all-one vector, $D$ be the diagonal matrix whose main diagonal is $x$ (so that $D\mathbf1=x$) and $B=D^{-1}AD$. Then $A^2x=x$ is equivalent to $B^2\mathbf 1=\mathbf 1$ and we want to prove that $\color{red}{B\mathbf 1=\mathbf 1}$.
Let $y=B\mathbf 1$. Hence it is a positive vector. There are two possibilities:


*

*$y$ and $\mathbf1$ are linearly independent. Let $v$ be the positive multiple of $y$ such that its largest element is equal to $1$. From $B^2\mathbf1=\mathbf1$, we get $B^2y=y$ and in turn $B^2v=v$. Therefore
$$B^2(\mathbf1-v)=\mathbf1-v.\tag{$\dagger$}$$
Argue that $\mathbf1-v$ is a nonnegative vector with both zero entries and positive entries. Hence explain why ($\dagger$) is impossible.

*$y$ is a scalar multiple of $\mathbf1$. Explain why this multiple must be positive; hence explain why it is equal to $1$. Now $B\mathbf1=y=\mathbf1$ and we are done.

A: Consider the characteristic polynomial $p$ of $A$.  By the Cayley-Hamilton theorem, $p(A)=0$, and thus $p(A)X=0$.  If $p(x)=\sum_{i=0}^n c_ix^i$, this
gives $\sum_{i=0}^n c_iA^iX=0$.  As $A^2X=X$, the latter sum simplifies to
$d_1AX+d_0X=0$ for some constants $d_0$ and $d_1\not=0$.  This in turn implies that
$AX=\lambda X$ for $\lambda=-d_0/d_1$.  Now $X=A^2X=\lambda^2 X$, so $\lambda=\pm 1$, and since all entries of $A$ and $X$ are positive, it
can't be that $\lambda=-1$.
