How to prove $|\sum_{i=1}^n a_i|\le \sqrt{n} \sqrt{\sum_{i=1}^n a_i^2}$

Let $n$ be a natural number and $a_1,a_2,\ldots,a_n$ are real numbers. Then prove that $|\sum_{i=1}^n a_i|\le \sqrt{n\cdot \sum_{i=1}^n a_i^2}$.

At first I tried to prove for $n=2$ i.e, $|a_1+a_2|\le \sqrt{2(a_1^2+a_2^2)}$, but unable to proceed. Give me some hint to proceed.


It's C-S: $$\sqrt{n}\sqrt{\sum_{i=1}^na_i}=\sqrt{\sum_{i=1}^n1^2\sum_{i=1}^na_i^2}\geq\sqrt{\left(\sum_{i=1}^na_i\right)^2}=\left|\sum_{i=1}^na_i\right|.$$ We can use also the following way.

Since our inequality is homogeneous and does not depend on the substitution $a_i\rightarrow-a_i$,

we can assume that $\sum\limits_{i=1}^na_i=n.$

Thus, we need to prove that $$n\sum_{i=1}^na_i^2\geq\left(\sum_{i=1}^na_i\right)^2$$ or $$\sum_{i=1}^na_i^2\geq n$$ or $$\sum_{i=1}^n\left(a_i^2-1\right)\geq0$$ or $$\sum_{i=1}^n\left(a_i^2-1-2(a_i-1)\right)\geq0$$ or $$\sum_{i=1}^n(a_i-1)^2\geq0.$$ Done!


$\displaystyle P(x)=\sum\limits_{i=1}^n(a_i+x)^2=\sum\limits_{i=1}^n(a_i^2+2xa_i+x^2)=nx^2+2x\sum\limits_{i=1}^na_i+\sum\limits_{i=1}^n a_i^2\ge 0$

$P(x)$ is a quadratic polynomial of constant sign so $\Delta\le 0$.

$\Delta=4\left(\sum\limits_{i=1}^na_i\right)^2-4n\sum\limits_{i=1}^na_i^2\le 0\iff \left(\sum\limits_{i=1}^na_i\right)^2\le n\sum\limits_{i=1}^na_i^2$

Which is the desired inequality after taking the square root, it is known as Cauchy-Schwarz inequality.