# Evaluate $\int \frac{1}{1+3\sin^2 x} dx$ (Making antiderivative continuous.)

Evaluate $$\int \frac{1}{1+3\sin^2 x} dx$$

I know that this has an antiderivative on $$\mathbb{R}$$

I can use the trig. substitution $$t = \tan x$$ on $$(-\frac{\pi}{2}+k\pi, \frac{\pi}{2}+k\pi)$$

$$x = \arctan t$$

$$dx = \frac {1}{1+t^2} dt$$

To get $$\int \frac{1}{1+3\sin^2 x} dx$$ = $$\int \frac{1}{1+3\frac{t^2}{t^2+1} }\cdot \frac{1}{1+t^2} dt$$ = $$\int \frac{1}{1+(2t)^2} dt =\frac 1 2 \int{\frac {1}{1+u^2} du} = \frac 1 2 \arctan (2\tan x) + C$$

But this only appplies on the interval $$(-\frac{\pi}{2}+k\pi, \frac{\pi}{2}+k\pi)$$, whereas the original function should have an antiderivative on $$\mathbb {R}$$. So I have to make it continuous, but I don't know how.

(I do know that we did a similar thing for $$\int |x| \ dx$$, but I lost my notes and don't know how doing this is called in english so I can't google it. We called it "gluing" antiderivatives. And I remember that we utilized limits in some fashion related to the integration constants)

In each interval $$(-\frac{\pi}{2}+k\pi,\frac{\pi}{2}+k\pi)$$ the solution will be $$F(x) = \frac12\arctan(2\tan x) + C_k$$. To make it continuous for $$x\in\mathbb R$$ you need that for every $$k\in\mathbb Z$$ $$\lim_{x\rightarrow (k\pi+\frac{\pi}{2})^-} F(x) = \lim_{x\rightarrow (k\pi+\frac{\pi}{2})^+} F(x)$$ that is

$$\lim_{x\rightarrow (k\pi+\frac{\pi}{2})^-} \frac12\arctan(2\tan x) + C_k = \lim_{x\rightarrow (k\pi+\frac{\pi}{2})^+} \frac12\arctan(2\tan x) + C_{k+1}$$

$$\lim_{x\rightarrow (\frac{\pi}{2})^-} \frac12\arctan(2\tan x) + C_k = \lim_{x\rightarrow (-\frac{\pi}{2})^+} \frac12\arctan(2\tan x) + C_{k+1}$$

$$\lim_{t\rightarrow +\infty} \frac12\arctan(2t) + C_k = \lim_{t\rightarrow -\infty} \frac12\arctan(2t) + C_{k+1}$$

$$\frac{\pi}{4} + C_k = -\frac{\pi}{4} + C_{k+1}$$ $$C_{k+1} = C_k + \frac{\pi}{2}$$ $$C_k = C_0 +\frac{k\pi}{2}$$ You have then $$F(x) = \frac12\arctan(2\tan x) + \frac{k\pi}{2} + C_0 \qquad \text{for } x\in (-\frac{\pi}{2}+k\pi,\frac{\pi}{2}+k\pi)$$ or equivalently $$F(x) = \frac12\arctan(2\tan x) + \lfloor \frac{x}{\pi}+\frac12\rfloor \frac{\pi}{2} + C_0$$

Actually, the answer should have been $$\frac12\arctan(2\tan x)$$.

Now, define $$F\colon[0,\infty)\longrightarrow\mathbb R$$ as$$x\mapsto\begin{cases}\frac12\arctan(2\tan x)&\text{ if }x\in\left[0,\frac\pi2\right)\\\frac\pi4&\text{ if }x=\frac\pi2\\\frac12\arctan(2\tan x)+\frac\pi2&\text{ if }x\in\left(\frac\pi2,\frac{3\pi}2\right)\\\frac{3\pi}4&\text{ if }x=\frac{3\pi}2\\\frac12\arctan(2\tan x)+\pi&\text{ if }x\in\left(\frac{3\pi}2,\frac{5\pi}2\right)\\\vdots\end{cases}$$Finally, extend $$F$$ to $$\mathbb R$$ by doing $$F(x)=-F(-x)$$ is $$x<0$$. And now $$F$$ is the primitive of $$x\mapsto\frac1{1+3\sin^2x}$$ such that $$F(0)=0$$.