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}
$$

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
$$
