Proving an endomorphism is an orthogonal projection. In this exercise $n$ is an integer >= 1.
We consider the column matrix 
$Z=\begin{pmatrix} 1  \\ 1  \\ 1 \\ \vdots \\ 1 \end{pmatrix}$
We define the two following matrices : $J=Z.Z^{t}$ and $P=I_{n} - \frac{1}{n}J$ where $I_{n}$ is the identity matrix.
We consider the vector space $\mathbb{R}^{n}$ with the standard inner product , and the space $M_{n}(\mathbb{R})$ of square matrices with the inner product $(M|N)=tr(M^{t}.N)$ where tr denotes the trace of a matrix.
1)Let $f$ be an endomorphism of $\mathbb{R}^{n}$ whose representation in the standard basis is the matrix $P$.Show that $f$ is an orthogonal projection.
What i tried:
Let $e_1=(1,0,0,0,\cdots,0)$
$f(e_{1}) = Pe_{1}=(I_{n} - \frac{1}{n}J)e_1{}=e_1{}-\frac{1}{n}Je_{1}$
Let $v=Je_{1}=(1,1,1,1,\cdots,1)$
$(v|v)=tr(v^{t}.v)=n$
$(e_{1}|v) = tr (e_{1}^{t}.v)=1$
Hence $f(e_{1})=e_{1}-\frac{(e_1{}|v)}{(v|v)}v.$
This seems a lot like the Gram–Schmidt formula to orthogonalize a vector,however doesn't this mean that only the 2nd term is equivalent to a projection?
Thanks in advance.
 A: $J=ZZ^T$, so $J^2 = (ZZ^T)(ZZ^T)=Z(Z^TT)Z^T = nZZ^T=nJ$
$$P^2=(I_N-\frac1nJ)^2=I_n^2-\frac2nJ+\frac1{n^2}J^2=I_n-\frac2nJ+\frac1{n^2}nJ=$$
$$I_n-\frac2nJ+\frac1{n}J=I_n-\frac1nJ=P$$
This shows that $P$ is a projection matrix.
$J^T=(ZZ^T)^T=(Z^T)^TZ^T = ZZ^T=J$
So $P^T=  (I_n−\frac1nJ)^T=I_N^T-\frac1nJ^T = I_n−\frac1nJ=P$
This shows $P$ is orthogonal.
A: Note that with
$Z = \begin{pmatrix} 1 \\ 1 \\ \vdots \\ 1 \end{pmatrix}, \; J = ZZ^T, \tag 1$
we have
$J^2 = (ZZ^T)^2 = (ZZ^T)(ZZ^T) = Z(Z^TZ)Z^T; \tag 2$
also, it is easy to see that
$Z^TZ = n; \tag 3$
thus
$J^2 = Z(n)Z^T = n ZZ^T = nJ. \tag 4$
Now with
$P = I - \dfrac{1}{n}J, \tag 5$
we have
$P^2 = I^2 - 2I (\dfrac{1}{n}J) + \dfrac{1}{n^2}J^2 = I - \dfrac{2}{n}J + \dfrac{n}{n^2}J = I - \dfrac{2}{n}J + \dfrac{1}{n}J = I - \dfrac{1}{n}J = P, \tag 6$
which shows that $P$ is a projection.  
To see that $P$ is orthogonal, we observe that for any symmetric matrix $A = A^T$, 
$\ker A\; \bot \; \text{range}(A); \tag 7$
indeed,
$y \in \text{range}(A) \Longrightarrow \exists x \in \Bbb R^n, \; y = Ax; \tag 8$
then if
$z \in \ker A, \tag 9$
$\langle z, y \rangle = \langle z, Ax \rangle = \langle A^Tz, x \rangle = \langle Az, x \rangle = \langle 0, x \rangle = 0; \tag{10}$
we next merely observe that
$P^T = (I - \dfrac{1}{n}J)^T = I^T - \dfrac{1}{n}J^T = I - \dfrac{1}{n}J = P, \tag{11}$
and it follows from (7) that 
$\ker P\; \bot \; \text{range}(P), \tag {12}$
and we conclude that $P$ is in fact an orthogonal projection.
Note Added in Edit, Monday 25 June 2018 12:15 PM PST:  I think it further worth observing that the answer given above allows us to find both $\ker P$ and $\text{range}(P)$ without too much more effort.  Indeed, if $k \in \ker P$, then
$k - \dfrac{1}{n}Jk = (I - \dfrac{1}{n}J)k = Pk = 0, \tag{13}$
whence
$k = \dfrac{1}{n}Jk = \dfrac{1}{n}ZZ^Tk = \dfrac{Z^Tk}{n} Z = \dfrac{1}{n}\left ( \displaystyle \sum_1^n k_j \right ) Z; \tag{14}$
(14) tells us that
$k_i = \dfrac{1}{n} \displaystyle \sum_1^n k_j; \tag{15}$
that is, that every entry of $k$ is the average of all the entries of $k$, whence $k_i = k_j, \; \forall 1 \le i, j \le n$; we thus have
$k = k_i (1, 1, \ldots, 1)^T = k_iZ, \; 1 \le i \le n; \tag{16}$
we see that $\ker P$ is a one-dimensional subspace of $\Bbb R^n$; we now use (12) to find $\text{range}(P)$; we see that the vectors
$e_j = (1, 0, \ldots, -\delta_{jk}, \ldots, 0)^T, \tag{17}$
that is, vectors which have $1$ as their first entry and $-1$ as their $j$-th element, their other entries being $0$, are all orthogonal to $k$:
$e_j \cdot k = 0; \tag{18}$
it is easy to see the $n - 1$ $e_j$ are linearly independent, since
$\displaystyle \sum_2^n \alpha_j e_j = \left ( \sum_2^n \alpha_j, -\alpha_2, -\alpha_3, \ldots, -\alpha_n \right )^T = 0 \Longrightarrow \alpha_j = 0, \; 2 \le j \le n; \tag{19}$
thus we see that 
$\text{range}(P) = \text{span}(\{e_2, e_3, \ldots, e_n\}), \tag{20}$
is an $n - 1$ dimensional subspace of $\Bbb R^n$.  End of Note.
