Integral with Weierstrass substituion, limits gone wrong I'm trying to evaluate the following integral with a Weierstrass substitution:
$$
\int_{\pi/3}^{4\pi/3} \frac{3}{13 + 6\sin x - 5\cos x} \text{d}x
$$
This comes out to about 0.55 when evaluated numerically. I thought it would be possible to rewrite the integral using the substitution $t = \tan\frac{x}{2}$ like so:
$$
\text{Upper limit: }\frac{4\pi}{3} \to \tan\frac{4\pi}{6} \to -\sqrt{3}
$$
$$
\text{Lower limit: }\frac{\pi}{3} \to \tan\frac{\pi}{6} \to \sqrt{3}/3
$$
$$
\int_{\sqrt{3}/3}^{-\sqrt{3}} \frac{3(1+t^2)}{2(3t+1)^2 + 6} \cdot \frac{2}{1 + t^2} \text{d}x
$$
However, evaluating this numerically now gives -1.26, so it's clear that this method is wrong. I am sure that
$$
\frac{3}{13 + 6\sin x - 5\cos x} = \frac{3(1+t^2)}{2(3t+1)^2 + 6}
$$
So something must have gone wrong changing the limits, but I've never come across this problem before. I thought the integral may be improper but plotting $\frac{3}{13 + 6\sin x - 5\cos x}$ on a graph shows it has no asymptotes or any other obvious problems in the range of integration.
Any help would be greatly appreciated :)
 A: Take care of the discontinuity at $x=\pi$ with the half angle substitution $t=\tan\frac x2$
\begin{align}
&\int_{\pi/3}^{4\pi/3} \frac{3}{13 + 6\sin x - 5\cos x} dx
\overset{t=\tan\frac x2}=\bigg(\int_{\frac1{\sqrt3}}^\infty +\int_{-\infty}^{-\sqrt3}\bigg)
\frac3{4+6t+9t^2}dt
\end{align}
A: The Weierstrass substitution is valid for $x\in(-\pi,\pi)$ or $x\in(\pi,3\pi)$, but not for an interval containing a neighborhood of $\pi$. As $x$ tends to $\pi$ from below, $z$ tends to $+\infty$. As $x$ tends to $\pi$ from above, $z$ tends to $-\infty$.
$$
\begin{align}
&\int^{4\pi/3}_{\pi/3}\frac3{13+6\sin(x)-5\cos(x)}\,\mathrm{d}x\\
&=\int^{\pi}_{\pi/3}\frac3{13+6\sin(x)-5\cos(x)}\,\mathrm{d}x
+\int^{4\pi/3}_{\pi}\frac3{13+6\sin(x)-5\cos(x)}\,\mathrm{d}x\tag{1a}\\
&=\int_{1/\sqrt3}^\infty\frac3{13+6\frac{2z}{1+z^2}-5\frac{1-z^2}{1+z^2}}\frac{2\,\mathrm{d}z}{1+z^2}
+\int_{-\infty}^{-\sqrt3}\frac3{13+6\frac{2z}{1+z^2}-5\frac{1-z^2}{1+z^2}}\frac{2\,\mathrm{d}z}{1+z^2}\tag{1b}\\
&=\int_{1/\sqrt3}^\infty\frac{3\,\mathrm{d}z}{4+6z+9z^2}
+\int_{-\infty}^{-\sqrt3}\frac{3\,\mathrm{d}z}{4+6z+9z^2}\tag{1c}\\
&=\int_{\tan^{-1}\left(\frac{3+\sqrt3}3\right)}^{\pi/2}\frac{\mathrm{d}u}{\sqrt3}
+\int_{-\pi/2}^{\tan^{-1}\left(\frac{-9+\sqrt3}3\right)}\frac{\mathrm{d}u}{\sqrt3}\tag{1d}\\[3pt]
&=\frac1{\sqrt3}\tan^{-1}\left(\frac{60-24\sqrt3}{13}\right)\tag{1e}
\end{align}
$$
Explanation:
$\text{(1a)}$: break the integral into ranges where $z$ is increasing
$\text{(1b)}$: $z=\tan(x/2)$, $\sin(x)=\frac{2z}{1+z^2}$, $\cos(x)=\frac{1-z^2}{1+z^2}$, $\mathrm{d}x=\frac{2\,\mathrm{d}z}{1+z^2}$
$\text{(1c)}$: simplify
$\text{(1d)}$: if $\sqrt3z+1/\sqrt3=\tan(u)$, then $4+6z+9z^2=3\sec^2(u)$ and $\mathrm{d}z=\frac1{\sqrt3}\sec^2(u)\,\mathrm{d}u$
$\text{(1e)}$: $\tan^{-1}\left(\frac{3+\sqrt3}3\right)\gt\frac\pi4$ and $\tan^{-1}\left(\frac{9-\sqrt3}3\right)\gt\frac\pi4$, and
$\phantom{\text{(1e): }}$$\tan\left(\pi-\tan^{-1}\left(\frac{3+\sqrt3}3\right)-\tan^{-1}\left(\frac{9-\sqrt3}3\right)\right)=\frac{60-24\sqrt3}{13}$
