this might be a dumb question, but I was working on a problem and ran into the following (sub)problem.


Suppose we have a nonnegative vector $\pi \in \mathbf{R}^n$ that satisfies $\sum\_{i=1}^n \pi\_i = 1$, i.e., it is a discrete probability density. We want to choose a unit vector $v \in \mathbf{R}^n$, $\|v\|=1$, where $\| \cdot \|$ is the Euclidean norm, such that the "variance" 


$f(v) = \sum\_{i=1}^n v\_i^2 \pi\_i - (\sum\_{i=1}^n v\_i \pi\_i)^2$


is maximized. Of course there will be multiple maxima, because $f(v) = f(-v)$. 


Is there any closed form solutions for the maximum $v$ or any ideas how to find it, or what is the maximum function value $f(v)$?
Specifically, I want to show that if $\pi\_1 > 0.5$, then any maximum $v$ satisfies ${\rm sign}(v\_1) = -{\rm sign}(v\_i)$ for all $i \neq 1$.


Any tips or ideas? Thank you very much!



A unit vector that maximizes variance in a discrete probability distribution
Define the $n\times n$ symmetric matrix $M$ with elements
$$M\_{ij}=\pi\_i \delta\_{ij}-\pi\_i\pi\_j.$$
We seek to maximise the quadratic form
$$f(v)=\sum\_{ij} v\_i M\_{ij} v\_j$$
where $v$ is a vector on the unit $n$-sphere. An extremum is reached for an eigenvector $v\_0$ of $M$ and $f(v\_0)=\mu\_0$ is the corresponding eigenvalue $\mu\_0$ of $M$. For the global maximum we should take the eigenvector $v\_{\rm max}$ with the largest eigenvalue $\mu\_{\rm max}$.  

*This is basically the [min-max theorem,](https://en.wikipedia.org/wiki/Min-max_theorem) for an explicit proof see proposition 6 of [these notes.](http://www.its.caltech.edu/~kcborder/Notes/QuadraticForms.pdf)*


The eigenvalues $\mu$ of $M$ are determined by the equation
$$1+\sum\_{i}\frac{\pi\_i^2}{\mu-\pi\_i}=0.$$
This follows from the [Matrix determinant lemma,](https://en.wikipedia.org/wiki/Matrix_determinant_lemma) see this [MO posting](https://mathoverflow.net/a/67935/11260) for a derivation.


The smallest eigenvalue $\mu=0$ has eigenvector with all elements $1\sqrt n$. Since the eigenvectors are orthogonal, the desired $v\_{\rm max}$ should satisfy 
$$\sum\_{i}(v\_{\rm max})\_i=0.$$


I don't think a closed form expression for $v\_{\rm max}$ exists for arbitrary $n$. 


For $n=2$ one has simply $v\_{\rm max}=(1/\sqrt 2,-1/\sqrt 2)$ independent of $\pi$, but already for $n=3$ the expression is complicated:
$$v\_{\rm max}=\{\pi\_2(\pi\_1-\pi\_3)+\sqrt X,\pi\_1(\pi\_3-\pi\_2)-\sqrt X, \pi\_3(\pi\_2-\pi\_1)\}$$
$$X=\pi\_1^4+2 \pi\_1^3 (\pi\_2-1)+\pi\_1^2 (3\pi\_2^2 -\pi\_2+1)+\pi\_1 (\pi\_2-1) \pi\_2 (2 \pi\_2+1)+(\pi\_2-1)^2 \pi\_2^2,$$
where $v\_{\rm max}$ is still to be normalized to unit length. The corresponding $\mu\_{\rm max}$ is
$$\mu\_{\rm max}=\sqrt{\left(\pi\_1^2- (1-\pi\_2)(1-\pi\_3)\right)^2-3 \pi\_1 \pi\_2 \pi\_3}-\pi\_1^2-\pi\_2^2-\pi\_1 \pi\_2+\pi\_1+\pi\_2.$$


