how can i find the matrix $P$ that diagonalizes the matrix $A$? I want to find matrix $P$ that diagonalizes the matrix $A$:
$$
        \begin{bmatrix}
        4 & 0 & 1 \\
        2 & 3 & 2 \\
        1 & 0 & 4 \\
        \end{bmatrix}
$$
 A: You need to calculate the eigenvectors which are (1,2,1), (-1,0-1) and (0,1,0). So we have the passage matrix
\begin{equation}P=\left(\begin{array}{ccc}
1 & -1& 0\\
2 & 0 & 1\\
1 & 1 & 0
\end{array}\right)
\end{equation}
\begin{equation}P^{-1}=\left(\begin{array}{ccc}
1/2 & 0& 1/2\\
-1/2 & 0 & 1/2\\
-1 & 1 & -1
\end{array}\right)
\end{equation}
The inverse of P is
\begin{equation}D=P^{-1}AP=\left(\begin{array}{ccc}
5 & 0& 0\\
0 & 3 & 0\\
0 & 0 & 3
\end{array}\right)
\end{equation}
So we have the diagonalization
A: Hint: The columns of $P$ are precisely the eigenvectors of $A$.
A: Suppose that $A$ has eigenvalues $\lambda_1,\lambda_2,\lambda_3$. Let $v_1,v_2,v_3$ be the associated eigenvectors. Let $D$ be the diagonal matrix with diagonal entries $\lambda_1,\lambda_2,\lambda_3$. Let $P$ be the matrix whose columns are $v_1,v_2,v_3$ in that order. 
Then, we have $P^{-1}AP = D$, which is to say that $P$ diagonalizes $A$.
A: The general procedure to diagonalize $A$ is to solve $$A\vec x=\lambda \vec x$$
Then find the eigenvalues $\lambda$ by solving the characteristic equation $$\det(A-\lambda I)=0$$ where $I$ is the identity matrix. 
Now for each eigenvalue $\lambda_i$, find the associated eigenvector $x_i$, by solving the homogeneous equation $$(A-\lambda_i I)x_i=0$$ Construct the matrix of eigenvectors $$S=(x_1,x_2,x_3,\cdots , x_n)$$
The last step is $$P=S^{-1}AS$$ where $$P=\mathrm{diag}(\lambda_1,\lambda_2,\lambda_3,\cdots , \lambda_n)$$ is the diagonalized matrix with the eigenvalues along the main diagonal.   
In response to the comment below if:
$$B=
        \begin{bmatrix}
        \lambda-4 & 0 & 7\\
        2 & \lambda & 0 \\
        0 & 2\lambda & 1 \\
        \end{bmatrix}
$$
then 
$$\det(B-\lambda I)=0\implies\det\left(
        \begin{bmatrix}
        \lambda-4 & 0 & 7\\
        2 & \lambda & 0 \\
        0 & 2\lambda & 1 \\
        \end{bmatrix}-\begin{bmatrix}
        \lambda & 0 & 0\\
        0 & \lambda & 0 \\
        0 & 0 & \lambda \\
        \end{bmatrix}\right)=0
$$
$$\implies \det
        \begin{pmatrix}
        -4 & 0 & 7\\
        2 & 0 & 0 \\
        0 & 2\lambda & 1-\lambda \\
        \end{pmatrix}=0
$$
