I am trying to find the matrix of the projection in $\mathbb{R}^3$ onto the line spanned by the vector $\vec{w}=[1,1,1]$. The way I thought I should find the matrix is by taking
$$\frac{(\vec{x} \cdot \vec{w}) \, \vec{w}}{\vec{w} \cdot \vec{w}} = \frac{x_1 +x_2+x_3}{3} \begin{bmatrix} 1\\1\\1 \end{bmatrix} $$
So the final matrix is $$\frac{1}{3} \begin{bmatrix} 1\ 1\ 1\\ 1\ 1\ 1\\ 1\ 1\ 1 \end{bmatrix}$$
This seems wrong to me, but I can't figure what mistake I made.
The length of the projection of a vector ${\bf x}$ onto ${\bf w}$ can be written as
$$ x_w = {\bf x}\cdot \frac{{\bf w}}{|{\bf w}|} = \frac{{\bf w}^T {\bf x}}{|{\bf w}|} $$
So that the projection vector is
$$ {\bf x}_w = x_w \frac{{\bf w}}{|{\bf w}|} = \frac{{\bf w}^T {\bf x}}{|{\bf w}|} \frac{{\bf w}}{|{\bf w}|} = \frac{{\bf w}{\bf w}^T}{|{\bf w}|^2} {\bf x} = P_w {\bf x} $$
where the projection matrix $P_w$ is
$$ P_w = \frac{{\bf w}{\bf w}^T}{|{\bf w}|^2} $$