<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] Multiplying both numerator and denominator by $\sec^2 \theta$ yields
$$
\begin{aligned}
I_2=&\int\left(\frac{\cos \theta}{1+\sin ^{2} \theta}\right)^{2} d \theta\\=& \int \frac{\sec ^{2} \theta}{\left(\sec ^{2} \theta+\tan ^{2} \theta\right)^{2}} d \theta \\
=& \int \frac{d t}{\left(1+2 t^{2}\right)^{2}}, \text { where } t=\tan \theta
\end{aligned}
$$
$$
\begin{aligned}
I_{2} & =\int \frac{d t}{\left(1+2 t^{2}\right)^{2}}\\&=-\frac{1}{4}\int\frac{1}{t} d\left(\frac{1}{1+2 t^{2}}\right)\\
&=-\frac{1}{4 t\left(1+2 t^{2}\right)}-\frac{1}{4}\left(\frac{1}{t^{2}\left(1+2 t^{2}\right)} d t\right.\\
&=-\frac{1}{4 t\left(1+2 t^{2}\right)}-\frac{1}{4} \int\left(\frac{1}{t^{2}}-\frac{2}{1+2 t^{2}}\right) d t \\
&=-\frac{1}{4 t\left(1+2 t^{2}\right)}+\frac{1}{4 t}+\frac{1}{2 \sqrt{2}} \tan ^{-1}(\sqrt{2} t)+C \\
&=\frac{t}{2\left(2 t^{2}+1\right)}+\frac{1}{2 \sqrt{2}} \tan ^{-1}(\sqrt{2} t)+C \\
&=\frac{\tan \theta}{2\left(2 \tan ^{2} \theta+1\right)}+\frac{1}{2 \sqrt{2}} \tan ^{-1}(\sqrt{2} \tan \theta)+C
\end{aligned}
$$
Now let’s go further to $I_3$ by the substitution $\tan u=\sin \theta$.
$$\begin{aligned} \int \frac{\cos ^{3} \theta}{\left(1+\sin ^{2} \theta\right)^{3}} d \theta &=\int \frac{1-\tan ^{2} u}{\left(1+\tan ^{2} \theta\right)^{3}} \cdot \sec ^{2} u d u \\ &=\int \frac{1-\tan ^{2} u}{\sec ^{4} u} d u \\ &=\int\left(\cos ^{4} u-\sin ^{2} u \cos ^{2} u\right) d u \\ &=\int \cos ^{2} u\left(\cos ^{2} u-\sin ^{2} u\right) d u \\ &=\int \frac{1+\cos 2 u}{2} \cos 2 u d u \\ &=\frac{\sin 2 u}{4}+\frac{1}{2} \int \frac{1+\cos 4 u}{2} d u \\ &=\frac{\sin u \cos u}{2}+\frac{1}{4} u+\frac{1}{16} \sin 4 u+C \\ &=\frac{\sin u \cos u}{2}+\frac{u}{4}+\frac{\sin u \cos u \cos 2 u}{4}+C \\ &=\frac{u}{4}+\frac{\sin u \cos u}{4}(2+\cos 2 u)+C \\ & =\frac{1}{4} \tan ^{-1}(\sin \theta)+\frac{\sin \theta}{4\left(1+\sin ^{2} \theta\right)}\left(2+\frac{1-\sin ^{2} \theta}{1+\sin ^{2} \theta}\right)+C\\& =\frac{1}{4} \tan ^{-1}(\sin \theta)+\frac{\sin \theta\left(\sin ^{2} \theta+3\right)}{(\cos 2 \theta-3)^{2}}+C\end{aligned}$$
:|D Wish you enjoy my solution!
</s>