What am I doing wrong (matrix diagonalization)? I have $3$ eigenvectors $v_1=(0,2,0)$, $v_2=(1,0,-1)$ and $v_3=(-1,0,-1)$ and the corresponding eigenvalues of $\lambda_1=-1$, $\lambda_2=2$ and $\lambda_3=2$. Vectors $v_2$ and $v_3$ form the basis $\{v_2, v_3\}$ for the eigenspace $E(2, A)$, where $A$ is a matrix I need to determine.
I thought of calculating matrix $A$ using diagonalization ($A=PDP^{-1}$), which seems to be quite straightforward since I have the eigenvalues needed to construct the diagonal matrix and $v_1, v_2$ and $v_3$ are all linearly independent so they form a basis, thus giving the required invertible $P=[v_1, v_2, v_3]$.
Essentially all I've done is basic matrix multiplication and I end up with another diagonal matrix... I have no idea what I'm doing wrong.
 A: There is nothing wrong here, though it looks a bit mysterious at first sight.
Your matrix $A$ really is:
$$A=\begin{pmatrix}2 & 0 & 0 \\ 0 & -1 & 0 \\ 0 & 0 & 2\end{pmatrix}$$
Now, what are its eigenvalues an eigenspaces? Well, since it's already diagonal, it's not difficult to see that the eigenvalue $-1$ is associated with the eigenvector $u_1=(0,1,0)$, and any nonzero multiple of $u_1$ is a valid eigenvector, e.g. $v_1=2u_1$.
The eigenvalue $2$ is associated with eigenvectors $u_2=(1,0,0)$ and $u_3=(0,0,1)$, i.e. the eigenspace is $\mathrm{span}(u_2,u_3)$, and any pair of independent eigenvectors formed as a linear combination of $u_2$ and $u_3$ is again a basis of the associated eigenspace. For instance, $v_2=u_3-u_3$ and $v_3=-u_2-u_3$.
The diagonalization you were given is indeed a valid diagonalization of the diagonal matrix $A$. Of course, you might as well write $A=PDP^{-1}$ with $P=I$ and $D=\mathrm{diag}(2,-1,2)$, but it's not forbidden to pick other eigenvectors.
And the "order" of eigenvalues in $D$ changed because in $A$ the eigenvalue $-1$ is in the middle, whereas you have written $A=PDP^{-1}$ with $D=\mathrm{diag}(-1,2,2)$, but this has no impact on the value of $A$: with $D=\mathrm{diag}(2,-1,2)$, you could pick the eigenvectors $[u_2,u_1,u_3]$ in this order, and $P=I$ as expected. But again, $[v_2,v_1,v_3]$ is also valid, as well as $[v_3,v_1,v_2]$. And $D=\mathrm{diag}(2,2,-1)$ would also lead to $A$. The order of eigenvalues in $D$ does not change the value of $A$ (provided you change the order of eigenvectors as well).
