I have the function $$f(k)=\dfrac{k}{n}\sum_{i=k+1}^n \frac{1}{i-1}=\dfrac{k}{n}\sum_{i=k}^{n-1} \frac{1}{i}.$$ I want to find the $k$ for which this function attains the maximum value. I thought of differentiating the function but it doesn't seem easy to do so since the limit of summation is the function of $k$. Moreover since it is a discrete harmonic sum , differentiating it wouldn't make sense. How do I proceed to find the $k$ for which the function attains maximum value ?
-
If $n\ge 2$, it is the nearest integer to $\frac{1}{{\rm e}}\left( {n - \frac{1}{2}} \right)$. – Gary Jan 22 '25 at 05:33
-
@Gary If true, then this is worth its own answer (in particular, showing that the error is always less than 1/2) – Akiva Weinberger Jan 22 '25 at 05:50
2 Answers
$$f(k)=\frac{k}{n}\sum_{i=k+1}^n \frac{1}{i-1}=\frac{k}{n}\big(\psi ^{(0)}(n)-\psi ^{(0)}(k)\big)$$ $$f'(k)=-\frac 1 n\big(\psi ^{(0)}(k)+k \psi ^{(1)}(k)-\psi ^{(0)}(n) \big)$$ Expanding the derivative as series for large values of $k$ and letting it equal to $0$, we have $$0=(\log (k)-\psi ^{(0)}(n)+1)+\frac{1}{12 k^2}+O\left(\frac{1}{k^4}\right)$$ So, an estimate in terms of Lambert function $$\large\color{blue}{k_*^2=-\frac 1{6\,W(t)}}\qquad \text{where} \qquad \color{blue}{t=-\frac{1}{6} e^{2-2 \psi ^{(0)}(n)}}$$ A few numbers for illustration $$\left( \begin{array}{ccc} n & \text{estimate} & \text{solution} \\ 5 & 1.6061060 & 1.6111645 \\ 10 & 3.4723834 & 3.4729528 \\ 15 & 5.3196199 & 5.3197825 \\ 20 & 7.1627912 & 7.1628584 \\ 25 & 9.0044123 & 9.0059014 \\ 30 & 10.845276 & 10.845296 \\ 35 & 12.685714 & 12.685726 \\ 40 & 14.525888 & 14.525896 \\ 45 & 16.365887 & 16.365893 \\ 50 & 18.205764 & 18.205768 \\ 55 & 20.045553 & 20.045556 \\ 60 & 21.885276 & 21.885276 \\ \end{array} \right)$$
Expanding for large values of $n$ $$\large\color{blue}{k_*=\frac{n}{e}-\frac{1}{2 e}+\frac{1-2 e^2}{24 e n} +\frac{1-2 e^2}{48 e n^2}+O\left(\frac{1}{n^3}\right)}$$
For this approximation $$f'(k_*)=\frac{23-100 e^2+84 e^4}{5760\,n^5}+O\left(\frac{1}{n^6}\right)$$ $$f(k_*)=\frac{1}{e}+\frac{e-1}{2 e n}+\frac{1+2e^2}{24 en^2} +O\left(\frac{1}{n^3}\right)$$
Edit
As @Gary commented, using $m=n-\frac 12$, the expansion of the first $k*$ gives the expansion $$k_*=\frac m e+\frac 1 e\sum_{p=0}^\infty \frac {a_p}{m^{2p+1}}$$ the very first coefficients being $$\left( \begin{array}{cc} p & a_p \\ 0 & \frac{1-2 e^2}{24} \\ 1 & \frac{-37+20 e^2-60 e^4}{5760} \\ 2 & \frac{10313-1974 e^2+3780 e^4-7000 e^6}{2903040} \\ \end{array} \right)$$
Update
Interesting is to notice that, writing from the start $$k_*=\frac m e+\frac 1 e\sum_{p=1}^\infty \frac {a_p}{m^{p}}$$, the even terms are $0$ and the odd terms are slightly different $$\left( \begin{array}{cc} p & a_p \\ 1 & \frac{1-2 e^2}{24} \\ 3 & \frac{-37+20 e^2+84 e^4}{5760} \\ 5 & \frac{10313-1974 e^2-5292 e^4-34360 e^6}{2903040} \\ \end{array} \right)$$ This has a significant impact $$f'(k_*) = \frac{57.5638}{m^8}+O\left(\frac{1}{m^{10}}\right)$$ $$f(k_*)=\frac{1}{e}+\frac{e-1}{2 e m}+\frac{7-6 e+2 e^2}{24 e m^2}+O\left(\frac{1}{m^{3}}\right)$$ For $n=5$, this gives $k=1.61085$ (reducing the relative error by a factor of $16$).
- 289,558
-
Expanding in $n-\frac{1}{2}$ will probably involve only odd powers: $$ k_ * = \frac{1}{{\rm e}}\left( {n - \frac{1}{2}} \right) + \cfrac{{1 - 2{\rm e}^2 }}{{24{\rm e}\bigg( {n - \cfrac{1}{2}} \bigg)}} + \mathcal{O}!\left( {\frac{1}{{n^3 }}} \right). $$ – Gary Jan 22 '25 at 05:35
-
-
Is best integer solution always the closest integer to the solutions you have found? – Akiva Weinberger Jan 22 '25 at 05:52
-
1@Gary. If you have time to waste, have a look at the update. It is funny to see how small differences impact everything. Cheers :-) – Claude Leibovici Jan 23 '25 at 05:34
NB: This is not a complete answer but some ideas about how we may approach this question.
We may use the Harmonic sum to get started. Denoting, $H_n = \sum_{j=1}^n\frac{1}{j},$ we get $f(k) = \frac{k}{n}\left(H_{n-1}-H_{k-1}\right).$ Then, using the bounds on the Harmonic sum from here, we get $$\frac{k}{n}\left(\ln(n-1)+\frac{1}{n-1}-\ln(k-1)-1\right)<f(k)<\frac{k}{n}\left(\ln(n-1)+1-\ln(k-1)-\frac{1}{k-1}\right).$$ A little thought suggests that the upper and lower bounds should be maximized when $k=[n/e]$ (whether it is ceil or floor needs to be verified). I will now argue informally using the big-Oh $\mathcal{O}(\cdot)$ notation that the optimal $k$ might be $\mathcal{O}(n/e)$.
Note that the absolute gap between the upper and lower bounds is $\frac{k}{n}\left(2-\frac{1}{k-1}-\frac{1}{n-1}\right)=\mathcal{O}\left(\frac{k}{n}\right)$. When $k=\mathcal{O}(n/e)$, the values of the upper and lower bounds are $\mathcal{O}\left(\frac{1}{e}\right)$, and the absolute gap is $\mathcal{O}\left(\frac{1}{e}\right)$. Therefore, at least for large $n$, it seems that deviating too much from $k=\mathcal{O}(1/e)$ may reduce the max values of both bounds significantly. Therefore, it seems that the max is obtained for $k=\mathcal{O}(n/e)$. Of course, the exact constants need to be evaluated separately.
- 16,568
-
I'm getting $k \sim \frac ne$. We get better bounds with $$ \int_k^n \frac 1x, dx \leq \sum_{i=k+1}^n \frac{1}{i-1} \leq \int_{k-1}^{n-1} \frac 1x, dx $$ $$ \frac kn \ln \frac nk \leq f(k) \leq \frac kn \ln \frac{n-1}{k-1} $$ – aschepler Jan 20 '25 at 17:34
-
-
You're not using big-Oh correctly. You just mean "near/approximately". – aschepler Jan 20 '25 at 17:47