TITLE: Prove you can choose orthonormal bases of any two subspaces of Euclidean space such that $(e_i, f_j)=0$ if $ i\neq j $
QUESTION [7 upvotes]: Prove you can choose orthonormal bases $(e_1,...,e_k)$ and $(f_1,...,f_j)$ of any two subspaces of Euclidean space such that $(e_i, f_j)=0$ if $i\neq j$ and $(e_i, f_j) \geq 0$
This is a question from a question bank my teacher linked to us. 
The way I want to approach it is to let $(e_1,...,e_k)$ be the standard basis and then define some sort of map that will ensure $(e_i, f_j)=0$ $\forall$ $i\neq j$
I'm struggling with being able to come up with this map on my own. Any help would be appreciated.

REPLY [2 votes]: Call the two subspaces $V,W$, and call $p_V,p_W$ the orthogonal projections onto these subspaces.
The question is not easy, since not all vectors are candidate for being element of such a basis. If $v\in V$ is such that $p_W(v)\neq 0$, then taking $p=e_i$ forces $f_i$ to be a scalar multiple of $p_W(v)$, as it must be perpendicular to all other $f_j\in W$, which are perpendicular to $v$ and therefore to $p_W(v)$. But similarly $v=e_i$ must be a scalar multiple of$~p_V(f_i)$, and one concludes that $v$ must be an eigenvector for the linear operator $(p_V\circ p_W)|_V$ on $V$.
Given this, it is not surprising that one should invoke the spectral theorem. Let $B$ be the bilinear form on$~V$ defined by $B(v,v')=(p_W(v),p_W(v'))$. (Alternative expressions for $B(v,v')$ are $(p_W(v),v')$ or $(p_V(p_W(v)),v')$.) This bilinear form is clearly symmetric, so by the spectral theorem there exists an orthonormal basis of $V$ which is also orthogonal for$~B$ (this is the same thing as an orthonormal basis of eigenvectors for $(p_V\circ p_W)|_V$). Since $0\leq B(v,v)\leq(v,v)$ for all$~V$, the eigenvalues of $(p_V\circ p_W)|_V$ lie in the interval $[0,1]$, in particular they are non-negative. Now one can take the $e_i$ to run through such a basis, starting with those that have nonzero eigenvalues for $(p_V\circ p_W)|_V$, or what amounts to the same, nonzero images by$~p_W$. If there are $k$ such vectors, the first $k$ vectors $f_i$ can be taken to be $p_W(e_i)$ normalised to unit length by a positive scalar. One can complete these to an orthonormal basis of $W$ with any orthonormal basis of $W\cap V^\perp$. Checking the required properties is easy (and done in the  answer by Alex Zorn).