Solution (source code)

= Solution

Extend the selected $\ell_1$ to an <orthonormal basis> of <eigenvectors>, writing it as $v_1$. For a <unit vector> orthogonal to it, $a_1=0$, and therefore
$$
\operatorname{Var}(\ell^TX)=\sum_{j=2}^{p}\lambda_ja_j^2\leq\lambda_2.
$$
A unit <eigenvector> $v_2$ attains equality. Thus \b[$\ell_2$ is a unit <eigenvector> for the largest <eigenvalue> on $\ell_1^\perp$, and the maximum is $\lambda_2$]. If the largest <eigenvalue> is repeated, a second orthogonal vector in that <eigenspace> is allowed and $\lambda_2=\lambda_1$; there is no uniquely determined first pair of directions.