Prove the following summation inequality: $\sum_{i=1}^n(a_i)\sum_{i=1}^n(\frac{1}{a_i})\ge n^2$ [duplicate]

$\sum_{i=1}^n(a_i)\sum_{i=1}^n(\frac{1}{a_i})\ge n^2$ is what I want to prove, where $a_i>0$ and I need to showwhen equality holds. I have tried using Cauchy-Schwarz, where inside the sums I multiply each value by 1 to do it but it doesn't work out. I have also done

$\sum_{i=1}^n(a_i)\sum_{i=1}^n(\frac{1}{a_i})=\sum_{i=1}^n \sum_{i=1}^n(\frac{a_i}{a_i})=\sum_{i=1}^n\sum_{i=1}^n(1)=\sum_{i=1}^n(n)=n^2$, but this proves an equality.

Am I not allowed to do the first step I did in my work?


By the Cauchy-Schwarz inequality,

$$\sum_{i = 1}^n a_i \sum_{i = 1}^n \frac{1}{a_i} \ge \left(\sum_{i = 1}^n \sqrt{a_i}\cdot \sqrt{\frac{1}{a_i}}\right)^2 =\left(\sum_{i = 1}^n 1\right)^2 = n^2.$$


For the first step $$ \sum_{i=1}^n(a_i)\sum_{i=1}^n(\frac{1}{a_i})=\sum_{i=1}^n \sum_{j=1}^n(\frac{a_i}{a_j}) $$ The first factor has $n$ terms, the second factor has $n$ terms, and when you multiply them there are $n^2$ terms.

Can you see how to finish now?


Expanding GEdgar's answer,

$\begin{array}\\ \sum_{i=1}^na_i\sum_{i=1}^n\frac{1}{a_i} &=\sum_{i=1}^n \sum_{j=1}^n\frac{a_i}{a_j}\\ &=\sum_{i=1}^n \left(\sum_{j=1}^{i-1}\frac{a_i}{a_j} +\frac{a_i}{a_i} +\sum_{j=i+1}^{n}\frac{a_i}{a_j}\right)\\ &=\sum_{i=1}^n \sum_{j=1}^{i-1}\frac{a_i}{a_j} +n +\sum_{i=1}^n\sum_{j=i+1}^{n}\frac{a_i}{a_j}\\ &=\sum_{i=1}^n \sum_{j=1}^{i-1}\frac{a_i}{a_j} +n +\sum_{j=1}^n\sum_{i=1}^{j-1}\frac{a_i}{a_j}\\ &=\sum_{i=1}^n \sum_{j=1}^{i-1}\frac{a_i}{a_j} +n +\sum_{i=1}^n\sum_{j=1}^{i-1}\frac{a_j}{a_i} \quad\text{ (swapping i and j in the last sum)}\\ &=\sum_{i=1}^n \sum_{j=1}^{i-1}\left(\frac{a_i}{a_j}+\frac{a_j}{a_i}\right) +n\\ &=\sum_{i=1}^n \sum_{j=1}^{i-1}\left(\frac{a_i^2+a_j^2}{a_i a_j}\right) +n\\ &=\sum_{i=1}^n \sum_{j=1}^{i-1}\left(\frac{(a_i-a_j)^2+2a_i a_j}{a_i a_j}\right) +n\\ &=\sum_{i=1}^n \sum_{j=1}^{i-1}\left(\frac{(a_i-a_j)^2}{a_i a_j}+2\right) +n\\ &=\sum_{i=1}^n \sum_{j=1}^{i-1}\frac{(a_i-a_j)^2}{a_i a_j} +\sum_{i=1}^n \sum_{j=1}^{i-1}2 +n\\ &=\sum_{i=1}^n \sum_{j=1}^{i-1}\frac{(a_i-a_j)^2}{a_i a_j}+\sum_{i=1}^n 2(i-1)+n\\ &=\sum_{i=1}^n \sum_{j=1}^{i-1}\frac{(a_i-a_j)^2}{a_i a_j}+2\frac{n(n-1)}{2}+n\\ &=n^2+\sum_{i=1}^n \sum_{j=1}^{i-1}\frac{(a_i-a_j)^2}{a_i a_j}\\ &\ge n^2\\ \end{array} $

with equality if and only if all the $a_i$ are equal.