How to integrate $\frac{1}{3+\sin x+\cos x}$ I can easily do it with $\tan {\frac{x}{2}}$ substitution, but my problem requires $x\in(0,2\pi)$.
$\int \frac{1}{3+\sin x+\cos x}dx, x\in(0,2\pi)$
How do i solve it now ?
 A: First make the substitution $x=\pi + y$ with $y\in (-\pi, +\pi)$. The integral becomes
\begin{equation}
\int \frac{d y}{3 - \sin(y)-\cos(y)} = \frac{2}{\sqrt{7}}\arctan\left(
\frac{4\tan\left(\frac{y}{2}\right) - 1}{\sqrt{7}}\right) + C
\end{equation}
after integration with the $\tan(y/2)$ substitution. Now replace $y$ with $x-\pi$ and the solution is defined in $(0, 2\pi)$.
A: Take $\sin x=2t/(1+t^2), \cos x=(1-t^2)/(1+t^2), tan(x/2)=t \implies 2 \sec^2(x/2) dx=dt$. Then
$$I=\int \frac{dx}{3+\sin x+ \cos x}=\frac{1}{4}\int \frac{dt}{t^2+t+2}=\frac{1}{4}\int \frac{dt}{(t+1/2)^2+7/4}==\frac{1}{2\sqrt{7}} \tan^{-1} \frac{2t+1}{\sqrt{7}}+C.$$
where $t=\tan(x/2)$.
A: Making the substitution $t=\tan(x/2)$ gives \begin{align}I(x)&=\frac{1}{2}\int\frac{1+t^2}{2+t+t^2}\frac{2}{1+t^2}\,dt=\int\frac{1}{2+t+t^2}\,dt=\frac{4}{7}\int\frac{1}{1+(\frac{2t+1}{\sqrt7})^2}\,dt\\&=\frac{2}{\sqrt7}\arctan(\frac{2t+1}{\sqrt7})=\frac{2}{\sqrt7}\arctan(\frac{2\tan(x/2)+1}{\sqrt7})\end{align}
The problem with this is that this substitution is only valid for $0\le x<\pi$. In fact, at $x=\pi^+$, the above formula become negative, but there's nothing amiss in the original integrand at $x=\pi$.
For $x>\pi$, one needs to add a constant to keep the integral continuous, namely $$I(x)=\frac{2}{\sqrt7}\arctan(\frac{2\tan(x/2)+1}{\sqrt7})+\frac{2\pi}{\sqrt7}$$
