Evaluating integral $\int_0^{2\pi}\frac{1}{2-\sin(x)}\,dx$ I come across a problem, which is to evaluate: $$\int_0^{2\pi}\frac{1}{2-\sin(x)}\,dx$$
My attempt so far is:
$$\begin{align}\int_0^{2\pi}\frac{1}{2-\sin(x)}\,dx 
&= \int_0^{2\pi}\frac{1}{2-\frac{2\tan(\frac{x}{2})}{1+\tan^2(\frac{x}{2})}}\,dx\\ 
&= \int_0^{2\pi}\frac{1+\tan^2(\frac{x}{2})}{2+2\tan^2(\frac{x}{2})-2\tan(\frac{x}{2})}\,dx\\
&= \int_0^{2\pi}\frac{\frac{1}{2} \sec^2(\frac{x}{2})}{1+\tan^2(\frac{x}{2})-\tan(\frac{x}{2})}\,dx\end{align}$$
I'm wondering whether I'm in the right direction and how can I proceed?
 A: Note that because of periodicity, $\displaystyle \int_0^{2\pi} = \int_{-\pi}^{+\pi}.$
If you let $u = \tan\tfrac x2$ so that $\sin x= \dfrac{2u}{1+u^2}$ and $du = \dfrac{2\,du}{1+u^2},$ then as $x$ goes from $-\pi$ to $+\pi,$ $u$ goes from $-\infty$ to $+\infty.$
\begin{align}
& \int_{-\pi}^{+\pi} \frac 1 {1+\tan^2(\frac{x}{2})-\tan(\frac{x}{2})} \big(\tfrac 1 2\sec^2\tfrac x 2 \,dx\big) \\[8pt]
= {} & \int_{-\infty}^{+\infty} \frac 1 {1+u^2 - u} \, du \\[12pt]
= {} & \int_{-\infty}^{+\infty} \frac 1 {(u-\frac 1 2 )^2 + \frac 3 4} \, du \quad \left( \begin{array}{c} \text{This is complet-} \\ \text{ing the square.} \end{array} \right)\\[10pt]
= {} & \frac 4 3 \int_{-\infty}^{+\infty} \frac 1 {\left( \frac{2u-1}{\sqrt3} \right)^2 + 1} \, du \quad \left( \begin{array}{c} \text{Here we multiplied the} \\ \text{top and bottom by }4/3. \end{array} \right) \\[10pt]
= {} & \frac 2 {\sqrt3}\int_{-\infty}^{+\infty} \frac 1 {\left( \frac{2u-1}{\sqrt3} \right)^2+1} \left( \tfrac 2 {\sqrt3} \, du \right) \\[10pt]
= {} & \frac 2 {\sqrt3} \int_{-\infty}^{+\infty} \frac 1 {w^2+1} \, dw = \frac{2\pi}{\sqrt3}.
\end{align}
A: This is the step-by-step process I mentioned in the link to deal with the discontinuity at $x=\pi$.
Using Weierstrass substitution $t = \tan\left(\frac{x}{2}\right)$, where $-\pi < x < \pi$ or $\pi < x < 3\pi$, then $\sin(x) = \frac{2t}{1+t^2}$, $dx = \frac{2}{1+t^2}dt$, there is a discontinuity at $x=\pi$ that needs to be taken into account, first you find the indefinite integral and then evaluate the limits of the endpoints of the improper integrals. First split the integral:
$$\int\limits_0^{2\pi}\frac{1}{2-\sin(x)}\:dx = \int\limits_0^{\pi}\frac{1}{2-\sin(x)}\:dx +\int\limits_\pi^{2\pi}\frac{1}{2-\sin(x)}\:dx.$$
Then evaluate the indefinite integral. Since $\frac{1}{2-\frac{2t}{1+t^2}}= \frac{1+t^2}{2(t^2-t+1)}$, $\frac{1}{2-\sin(x)}\:dx = \frac{1}{t^2-t+1}\:dt$, hence
$$\int\frac{1}{2-\sin(x)}\:dx = \int\frac{1}{t^2-t+1}\:dt,$$
substituting $t = s + \frac{1}{2}$ to get rid of the $-t$, then $dt=ds$, and $$\int\frac{1}{t^2-t+1}\:dt  = \int\frac{1}{s^2 +\frac{3}{4}}\:ds = \frac{2}{\sqrt3}\int\frac{1}{\left(\frac{2s}{\sqrt3}\right)^2+1}\:\frac{2}{\sqrt3}ds =\\ \frac{2}{\sqrt3}\int\frac{1}{u^2+1}\:du = \frac{2}{\sqrt3}\arctan(u) $$
with $u =\frac{2s}{\sqrt3}$ and the answer of the indefinite integral is := $\frac{2}{\sqrt3}\arctan\left(\frac{2\tan\left(\frac{x}{2}\right)-1}{\sqrt3}\right)$
$$\int\limits_0^{\pi}\frac{1}{2-\sin(x)}\:dx +\int\limits_\pi^{2\pi}\frac{1}{2-\sin(x)}\:dx = \\\lim_{b\rightarrow\pi^{-}}\frac{2}{\sqrt3}\arctan\left(\frac{2\tan\left(\frac{x}{2}\right)-1}{\sqrt3}\right)\Biggr|_0^b + \lim_{b\rightarrow\pi^{+}}\frac{2}{\sqrt3}\arctan\left(\frac{2\tan\left(\frac{x}{2}\right)-1}{\sqrt3}\right)\Biggr|_b^{2\pi} = \\ \lim_{b\rightarrow\pi^{-}}\frac{2}{\sqrt3}\arctan\left(\frac{2\tan\left(\frac{b}{2}\right)-1}{\sqrt3}\right) - \lim_{b\rightarrow\pi^{+}}\frac{2}{\sqrt3}\arctan\left(\frac{2\tan\left(\frac{b}{2}\right)-1}{\sqrt3}\right) - \frac{2}{\sqrt3}\arctan\left(\frac{-1}{\sqrt3}\right) + \frac{2}{\sqrt3}\arctan\left(\frac{-1}{\sqrt3}\right) = \frac{2}{\sqrt3}\cdot\frac{\pi}{2} - \left(-\frac{2}{\sqrt3}\cdot\frac{\pi}{2}\right) + 0 = \frac{2\pi}{\sqrt3}$$
since you can't evaluate at $\pi$.
