How to do this integral $\int_{-\pi}^{\pi}\frac{\cos^2(x)}{1+a^x}dx, a>0$

definite integralsintegration

$$\int_{-\pi}^{\pi}\frac{\cos^2(x)}{1+a^x}dx, a>0$$
I've tried doing $z = e^{ix}$ and evaluating the resulting contour integral, but this introduced a branch cut that goes through the contour ($a^x$ becomes $a^{-i\log(z)})$.

The answer is $\frac{\pi}{2}$ (independent of $a$), but I don't know how one would get to that answer.

Could anyone help me with this integral?

Best Answer

Using the reflection property: $\int_{a}^{b}f(x)\mathrm dx=\int_{a}^{b}f(a+b-x)\mathrm dx$ $$x\mapsto -x \implies \mathrm I =\int_{-\pi}^{\pi}\dfrac{a^x\cos^2 x}{1+a^x}\mathrm dx$$

Add the initial integral to the transformed integral to get $2\mathrm I$ and consequently the value of the integral at hand. $$2\mathrm I=\int_{-\pi}^{\pi}\dfrac{1+a^x}{1+a^x}\cdot\cos^2x\mathrm dx=2\int_{0}^{\pi}\dfrac{1+\cos 2x}{2}\mathrm dx \implies \mathrm I=\pi/2$$

Related Question