Finding the closest point on a hyperplane to a given point Let $P_1, \cdots, P_k$ be a set of point in $\mathbb R^n$ such that $k \le n$. Let $C$ be a point in $\mathbb R^n$ too. How can I find the closest point on the $(k-1)$-dimensional hyperplane containing $P_1, \cdots, P_k$ to $C$. Formally, I want to,
$$
\text{minimize} \;d(C, \sum_{i=1}^k \alpha_i P_i) \quad \text{s.t.} \sum_i \alpha_i=1
$$
where $d(\cdot)$ denote the Euclidean distance.
 A: First, let's suppose that mentioned hyperplane passes through the origin. We can always reduce initial task to this setting by translation (finding the distance is translation invariant problem). Let $P$ be the linear span of vectors $P_1, \dots, P_k$ and let $P^{\bot}$ be the orthogonal complement to $P$ in $\mathbb{R}^n$. Since 
$\mathbb{R}^n$ is a direct sum of $P$ and $P^{\bot}$ any vector (and $C$ too) can be represented uniquely as a sum $p + p^{\bot}$, $p \in P$, $p^{\bot} \in P^{\bot}$. That is, $C = c + c^{\bot}$. So, now we have to find vector $p' \in P$ such that $(p'-C, p'-C)$ is
minimal among all $\tilde{p} \in P$. Using the dot product properties, representation for $S$ and orthogonality of $P$ and $P^{\bot}$ we get the following consequence:
$$ (p'-C, p'-C) = (p'- c - c^{\bot}, p'- c - c^{\bot}) = (p'-c, p'-c) + (c^{\bot}, c^{\bot}) $$
This dot product is always greater than $(c^{\bot}, c^{\bot})$ and achieves that value if and only if we take $p'$ equal to $c$. This is an answer for a problem in case of subspaces: take a point $C$ and find its projection on the $P$. This can be done using orthogonal basis in $P$ and dotproduct of $C$ with basis vectors. 
