Proof: Suppose \(\{\vec u_1,\dots,\vec u_p\}\) is an orthogonal basis for a subspace \(W\text{.}\) Then, we know that \(\vec u_i \cdot \vec u_j = 0\) for each \(i \neq j\) (since this is an orthogonal set) and \(\vec u_i \cdot \vec u_i \neq 0\) (since \(\vec u_i \neq \vec 0\)). Let \(\vec w \in W\text{.}\) Then, \(\vec w\) can be expressed uniquely as a linear combination of the basis vectors; that is
\begin{equation*}
\vec w = c_1\vec u_1 + c_2\vec u_2 + \cdots + c_p\vec u_p
\end{equation*}
for a unique choice of \(c_1, c_2 ,\dots, c_p\text{.}\) Note what happens if we dot product both sides of the above equation with \(\vec u_k\) for some \(k \in \{1,2,\dots, p\}\text{:}\)
\begin{align*}
\vec w \cdot \vec u_k \amp = (c_1\vec u_1 + \cdots + c_k\vec u_k + \cdots + c_p\vec u_p) \cdot \vec u_k \\
\vec u_k \cdot \vec w \amp = c_1(\vec u_1 \cdot \vec u_k) + \cdots + c_k(\vec u_k \cdot \vec u_k) + \cdots + c_p(\vec u_p \cdot u_k) \\
\vec w \cdot \vec u_k \amp = c_1(0) + \cdots + c_{k-1}(0) + c_k(\vec u_k \cdot \vec u_k) + c_{k+1}(0) + \cdots + c_p(0)
\end{align*}
It follows that
\begin{equation*}
\vec w \cdot \vec u_k = c_k(\vec u_k \cdot \vec u_k)\text{.}
\end{equation*}
Since \(\vec u_k \cdot \vec u_k \neq 0\text{,}\) we divide both sides by that quantity to get
\begin{equation*}
c_k = \dfrac{\vec w \cdot \vec u_k}{\vec u_k \cdot \vec u_k}\text{.}
\end{equation*}