Conditions for symmetry for pair of commuting matrices Let A = $\left(\begin{array}{ccc}
2 & -1 & 0  \\
-1 & 2 & -1  \\
0 & -1 & 2 
\end{array} \right)$
Show that every real matrix $B$ such that $AB = BA$ has the form $B = aI + bA + cA^2$
My attempt: If we assume that $AB = BA$ are simultaneously diagonalizable by $P$, then since $A = PDP^{-1}$we have the RHS expression to be $aPIP^{-1} + bPDP^{-1} + cPD^2P^{-1}$. Computing $D$, we observe that $I$ and $D$ and $D^2$ are linearly independent, and thus they span all 3X3 diagonal matrices, diagonalized B included.
But $A$ and $B$ are simultaneously diagonalizable iff the commute and they are both diagonalizable. Now $A$ is real symmetric so it is diagonalizable, but what can we say about $B$?
It looks like $B$ wants to be symmetric. But A symmetric and $AB=BA$ does not imply B is symmetric, take $A = I$ for instance. So I have two questions:
1) Under what conditions for A will the statement ($A$ symmetric and $AB= BA) \Rightarrow B$ symmetric hold?
2) If my approach does not work, does anyone have any other way of proceeding?
 A: This particular $A$ has distinct eigenvalues (it's not hard to factor the characteristic polynomial).  Every matrix $B$ that commutes with $A$ must preserve the eigenspaces, thus the eigenvectors of $A$ must be eigenvectors of $B$, and in particular $B$ is diagonalizable.  
If a symmetric matrix does not have distinct eigenvalues, there will be 
matrices that commute with it but are not diagonalizable.  For example, if $v$ and $w$ are orthogonal eigenvectors of $A$ for the same eigenvalue, 
$ v w^T$ is such a matrix (note that its square is $0$). 
A: We can prove the statement by brute force.
Search a matrix $B$ the commute with $A$:
$$
\begin{bmatrix}
2&-1&0\\
-1&2&-1\\
0&-1&2
\end{bmatrix}
\begin{bmatrix}
x_1&y_1&z_1\\
x_2&y_2&z_2\\
x_3&y_3&z_3
\end{bmatrix}=
\begin{bmatrix}
x_1&y_1&z_1\\
x_2&y_2&z_2\\
x_3&y_3&z_3
\end{bmatrix}
\begin{bmatrix}
2&-1&0\\
-1&2&-1\\
0&-1&2
\end{bmatrix}
$$
wit a bit of work, equating the corresponding entries of the two products, we find that $B$ has the form:
$$
B=\begin{bmatrix}
x&y&z\\
y&x+z&y\\
z&y&x
\end{bmatrix}
$$
Now:
$$aI+bA+cA^2=
a\begin{bmatrix}
1&0&0\\
0&1&0\\
0&0&1
\end{bmatrix}+b
\begin{bmatrix}
2&-1&0\\
-1&2&-1\\
0&-1&2
\end{bmatrix}+c
\begin{bmatrix}
5&-4&1\\
-4&6&-4\\
1&-4&5
\end{bmatrix}=
\begin{bmatrix}
2a+2b+5c&-b-4c&c\\
-b-4c&a+2b+6c&-b-4c\\
c&-b-4c&a+2b+5c
\end{bmatrix}
$$
tha has the form of $B$ for $x=2a+2b+5c$, $y=-b-4c$ and $z=c$.
