<s>[INST] Integration with Cos function in denominator I need to solve following integration:
$$\int_0^{\frac{\pi }{2}} \frac{1}{\left(a \cos ^2(x)+1\right)^m} \, dx$$
In Mathematica, the solution is given with $\text{Hypergeometric2F1}$ function. However, I want to know how to derive this step-by-steps. Can someone please guide me?
I started by applying the negative binomial expansion, however it works only when $a \cos ^2(x)<1$. I am wondering that if there is any general expression !!!
 [/INST] So as @Kiryl Pesotski suggests, we need to rewrite your integral in the form
$$_2 F_1(a,b;c;x) = \frac{\Gamma (c)}{\Gamma (b) \Gamma (c- b)} \int_0^1 \frac{t^{b - 1} (1 - t)^{c - b - 1}}{(1 - xt)^a} \, dt.\tag1$$
For convergence, I will assume the $a$ appearing in your integral is greater than negative one $(a > -1)$.
Since $\cos^2 x = 1 - \sin^2 x$, we begin by writing the integral as
$$I = \int_0^{\pi/2} \frac{dx}{(a + 1 - a \sin^2 x)^m} = \frac{1}{(a + 1)^m} \int_0^{\pi/2} \frac{dx}{\left (1 - \frac{a}{a + 1} \sin^2 x \right )^m}.$$
Setting $t = \sin^2 x$, since $\cos x = \sqrt{1 - t}$ then $dx = dt/(2 \sqrt{t} \sqrt{1 - t})$ while for the limits of integration $(0,\pi/2) \mapsto (0,1)$. Thus
\begin{align*}
I &= \frac{1}{2(a + 1)^m} \int_0^1 \frac{t^{-1/2} (1 - t)^{-1/2}}{\left (1 - \frac{a}{a + 1} t \right )^m} \, dt\\
&= \frac{1}{2 (a + 1)^m} \cdot \frac{\Gamma (1/2) \Gamma (1/2)}{\Gamma (1)} \cdot \frac{\Gamma (1)}{\Gamma (1/2) \Gamma (1/2)} \int_0^1 \frac{t^{1/2 - 1} (1 - t)^{1 - 1/2 - 1}}{\left (1 - \frac{a}{a + 1} t \right )^m} \, dt.
\end{align*}
Now the above integral is exactly in the form of (1) where $a = m, b = 1/2, c = 1$, and $x = a/(a+1)$. So in terms of the hypergeometric function the integral we started out with can be written as
$$\int_0^{\pi/2} \frac{dx}{(a \cos^2 x + 1)^m} = \frac{\pi}{2(a + 1)^m}\ _2 F_1 \left (m,\frac{1}{2};1; \frac{a}{a + 1} \right ).$$
</s>