<s>[INST] Find the symmetric matrix given its eigenvalues and eigenvector. 
$A$ is a $3 \times 3$ symmetric matrix. It has the eigenvalue $\lambda_1 = 3$ with the eigenvector
$$
\begin{bmatrix} 
1 \\ 0 \\ -1 
\end{bmatrix}
$$
and a double eigenvalue $\lambda_2 = -1$.
Find the matrix $A$.

Since $A$ is symmetric, it can be diagonalized orthogonally, with an orthogonal matrix $P$ as $A = PDP^T$. The matrix is made of the eigenvectors that are orthogonal to each other. What I then did was with the help of inner product, I got a vector that is orthogonal to $v_1$ and with the help of cross product I got another orthogonal vector. Those vectors are
$$
\begin{bmatrix} 
1 \\ 1 \\ 1 
\end{bmatrix}
\quad\text{and}\quad 
\begin{bmatrix} 
1 \\ -2 \\ 1 
\end{bmatrix}
$$
so
$$
A = PDP^{-1} 
= \begin{bmatrix} 
 1 &  1 & -5 \\ 
 1 & -5 &  1 \\ 
-5 &  1 & -5 
\end{bmatrix}. 
$$
But my answer is wrong obviously since $Av \neq \lambda v$. The answer is
$$
\begin{bmatrix} 
 1 &  0 & -2 \\ 
 0 & -1 &  0 \\ 
-2 &  0 & 1 
\end{bmatrix}
$$
where the vectors are
$v_2 = \begin{bmatrix} 1 & 0 & 1 \end{bmatrix}^T$ and
$\begin{bmatrix} 0 & 1 & 0 \end{bmatrix}^T$. The answer sheet says that these vectors are orthogonal to $v_1$. Also they didn't do $A = PDP^T$ instead they did $A = PDP^{-1}$. Can anyone help me understand?
 [/INST] (I will use row vectors because they are easier to type and use up less space; interpret them as transposes of the vectors you want)
Symmetric matrices are always orthogonally diagonalizable. So we know that the eigenspace of $-1$ will be the orthogonal complement of the eigenspace of $3$; you know the eigenspace of $3$ is $\mathrm{span}\bigl((1,0,-1)\bigr)$. So a basis of eigenvectors is obtained by finding the orthogonal complement of this span, and taking an basis for it (and you might as well make it orthogonal). There are multiple ways of doing this. The most mindless/automatic is to start with $(1,0,-1)$, complete to a basis, and then apply the orthogonalization part of the Gram-Schmidt process. Doing slightly less work and more thought, we might notice that $(0,1,0)$ and $(1,0,1)$ are both orthogonal to the vector we already had, and also orthogonal to each other, so these two will do, as will any two vectors that are orthogonal to each other and to $(1,0,-1)$. Your choice of $(1,1,1)$ and $(1,-2,1)$ is certainly a valid choice.
Now, if we let $\beta=[(1,0,-1),(1,1,1),(1,-2,1)]$ be an ordered orthogonal basis for $\mathbb{R}^3$, then we know that if $Q$ is the change-of-basis matrix from the standard basis to $\beta$, then
$$QAQ^{-1} = \left(\begin{array}{rrr}
3 & 0 & 0\\
0 & -1 & 0\\
0 & 0 & -1
\end{array}\right).$$
That means that if we let $P$ be the inverse of $Q$, so that $P=Q^{-1}$ is the change-of-basis matrix fvrom $\beta$ to the standard basis, then
$$A = P\left(\begin{array}{rrr}
3 & 0 & 0\\
0 & -1 & 0\\
0 & 0 & -1
\end{array}\right)P^{-1}.$$
I don't know how you did the calculations. The matrix $P$ has the vectors of $\beta$ as columns,
$$P = \left(\begin{array}{rrr}
1 & 1 & 1\\
0 & 1 & -2\\
-1 & 1 & 1
\end{array}\right).$$
Its inverse is given by
$$P^{-1} = \left(\begin{array}{rrr}
\frac{1}{2}_{\vphantom{2_2}} & 0 & -\frac{1}{2}\\
\frac{1}{3}_{\vphantom{2_2}} & \frac{1}{3} & \frac{1}{3}\\
\frac{1}{6} & -\frac{1}{3} & \frac{1}{6}
\end{array}\right),$$
which can be computed by hand (or with a calculator), and verified by multiplying them together. Note that because the columns of $P$ are not an orthonormal basis (although they are mutually orthogonal, the vectors do not have size $1$), the inverse of $P$ is not merely $P^T$.
So we get
$$\begin{align*}
A &= P\left(\begin{array}{rrr}
3 & 0 & 0\\
0 & -1 & 0\\
0 & 0 & -1
\end{array}\right)P^{-1}\\
&= \left(\begin{array}{rrr}
1 & 1 & 1\\
0 & 1 & -2\\
-1 & 1 & 1
\end{array}\right) \left(\begin{array}{rrr}
3 & 0 & 0\\
0 & -1 & 0\\
0 & 0 & -1
\end{array}\right)
\left(\begin{array}{rrr}
\frac{1}{2}_{\vphantom{2_2}} & 0 & -\frac{1}{2}\\
\frac{1}{3}_{\vphantom{2_2}} & \frac{1}{3} & \frac{1}{3}\\
\frac{1}{6} & -\frac{1}{3} & \frac{1}{6}
\end{array}\right)\\
&= \left(\begin{array}{rrr}
3 & -1 & -1\\
0 & -1 & 2\\
-3 & -1 & -1
\end{array}\right)
\left(\begin{array}{rrr}
\frac{1}{2}_{\vphantom{2_2}} & 0 & -\frac{1}{2}\\
\frac{1}{3}_{\vphantom{2_2}} & \frac{1}{3} & \frac{1}{3}\\
\frac{1}{6} & -\frac{1}{3} & \frac{1}{6}
\end{array}\right)\\
&=\left(\begin{array}{rrr}
1 & 0 & -2\\
0 & -1 & 0\\
-2 & 0 & 1
\end{array}\right),
\end{align*}$$
which is the same as the answer they gave.
From what I can tell, you mistakenly compute $PDP^T$ instead of $PDP^{-1}$. Note that because you do not have an orthonormal basis, the inverse of $P$ is not $P^T$, as noted above. That is the source of your error. Had you used $P^{-1}$ instead of $P$, you would have obtained the same matrix $A$.
</s>