I'm trying to compute numerically the non-elementary function below : $$ \frac{1}{x} \int_0^x \frac{t}{e^t-1}\mathrm{d}t $$
I tried to evaluate the integral with the quad algorithm, but at values of x < 1, the result is inaccurate compared with the tabled values, maybe because of the indetermination of the integrand at $t=0$.
I also tried to compute the integral with the Simpsons method in which I manually replace the first term of the integrand vector by the value of the limit : $$ \lim_{t\to 0} \frac{t}{e^t-1} = \lim_{t \to 0} \frac{1}{e^t}=1 $$ It takes however a large number of intervals to attain a precision as low as 3 digits, and it has poor performance.
Any ideas to compute this function more efficiently? Or maybe this function is already computed in a Scipy algorithm?
Thanks for your help
A clever way is to break the integral into two pieces, and massage the function in the piece having $t<1$ to avoid numerical error accumulation: $$ \int_0^x\frac{t}{e^t-1}= \int_0^1\frac{t}{e^t-1}+ \int_1^x\frac{t}{e^t-1} $$ You are having no trouble with the second piece. For the first piece, the trick is to Taylor expand about $t=0$: $$ \frac{t}{e^t-1}= 1-\frac12 t+\frac1{12}t^2-\frac1{6!}t^4+\frac1{6\cdot 7!}t^6-\frac1{60\cdot 8!}t^8+\frac1{132\cdot9!}t^{10}+ \cdots $$ Integrating this from zero to one is very easy.