Projection on the hyperplane $H: \sum x_i=0$ Consider the hyperplane $H: \sum_{i=1}^n x_i=0$. Let $P$ denote the orthogonal projection onto $H$. What exactly is the matrix $P$ and how do we find it?
 A: When $H\subseteq\Bbb{R}^n$ is the hyperplane through the origin, and $\vec{n}$ is the normal of $H$, the orthogonal projection $p:\Bbb{R}^n\to H$ is given by the recipe
$$
p(\vec{x})=\vec{x}-\frac{\vec{x}\cdot\vec{n}}{||\vec{n}||^2}\vec{n}.
$$
You can verify the recipe by checking that i) $p(\vec{x})\perp\vec{n}$ for all $\vec{x}$ and ii) $p(\vec{x})=\vec{x}$ whenever $\vec{x}\perp\vec{n}$.
You then get the matrix $P$ by the usual process of calculating the images of your basis vectors.
A: The hyperplane $H$ is the orthogonal subspace of $(1,1,\ldots,1)^T$. It follows that the projection of $v\in\mathbb{R}^n$ on $H$ is a vector of the form $v-\lambda(1,1,\ldots,1)^T$ with the sum of its coordinates being zero. If we assume $v=(v_1,v_2,\ldots,v_n)^T$, we have that the projection $\pi_H$ on $H$ acts in the following way:
$$ \pi_H : (v_1,v_2,\ldots,v_n)^T \mapsto (v_1,v_2,\ldots,v_n)^T-\left(\frac{1}{n}\sum_{k=1}^{n}v_k\right)\cdot (1,1,\ldots,1)^T $$
hence the matrix $P$ representing $\pi_H$ has the following structure:
$$ P = \begin{pmatrix}1-\frac{1}{n} & -\frac{1}{n}& \ldots & -\frac{1}{n} \\ -\frac{1}{n} & 1-\frac{1}{n} & \ldots & -\frac{1}{n} \\ \ldots & \ldots &1-\frac{1}{n} & \ldots \\ 
-\frac{1}{n} & -\frac{1}{n} & \ldots & 1-\frac{1}{n}\end{pmatrix} = I -\frac{1}{n}\mathbb{1} $$
where $I$ stands for the identity matrix and $\mathbb{1}$ stands for the matrix with every element being equal to one.
