TITLE: Analytic integral of diverging function
QUESTION [7 upvotes]: Is it possible to obtain the result of the following integral analytically?
$$\int_0^x \cfrac{{\rm d}u}{1-u^n}$$
I've tried using quadrature, but the function goes to infinity at $u=1$, hence the integral.
EDIT
I suppose an analytic solution is not possible, so is there any way to calculate it numerically for $u>1$? I managed to write:
from math import *
from scipy.integrate import quad
f = lambda u,n: 1./(1.-(u**n))
eps = 0.0001; n=2.6;
# from 0 to 1.005
print quad(lambda x:f(x,n),0.0,1.-eps)[0]+ quad(lambda x:f(x,n) ,1.+eps,1.005)[0]

I implemented the Cauchy principle value method in python 2.7 using scipy. Is there are particular reason for it not to work. For (u=1.005, n=2.6, x=u) the result should have been 2.022 (according to this (Open-Channel Flow by Subhash C. Jain, p78)). Instead, it is 2.48. Am I missing something? Can we say that $$\int_0^{x+\epsilon}\frac{\mathrm{d}u}{1-u^n} = \int_0^{x-\epsilon}\frac{\mathrm{d}u}{1-u^n}$$
Here are the numerical solutions that are supposedly correct:

Solution:
Here is a snippet in python2.7 using the hyp2f1() function from the mpmath package
def F(u,n):
    if u < 1:
        return u*mpmath.hyp2f1(1/n,1,1/n+1,u**n)
    elif u >1:
        return (u**(1-n))/(n-1)* \
            mpmath.hyp2f1(1-1/n, 1 , 2-1/n ,u**(-1*n)) #+ pi/n/tan(pi/n)
    else:
        return 0.

REPLY [4 votes]: The integral can be given a value for $x\gt1$ using the Cauchy Principal Value. That is, for $x\gt1$,
$$
\mathrm{PV}\int_0^x\frac{\mathrm{d}u}{1-u^n}
=\lim_{\epsilon\to0}\left(\int_0^{1-\epsilon}\frac{\mathrm{d}u}{1-u^n}
+\int_{1+\epsilon}^x\frac{\mathrm{d}u}{1-u^n}\right)
$$

Cauchy Principal Value over $\mathbf{\mathbb{R}^+}$
Consider the contour
$\hspace{3cm}$
Using this answer, we get
$$
\int_0^\infty\frac{\mathrm{d}u}{1+u^n}=\frac\pi n\csc\left(\frac\pi n\right)
$$
Thus, the integral on the blue line is
$$
-e^{i\pi/n}\frac\pi n\csc\left(\frac\pi n\right)=-\frac\pi n\cot\left(\frac\pi n\right)-i\frac\pi n
$$
The residue of $\frac1{1-u^n}$ at $u=1$ is $-\frac1n$. Therefore, the integral along the clockwise red semicircle is
$$
i\frac\pi n
$$
Since there are no singularities inside the contour, the total integral over the contour is $0$. Thus, the integral over the perforated green line must be
$$
\mathrm{PV}\int_0^\infty\frac{\mathrm{d}u}{1-u^n}=\frac\pi n\cot\left(\frac\pi n\right)
$$

Self-Contained Argument
Using the contour above and separating real and imaginary parts, we get that
$$
\begin{align}
\color{#00A000}{\mathrm{PV}\int_0^\infty\frac{\mathrm{d}u}{1-u^n}}+\color{#C00000}{i\frac\pi n}
&=\color{#0000FF}{e^{i\pi/n}\int_0^\infty\frac{\mathrm{d}u}{1+u^n}}\\
&=\left(\cos\left(\frac\pi n\right)+i\sin\left(\frac\pi n\right)\right)\int_0^\infty\frac{\mathrm{d}u}{1+u^n}
\end{align}
$$
Looking at the imaginary part, we get
$$
\int_0^\infty\frac{\mathrm{d}u}{1+u^n}=\frac\pi n\csc\left(\frac\pi n\right)
$$
Then looking at the real part, we get
$$
\mathrm{PV}\int_0^\infty\frac{\mathrm{d}u}{1-u^n}=\frac\pi n\cot\left(\frac\pi n\right)
$$