Let $M$ be a subspace of $R^n$ and $z\notin M$. Show that the orthogonal proyection of $z$ in $M$ is $\bar x$ if and only if:
$(z-\bar x,x)=0, $ $ \forall x \in M$
How can i prove it? I know that for a convex, closed and not empty $C \subset R^n$, there is an only $\bar x \in C$ orthogonal projection of $z$ in $C$, that:
$(x-\bar x,\bar x-z)\geq 0, $ $ \forall x \in C$
But i dont know how can i used it for the proof.