I have a Graph $G=(V,E)$ with an adjacency matrix $A(G)=a_{ij}$ I have a task to prove two theorems and then to apply them.
Theorem 1: $ trace(A)=\sum_{i=1}^{n}a_{ii}^{l} $ counts the Number of closed walks of the length l
Theorem 2: $ trace(A)=\sum_{i=1}^{n}\lambda_{ii}^{l} $ counts the Number of closed walks of the length l , with $\lambda_{i}$ is the eigenvalue.
I have prooven them both, and found references but! It doesn't work on the example. I have a graph with the following adjacency Matrix
$$ A=
\begin{pmatrix}1 & 2 & 1\\\ 2 & 0 & 2 \\\ 1&2&1 \end{pmatrix}$$
$$
The eigenvalues are ${4,-2,0}$ You could have a look here
The graph look like this
One can see that it has 2 closed ways of length 1.
Now it get weird, i am counting the trace(A)=1+1 =2 But when prooving the Theorem 2 I have used spectral Theorem, and when I use it I get: $$ A=U*D*V $$ $$ U=\begin{pmatrix}{} \frac{1}{\sqrt{3}}&-\frac{1}{\sqrt{6}}&-\frac{1}{\sqrt{2}}\\ \frac{1}{\sqrt{3}}&\sqrt{\frac{2}{3}}&0\\ \frac{1}{\sqrt{3}}&-\frac{1}{\sqrt{6}}&\frac{1}{\sqrt{2}}\\ \end{pmatrix} $$
$$ D=\begin{pmatrix}4 & 0 & 0\\\ 0 & 2 & 0 \\\ 0&0&0 \end{pmatrix} $$
$$ V=\begin{pmatrix}{} \frac{1}{\sqrt{3}}&\frac{1}{\sqrt{3}}&\frac{1}{\sqrt{3}}\\ \frac{1}{\sqrt{6}}&-\sqrt{\frac{2}{3}}&\frac{1}{\sqrt{6}}\\ -\frac{1}{\sqrt{2}}&0&\frac{1}{\sqrt{2}}\\ \end{pmatrix} $$
here are the computations So basically i am loosing a -1 on the 2 eigenvalue. When i use the $\sum_{i=1}^n \lambda_i^1=4-2=2$ What i am counting here? But when i use $trace(D)=6$ what is obviously not correct. I have used Mathematica 11 to evaluate the Spectral Decomposition. Any Thoughts on this?
The problem isn't in the graph theory. The trace is cyclically invariant, so
$$\operatorname{Tr}A=\operatorname{Tr}(P^{-1}DP)=\operatorname{Tr}(PP^{-1}D)=\operatorname{Tr}D\;,$$
so there's a mistake in your matrix calculations quite independent of graph theory. As far as I can tell from the calculations you linked to, the two matrices you're left- and right-multiplying by aren't actually inverses of each other.