Example 9 Let $n$ and $k$ be given positive integers $(k<n)$, and let $a_{1}, a_{2}, \cdots, a_{k}$ be given positive real numbers. Try to find positive real numbers $a_{k+1}, a_{k+2}, \cdots, a_{n}$ such that the sum

takes the minimum value.
$$M=\sum_{i \neq j} \frac{a_{i}}{a_{j}}$$
By calculating for $n=1,2,3$, we get
$$M=\left(a_{1}+a_{2}+\cdots+a_{n}\right)\left(\frac{1}{a_{1}}+\frac{1}{a_{2}}+\cdots+\frac{1}{a_{n}}\right)-n .$$

Let $a=a_{1}+a_{2}+\cdots+a_{k}, b=\frac{1}{a_{1}}+\frac{1}{a_{2}}+\cdots+\frac{1}{a_{k}}$, then by the assumption $a, b$ are given constants. Therefore, by the Cauchy-Schwarz inequality, we get
$$\begin{aligned}
M & =\left(a+a_{k+1}+\cdots+a_{n}\right)\left(b+\frac{1}{a_{k+1}}+\cdots+\frac{1}{a_{n}}\right)-n \\
& \geqslant(\sqrt{a b}+1+\cdots+1)^{2}-n \\
& =(\sqrt{a b}+n-k)^{2}-n
\end{aligned}$$

and when
$$\frac{\sqrt{a_{k+1}}}{\frac{1}{\sqrt{a_{k+1}}}}=\cdots=\frac{\sqrt{a_{n}}}{\frac{1}{\sqrt{a_{n}}}}=\frac{\sqrt{a}}{\sqrt{b}}$$

i.e., $a_{k+1}=\cdots=a_{n}=\sqrt{\frac{a}{b}}$, $M$ takes its minimum value.