Questions on eigenvalues with parameter 
Consider the matrix $B = \begin{pmatrix} a^2 & 0 & 0 \\ 0 & 2 & -1 \\
0 & a+2 & -a-1\end{pmatrix}$, with parameter $a \in \mathbb{R}$.
  
  
*
  
*Find the eigenvalues of $B$.
  
*For which values of $a$ is matrix $B$ diagonalizable? Give for these values a matrix $P$ such that $P^{-1}AP$ is diagonal.
  

What I've already got:


*

*Eigenvalues: $1,-a,a^2$ (since $\chi_B(x) = (x-a^2)(x+a)(x-1))$.

*I found the following eigenspaces for each of the found eigenvalues:
I) for $\lambda=1$: $\{(0,r,r)^t\mid r\in\mathbb{R}\}$ if $a^2 \ne 1$, and $\{(r,s,s)^t\mid r,s\in\mathbb{R}\}$ if $a^2=1$.
II) for $\lambda=-a$: $\{(0,r,(2+a)r)^t\mid r\in\mathbb{R}\}$ if $a^2+a \ne 0$, and $\{(r,s,(2+a)s)^t\mid r,s\in\mathbb{R}\}$ if $a^2+a=0$.
III) for $\lambda=a^2$: $\{(r,s,(2-a^2)s)^t \mid r,s\in\mathbb{R}\}$ if $a\in\{0,1,-1\}$, and $\{(r,0,0)^t\mid r\in\mathbb{R}\}$ if $a=0,1,-1$.
These answers are correct, I'm just giving them to make sure that you won't have to do lots of calculations. So, now I'm stuck with the rest of question 2. I think that $B$ will be diagonalizable for $a \notin \{ 0,1, -1\}$.
However the provided solutions tell me something more:


*

*$B$ is diagonalizable for $a \notin \{0,1,-1\}$ and $P = \begin{pmatrix} 0&0&1\\1&1&0\\1&a+2&0\end{pmatrix}$.

*$B$ is diagonalizable for $a=0$ with $P= \begin{pmatrix}0&0&1\\1&1&0\\1&2&0\end{pmatrix}$

*$B$ is diagonalizable for $a=1$ with $P= \begin{pmatrix}0&0&1\\1&1&0\\1&3&0\end{pmatrix}$

*$B$ is not diagonalizable for $a=-1$.


I don't understand how the values for which $B$ is a diagonalizable matrix are determined, and neither do I know how to find the asked matrix $P$.
 A: There are a couple of ways to proceed here. One is to compute an eigenvector for each of the eigenvalues in the general case. Trying to find complete eigenspaces at this stage is jumping the gun a bit since some values of $a$ produce repeated eigenvalues, so you’re going to have to treat those cases specially, anyway.  
By inspection, $(1,0,0)^T$ is an eigenvector corresponding to $a^2$. By summing the second and third columns you can find that $(0,1,1)^T$ is an eigenvector corresponding to $1$ (which is how I found that eigenvalue in the first place), and with a little work (or a bit of cleverness), find $(0,1,a+2)^T$ for $-a$. Now, these three eigenvectors are linearly independent unless $a=-1$, so that’s going to be the only problem case. For all other values of $a$, you have a set of three linearly-independent eigenvectors, so $B$ is diagonalizable even if it has repeated eigenvalues. When $a=-1$, you can check that the only eigenvectors of $\lambda=-a=1$ are multiples of $(0,1,1)^T$, so this eigenvalue is defective and $B$ is not diagonalizable.  
In this problem, diagonalizability can be determined without computing any eigenvectors at all. Observe that for $a\notin\{-1,0,1\}$ the three eigenvalues are distinct, so $B$ must be diagonalizable. When $a=-1$, the only eigenvalue is $1$. The only diagonalizable $3\times3$ matrix that has an eigenvalue of $1$ with algebraic multiplicity $3$ is the identity, but $B$ is obviously not the identity matrix for any value of $a$, so in this case $B$ is not diagonalizable. For the other two cases, examine $B-\lambda I$ for the repeated eigenvalue: we have $$\begin{bmatrix}0&0&0\\0&2&-1\\0&2&-1\end{bmatrix}\text{ and }\begin{bmatrix}0&0&0\\0&1&-1\\0&3&-3\end{bmatrix}.$$ Both of these quite obviously have rank one, so their null spaces—the corresponding eigenspaces of $B$—are two-dimensional, hence $B$ is diagonalizable in both cases. If you didn’t happen to know that the only diagonalizable matrix with only one eigenvalue is the identity, you could instead examine $B-\lambda I$ for $a=-1$: it is $$\begin{bmatrix}0&0&0\\0&1&-1\\0&1&-1\end{bmatrix}.$$ This is also a rank-one matrix, but that only gives you a two-dimensional eigenspace when you need a three-dimensional one since that’s the algebraic multiplicity of the only eigenvalue.
A: A matrix $A \in \mathbb{R}^{n \times n}$ is diagonalizable if and only if it has $n$ linearly independent eigenvectors. If this is the case and there exists a $P$ such that $P^{-1}AP$ is a diagonal matrix, the columns of $P$ will be the basis vectors for the eigenspace of $A$. Note that this holds for the vectors you found setting $r=1, s=0$. If $a=-1$ the eignevectors of $A$ are no longer linearly independent, and thus $A$ is not diagonalizable.
