calculating eigen values from an equation 
I'm trying to use this equation(in yellow) to calculate the eigen values of B = \begin{pmatrix}
1&1&1\\
1&1&1\\
1&1&1\\
\end{pmatrix}
but I'm getting $$-λ^3+3λ^2-3λ$$
and the proper answer using the other method is
$$det( \begin{pmatrix}
1-λ&1&1\\
1&1-λ&1\\
1&1&1-λ\\
\end{pmatrix})$$
$$=-λ^3+3λ^2$$
Anyone see where I could have gone wrong or if the yellow equation only works in certain situations?
 A: $\DeclareMathOperator\tr{tr}$The full proper formula for $n=3$ is:
$$\det(M-\lambda I_3)=(-1)^3\lambda^3 + (-1)^2\tr(M)\lambda^2 + (-1)\cdot \frac 12\big[(\tr M)^2-\tr(M^2)\big]\lambda + \det(M)$$
In this case:
$$\tr\begin{pmatrix}1&1&1\\1&1&1\\1&1&1\end{pmatrix}^2
=\tr \begin{pmatrix}3&3&3\\3&3&3\\3&3&3\end{pmatrix}
=9$$
So the result is indeed $-\lambda^3+3\lambda^2$.
A: You should find that $\det(M)=0,$ so that the two methods agree.
A: $\det(M-\lambda I)=\det\begin{pmatrix}1-\lambda&1&1
\\ 1&1-\lambda&1\\ 1&1&1-\lambda\end{pmatrix}=$ 
add to the 1st row two others
=$\det\begin{pmatrix}3-\lambda&3-\lambda&3-\lambda
\\ 1&1-\lambda&1\\ 1&1&1-\lambda\end{pmatrix}=(3-\lambda)\cdot\det\begin{pmatrix}1&1&1
\\ 1&1-\lambda&1\\ 1&1&1-\lambda\end{pmatrix}=$
Subtract the 1st row from the each of the others
=$(3-\lambda)\cdot\det\begin{pmatrix}1&1&1
\\ 0&-\lambda&0\\ 0&0&-\lambda\end{pmatrix}=\lambda^2(3-\lambda)$
The other approuch
Take $a=(1,1,1)^T$, then $Ma=3a$, so $\lambda=3$ is eigenvalue.
Evidently $\lambda=0$ is a root of $\det(M-\lambda I)$, so $\lambda=0$ is eigenvalue too. As $\text{rank} M=1$ the multiplisity of $\lambda=0$ is 2. So $\det(M-\lambda I)=\lambda^2(3-\lambda).$
