Evaluating $\int\frac{\sec^2(x)}{(4+\tan^2(x))^2}\, dx$ How to solve this integral?$$\int\frac{\sec^2(x)}{(4+\tan^2(x))^2}\, dx$$
I've tried the following:
Starting by substituting $\tan(x) = 2\tan(\theta)\implies \sec^2(x)\ dx= 2\sec^2(\theta)\ d\theta$
$$\implies\int\frac{2\sec^2(\theta)}{(4 + 4\tan^2\theta)^2}\ d\theta\\\implies\int\frac{2\sec^2(\theta)}{16 (\sec^2\theta)^2}\ d\theta\\\implies\int\frac{\cos^2(\theta)}{8} \ d\theta\\\implies\frac\theta{16} + \frac{\sin(2\theta)}{32}+ c$$
Now since, $\tan(x) = 2 \tan\theta\implies \arctan\left(\frac{\tan(x)}{2}\right) = \theta$
So, the final answer to the integral may be,
$$\implies\frac{\arctan\left(\frac{\tan(x)}{2}\right)}{16} + \frac{\sin(2\arctan\left(\frac{\tan(x)}{2}\right))}{32}+ c$$
I checked the answer on wolfram Alpha and found that my answer is not matching with that.
Can anyone tell me what should I do to verify my answer?
 A: If you want to check your answer, just differentiate and see if you get back the function you started from.
But there's a much simpler method. I'd simply observe that with the substitution $\tan x=2u$, the integral becomes
$$
\frac{1}{8}\int\frac{1}{(1+u^2)^2}\,du
$$
which is standard. Leaving aside the factor $1/8$, we can write
$$
\int\frac{1+u^2-u^2}{(1+u^2)^2}\,du=\int\frac{1}{1+u^2}\,du+\frac{1}{2}\int u\frac{-2u}{(1+u)^2}\,du=\arctan u+\frac{1}{2}\frac{u}{1+u^2}-\frac{1}{2}\int\frac{1}{1+u^2}\,du
$$
and therefore
$$
\frac{1}{2}\arctan u+\frac{1}{2}\frac{u}{1+u^2}+c
$$
Now reinsert the factor $1/8$ and do back substitution to get
$$
\frac{1}{16}\Bigl(\arctan\Bigl(\frac{\tan x}{2}\Bigr)+\frac{2\tan x}{4+\tan^2x}\Bigr)+c
$$
A: You can use the noble method known as Ostrogradski method:
Assume you are at the step evaluating $\int\frac{1}{(1+u^2)^2}du$. According to this method, it
$$\int\frac{1}{(1+u^2)^2}du=\dfrac{au+b}{1+u^2}+\int\frac{cu+d}{1+u^2}du$$
Now apply the method to find the constants $a,b,c$ and $d$.
A: Wolfram|Alpha returns an antiderivative of
$$\int \frac{\sec^2(x)}{\left(4+\tan^2(x)\right)^2} \, dx = \frac{2\sin(2x) - (3\cos(2x)+5) \arctan\left(2\cot(x)\right)}{48\cos(2x) + 80} + C$$
which we can rewrite as
$$-\frac1{16} \arctan\left(2\cot(x)\right) + \frac18 \cdot \frac{\sin(2x)}{3\cos(2x) + 5} + C$$

The antiderivative you found was
$$\int\frac{\sec^2(x)}{\left(4+\tan^2(x)\right)^2} \, dx = \frac1{16} \arctan\left(\frac12 \tan(x)\right) + \frac1{32} \sin\left(2\arctan\left(\frac12\tan(x)\right)\right) + C$$

We have
$$\arctan(x) + \arctan\left(\frac1x\right) = \begin{cases}\frac\pi2 & \text{if }x>0 \\ -\frac\pi2 & \text{if }x<0\end{cases}$$
If we take $2\cot(x)>0$, then
$$\begin{align}
-\frac1{16} \arctan(2\cot(x)) + C &= -\frac1{16} \arctan(2\cot(x)) - \frac\pi2 + C \\
&= \frac1{16} \arctan\left(\frac1{2\cot(x)}\right) + C \\
&= \frac1{16} \arctan\left(\frac12\tan(x)\right) + C
\end{align}$$
so that the first terms "match" (not identical, but they only differ by a constant). A similar conclusion is made by instead assuming $2\cot(x)<0$.
Since $\sin(2x) = 2\cos(x)\sin(x)$, the second term in your solution is
$$\frac1{16} \sin\left(\arctan\left(\frac12\tan(x)\right)\right) \cos\left(\arctan\left(\frac12\tan(x)\right)\right) = \frac18 \cdot \frac{\tan(x)}{4 + \tan^2(x)}$$
(Consider a right triangle with reference angle $\theta$ for which $\tan(\theta)=\frac12\tan(x)$, so the ratio of the legs opposite and adjacent to $\theta$ is $\tan(x)$ to $2$. It follows that this triangle's hypotenuse has length $\sqrt{4+\tan^2(x)}$.)
Now, we have
$$\begin{align}
\frac18\cdot\frac{\tan(x)}{4+\tan^2(x)} &= \frac18 \cdot \frac{\sin(x)\cos(x)}{4\cos^2(x)+\sin^2(x)} \\
&= \frac18 \cdot \frac{\frac12 \sin(2x)}{3\cos^2(x) + 1} \\
&= \frac1{16} \cdot \frac{\sin(2x)}{\frac32(1+\cos(2x))+1} \\
&= \frac18 \cdot \frac{\sin(2x)}{5+3\cos(2x)}
\end{align}$$
and so both solutions also have matching second terms.
