<s>[INST] Integrating $\int \left( \frac{\cos\theta}{1+\sin^2\theta} \right)^n \, d\theta$, for $n=2$ and $n=3$ How do you integrate the following functions:
$$\int \left( \frac{\cos\theta}{1+\sin^2\theta} \right)^2 \, d\theta$$ and $$\int \left( \frac{\cos\theta}{1+\sin^2\theta} \right)^3 \, d\theta 
$$
respectively?
Note: Initially, I tried integrating the function without the power and obtained the result below. 
$$
\int \frac{\cos\theta}{1+\sin^2\theta} \, d\theta = \arctan(\sin\theta)+ C
$$
However, from here it is difficult to proceed. Integration by substitution doesn't seem to work.
How should I go on from here? Any pointers would be greatly appreciated. 
 [/INST] I will be solving the first integral. If I can figure out the second integral I'll post my solution as another answer.
$$I=\int\bigg(\frac{\cos x}{1+\sin^2x}\bigg)^2\mathrm{d}x$$
$$I=\int\frac{\cos^2x}{(1+\sin^2x)^2}\mathrm{d}x$$
$$I=\int\frac{\sec^2 x\ \mathrm{d}x}{(2\tan^2x+1)^2}$$
$t=\tan x\Rightarrow \mathrm{d}t=\sec^2x\ \mathrm{d}x$:
$$I=\int\frac{\mathrm{d}t}{(2t^2+1)^2}$$
Apply the reduction formula
$$\int\frac{\mathrm{d}x}{(ax^2+b)^n}=\frac{x}{2b(n-1)(ax^2+b)^2}+\frac{2n-3}{2b(n-1)}\int\frac{\mathrm{d}x}{(ax^2+b)^{n-1}}$$
With $a=2,\ b=1,\ n=2$:
$$I=\frac{t}{2(2t^2+1)}+\frac12\int\frac{\mathrm{d}t}{2t^2+1}$$
Preform $u=\sqrt{2}\ t$: 
$$I=\frac{t}{2(2t^2+1)}+\frac1{2\sqrt{2}}\int\frac{\mathrm{d}u}{u^2+1}$$
$$I=\frac{t}{2(2t^2+1)}+\frac1{2\sqrt{2}}\arctan u$$
$$I=\frac{t}{2(2t^2+1)}+\frac1{2\sqrt{2}}\arctan t\sqrt{2}$$
$$I=\frac{\tan x}{2(2\tan^2x+1)}+\frac1{2\sqrt{2}}\arctan(\sqrt{2}\tan x)\quad +C$$
</s>