# maximum and minimum of $\sum_{i=1}^n a_ix_i$

Suppose that $a_i \in \mathbb R$, and $\sqrt{ \sum_{i=1}^n x_i^2} = 1$, what is the maximum value and minimum value of $\sum_{i=1}^n a_ix_i$

By the Cauchy-Schwarz inequality, one has $$|\sum_{i=1}^na_ix_i|\le \sqrt{\sum_{i=1}^na_i^2}\sqrt{\sum_{i=1}^nx_i^2}=\sqrt{\sum_{i=1}^na_i^2}$$ and "=" holds iff $$x_i=\pm\frac{a_i}{\sqrt{\sum_{i=1}^na_i^2}}.$$ Hence $\sum_{i=1}^na_ix_i$ reaches the max $\sqrt{\sum_{i=1}^na_i^2}$ when $x_i=\frac{a_i}{\sqrt{\sum_{i=1}^na_i^2}}$, $i=1,2,\cdots,n$ and the min $-\sqrt{\sum_{i=1}^na_i^2}$ when $x_i=-\frac{a_i}{\sqrt{\sum_{i=1}^na_i^2}}$, $i=1,2,\cdots,n$.

• I am also curious that when will $\sum_{i=1}^n a_ix_i = 0$? – koch Oct 6 '16 at 3:39

Think of this as a constrained optimization problem; you can use Lagrange Multipliers!

Note that all of what follows only works when $\vec{a}$ is not the zero vector; but, when all the $a_i$ are $0$, this problem is pretty boring.

We want to find minimum and maximum of $$f(\vec{x})=\sum_{i=1}^{n}a_ix_i$$ subject to $$g(\vec{x}):=\sum_{i=1}^{n}x_i^2=1.$$ Gradients are easy to compute here: $$\nabla f=\vec{a},\qquad \nabla g=2\vec{x}$$ So, the Lagrange condition is $$\vec{a}=2\lambda\vec{x}.$$ Note that $\lambda\neq0$, as $\vec{a}\neq \vec{0}$. So, we have $$\vec{x}=\frac{\vec{a}}{2\lambda}.$$

Now, we know that $\lvert\vec{x}\rvert=1$, so that $\lvert\lambda\rvert=\frac{\lvert\vec{a}\rvert}{2}$; this leaves us with only two options for $\lambda$.

When $\lambda=\frac{1}{2}\lvert\vec{a}\rvert$, we get $$\vec{x}=\frac{\vec{a}}{\lvert\vec{a}\rvert},$$ and therefore $$f(\vec{x})=\vec{a}\cdot\vec{x}=\frac{\vec{a}\cdot\vec{a}}{\lvert\vec{a}\rvert}=\lvert\vec{a}\rvert.$$ On the other hand, if we take $\lambda=-\frac{1}{2}\lvert\vec{a}\rvert$, we end up with $$f(\vec{x})=\vec{a}\cdot\vec{x}=-\lvert\vec{a}\rvert.$$

These will be your max and min!