Sum of $\cos\left(\frac{\pi n}N\right)\cot\left(\frac{\pi n}N\right)$ Consider the following sum for large $N$
$$
f\left(N\right)=\frac1{2N}\sum_{n=1}^{N-1}\cos\left(\frac{\pi n}N\right)\cot\left(\frac{\pi n}N\right)
$$
Since it is like a Riemann sum, I converted to into an integral
$$
\frac12\int_0^\pi\cos\left(x\right)\cot\left(x\right)\,\mathrm dx=\infty
$$
But $\frac12\int_\epsilon^{\pi-\epsilon}\cos\left(x\right)\cot\left(x\right)\,\mathrm dx=-\log\left(\tan\left(\frac\epsilon2\right)\right)-\cos\left(\epsilon\right)=\log\left(\frac1\epsilon\right)+\log\left(2\right)-1+a\left(\epsilon\right)$ with $\lim_{\epsilon\to0}a\left(\epsilon\right)=0$. Since $\epsilon\sim\frac\pi N$ I guessed that $f\left(N\right)$ also diverges logarithmically. 
I need to extract the large $N$ behaviour of $f\left(N\right)$, that is find a $g\left(N\right)$ such that $\lim_{N\to\infty}f\left(N\right)-g\left(N\right)=0$. My guess is that $g\left(N\right)=C\log\left(N\right)+ \text{others}$. An exact expression for $g$ with the non-logarithmic pieces would be great (that is, with all the relevant constant and subleading corrections). But any help would be greatly appreciated.
 A: Let's use the integral approximation more carefully, by identifying the $N-1$ terms in $f(N)$ with the areas of $N-1$ rectangular approximations to strips of a finite integral, viz.$$f(N)\approx I_N:=\frac{1}{2\pi}\int_{\pi/(2N)}^{\pi-\pi/(2N)}\cos x\cot x dx.$$In particular, each area approximation uses the height at the strip's midpoint. Since$$\int\cos x\cot xdx=\int(\csc x-\sin x)dx=-\ln|\csc x+\cot x|+\cos x+C,$$we have$$\begin{align}I_N&=\frac{1}{2\pi}\left[-\ln|\csc x+\cot x|+\cos x\right]_{\pi/(2N)}^{\pi-\pi/(2N)}\\&=\frac{1}{\pi}\left(\ln\left(\csc\frac{\pi}{2N}+\cot\frac{\pi}{2N}\right)-\cos\frac{\pi}{2N}\right)\\&\approx\frac{1}{\pi}\left(\ln\frac{4N}{\pi}-1\right).\end{align}$$Since a quadratic approximation of a sufficiently nice function $f$ gives$$\int_a^bf(x)dx-(b-a)f\left(\frac{a+b}{2}\right)\approx\frac{(b-a)^3}{12}f^{\prime\prime}\left(\frac{a+b}{2}\right),$$and since the second derivative of $\csc x-\sin x$ is $\sin x-\csc x+2\csc^3x$,$$I_N-f(N)\approx\sum_{n=1}^{N-1}\frac{\pi^3}{12N^3}\left(\sin\frac{n\pi}{N}-\csc\frac{n\pi}{N}+2\csc^3\frac{n\pi}{N}\right).$$We can easily verify $\pm O(N^{-2}\ln N)$ bounds on everything apart from the cubed-cosecant contributions, which are more problematic; the $n=1$ term alone adds approximately $\frac16$, as does the $n=N-1$ term. The same technique as before gives$$\begin{align}\sum_n\frac{\pi^3}{6N^3}\csc^3\frac{n\pi}{N}&\approx\frac{\pi^2}{6N^2}\int_{\pi/(2N)}^{\pi-\pi/(2N)}\csc^3 xdx\\&=\frac{\pi^2}{48N^2}\left[\sec^2\frac{x}{2}-\csc^2\frac{x}{2}+4\ln\tan\frac{x}{2}\right]_{\pi/(2N)}^{\pi-\pi/(2N)}\\&=\frac{\pi^2}{24N^2}\left(\csc^{2}\frac{\pi}{4N}-\sec^{2}\frac{\pi}{4N}-4\ln\tan\frac{\pi}{4N}\right).\end{align}$$Asymptotically, this is $\frac23$. But since it's $O(1)$, getting the exact $O(1)$ error no doubt requires a finer approximation than the quadratic one attempted here.
A: Using $\cot a=\cos a/\sin a$, the given summation can be written under the form :
$$\frac1{2N}\sum_{n=1}^{N-1}\dfrac{1}{\sin\left(\frac{\pi n}{N}\right)}-\frac1{2N}\sum_{n=1}^{N-1}\sin\left(\frac{\pi n}N\right)$$
The second term converges (Riemann sum) to a constant ($\tfrac{1}{2 \pi}$). 
The first is equivalent, when $\varepsilon \to 0$ to:
$$\int_{\varepsilon}^{\pi-\varepsilon} \dfrac{1}{\sin(x)}dx=2\int_{\varepsilon}^{\pi/2} \dfrac{1}{\sin(x)}dx=2\left[\ln(\tan\tfrac{x}{2})\right]_{\varepsilon}^{\pi/2}$$
(using the fact that $\sin(\pi-x)=\sin(x)$) yielding an equivalent in terms of $\ln$ that I leave you to find.
