<s>[INST] How can I find the P matrix in $P^{-1}AP $= D? I have the following exercise:
Let a matrix A = $\begin{pmatrix}
4 & 0  & 1\\ 
 2 & 2  & 1\\ 
 0 & 4   & 1 
\end{pmatrix}$
1) Determine its eigenvalues and their multiplicity.
2) Give a basis of the eigen spaces associated with each of the
distinct eigenvalues of A.
3) find P and D such that $P^{-1}AP$ = D is diagonal.
I've done 1) and 2) and found the basis 
B ={ $\begin{pmatrix}
-1 \\ 
-1 \\ 
4  
\end{pmatrix}$ , $\begin{pmatrix}
-2 \\ 
1 \\ 
4  
\end{pmatrix}$ , $\begin{pmatrix}
-1 \\ 
1 \\ 
1 
\end{pmatrix}$ }
Now, in my notes they say that the matrix P is constituted of the vectors of the basis found.
So, P = $\begin{pmatrix}
-1 & -2  & -1\\ 
 -1 & 1  & 1\\ 
 4 & 4   & 1 
\end{pmatrix}$
Also, because we have a 3x3 matrix and we've found three distinct eigen values, the matrix D exists and as such we put the eigen values on the diagonal line of the matrix. ($E_(\lambda_1) = 0$, $E_(\lambda_2) = 2$, $E_(\lambda_3) = 5$ )
D = $\begin{pmatrix}
0 & 0  & 0\\ 
 0 & 2  & 0\\ 
 0 & 0   & 5 
\end{pmatrix}$
Finally to verify that this is all true I compute $AP = PD$. However I didn't find the same result on the left side and the right side of the equation. Where did I go wrong?
$AP \ne PD$
$\begin{pmatrix}
    0 & -4 &-3\\
 0 & 2  & 1 \\
 0 & 8  & 5 \\
\end{pmatrix} \ne \begin{pmatrix}
    0 & -4 &-5 \\
 0 & 2 & 5 \\
 0 & 8 & 5 \\
\end{pmatrix} $
 [/INST] A quick look at your calculations, I think your last eigen vector is wrong. The last eigen vector is (1, 1, 1) and not (-1, 1, 1). I think that would solve your problem. 
</s>