# Evaluate the definite integral $\int_0^{2\pi}\arctan\left((a\cos x + b\sin x)^2\right)dx$

Writing:

Integrate[ArcTan[(a Cos[x] + b Sin[x])^2], {x, 0, 2 Pi}, Assumptions -> a^2 + b^2 > 0]


$$\int_0^{2\pi}\arctan\left((a\cos x + b\sin x)^2\right)dx,$$ where $$a$$ and $$b$$ are real numbers.

I get:

2 Pi ArcTan[Sqrt[1/2 (-1 + Sqrt[1 + (a^2 + b^2)^2])]]


$$2\pi\arctan\sqrt{\frac{\sqrt{1 + (a^2 + b^2)^2}-1}2}$$

How to derive this result on paper?

## migrated from mathematica.stackexchange.comJun 16 at 19:05

This question came from our site for users of Wolfram Mathematica.

• I have translated your question into math language. Please check. – user Jun 16 at 19:36

Denote $$C := a^2 + b^2 .$$ Then, we can find an angle $$x_0$$ such that $$a = \sqrt{C} \cos x_0$$ and $$b = -\sqrt{C} \sin x_0$$. The angle sum formula for $$\sin$$ lets us rewrite the quantity in the inner parentheses of the integrand as $$a \sin x + b \cos x = \sqrt{C} \sin (x - x_0).$$ Then, appealing to the periodicity of the integrand lets us rewrite the integral as $$I(C) := \int_0^{2 \pi} \arctan (C \sin^2 x) \,dx .$$ Differentiating under the integral sign gives $$I'(C) = \int_0^{2 \pi} \frac{\sin^2 x\, dx}{1 + C^2 \sin^4 x} .$$ Now, use symmetry to rewrite $$I'(C)$$ in terms of an integral over $$[0, \pi]$$, and apply the Euler substitution $$x = 2 \arctan t, \,dx = \frac{2\,dt}{1 + t^2}$$, giving the rational integral $$I'(C) = 16 \int_0^{\infty} \frac{t^2 (t^2 + 1) \,dt}{(t^2 + 1)^4 + 16 C^4 t^4}.$$ Integrating gives $$I'(C) = \frac{\pi \sqrt{2}}{\sqrt{1 + \sqrt{1 + C^2}} \sqrt{1 + C^2}} .$$ (This can be done with contour integration, which in this case is tedious but straightforward. Quite possibly there is a better method, and I would be grateful to learn it.) Since $$I(0) = 0$$, we have $$I(C) = \pi \sqrt{2} \int_0^C \frac{dc}{\sqrt{1 + \sqrt{1 + c^2}} \sqrt{1 + c^2}} = 2 \pi \sqrt{2} \int_0^{u_0} \frac{du}{u^2 + 2} ;$$ the latter equality follows from applying the substitution $$c^2 + 1 = (u^2 + 1)^2$$, and $$u_0$$ is the $$u$$-value corresponding to $$c = C$$. The integral on the right-hand side is elementary, and so one can produce an explicit formula for $$I(C)$$ in terms of $$C$$ and hence in terms of $$a, b$$.

• Fabulous, thanks! – TeM Jun 17 at 6:05
1. We have $$a\cos x+b\sin x=r\cos(x-\phi)$$, where $$r=\sqrt{a^2+b^2},\quad\cos\phi=a/r,\quad\sin\phi=b/r,$$ and we can simply replace $$x-\phi$$ by $$x$$ in the integrand (because of its $$2\pi$$-periodicity). Denoting $$c=(a^2+b^2)/2$$, we see that the given integral is equal to $$\int_{0}^{2\pi}\arctan(2c\cos^2 x)\,dx=\int_{0}^{2\pi}\arctan\big(c(1+\cos x)\big)\,dx.$$

2. Recall that if $$d\in\mathbb{C}$$ such that $$|d|<1$$, then $$\int_{0}^{2\pi}\ln(1-2d\cos x+d^2)\,dx=0$$ (assuming the principal branch taken). This can be seen, after $$1-2d\cos x+d^2=(1-de^{ix})(1-de^{-ix}),$$ as an application of the Cauchy integral theorem. (Alternatively, one can use the above and power series, or even just split $$\int_{0}^{2\pi}=\int_{0}^{\pi}+\int_{\pi}^{2\pi}$$ and substitute $$x=y+\pi$$ in the second integral, to get $$I(d)=I(d^2)/2$$ from which $$I(d)=0$$ follows easily.) This implies $$\int_{0}^{2\pi}\ln(1+d\cos x)\,dx=2\pi\ln\frac{1+\sqrt{1-d^2}}{2}.$$

3. Write $$\arctan\big(c(1+\cos x)\big)=\frac{1}{2i}\ln\frac{1+ic}{1-ic}\frac{1+d\cos x}{1+\bar{d}\cos x},\qquad d=\frac{ic}{1+ic}$$ (where $$\bar{d}$$ is complex conjugate to $$d$$); the integral then equals $$2\pi\arg(1+ic+\sqrt{1+2ic})=2\pi\arctan\frac{c+v}{1+u}=2\pi\arctan v,$$ where $$\sqrt{1+2ic}=u+iv$$, and we use $$u=c/v$$. This is the answer.

• Thank you very much to you, even if it is hard to understand, I don't know the field of complex numbers well. – TeM Jun 17 at 6:05

Premise: this self-response has been added "taking inspiration" from the two previous ones, especially that of @Travis.

Since, as usual, it is possible to write: \begin{aligned} A\cos x+B\sin x & = \sqrt{A^2 + B^2}\left(\frac{A}{\sqrt{A^2+B^2}}\cos x + \frac{B}{\sqrt{A^2+B^2}}\sin x\right) \\ & = C\left(\cos\varphi\cos x + \sin\varphi\sin x\right) \\ & = C\cos(x-\varphi) \end{aligned} it follows that: $$I(C) := \int_0^{2\pi}\arctan\left(\left(A\cos x+B\sin x\right)^2\right)\text{d}x = \int_0^{2\pi}\arctan\left(\left(C\cos(x-\varphi)\right)^2\right)\text{d}x$$ that placing $$y = x - \varphi$$, thanks to the periodicity of the integrand, equivalent to writing (1): $$I(C) = \int_{0-\varphi}^{2\pi-\varphi}\arctan\left(\left(C\cos y\right)^2\right)\text{d}y = \int_0^{2\pi}\arctan\left(C^2\cos^2 y\right)\text{d}y\,.$$ Then, differentiating under the integral sign, we have: \begin{aligned} I'(C) & = \int_0^{2\pi} \frac{2C\cos^2 y}{1+C^4\cos^4 y}\,\text{d}y \\ & = \int_0^{\frac{\pi}{2}} \frac{8C\frac{1+\cos(2y)}{2}}{1+C^4\left(\frac{1+\cos(2y)}{2}\right)^2}\,\text{d}y \\ & = \int_0^{\pi} \frac{4C\left(1+\cos(z)\right)}{1+\frac{C^4}{4}\left(1+\cos(z)\right)^2}\,\frac{1}{2}\text{d}z \\ & = \int_0^{\infty} \frac{2C\left(1+\frac{1-t^2}{1+t^2}\right)}{1+\frac{C^4}{4}\left(1+\frac{1-t^2}{1+t^2}\right)^2}\,\frac{2}{1+t^2}\text{d}t \\ & = \int_0^{\infty} \frac{8C}{C^4+\left(1+t^2\right)^2}\text{d}t \\ & = \int_0^{\infty} \frac{8C}{\left(C^2 + \text{i}\left(1+t^2\right)\right)\left(C^2 - \text{i}\left(1+t^2\right)\right)}\text{d}t \\ & = \frac{4\text{i}}{C}\left(\int_0^{\infty} \frac{1}{1+\text{i}C^2+t^2}\text{d}t - \int_0^{\infty} \frac{1}{1-\text{i}C^2+t^2}\text{d}t\right) \\ & = \frac{4\text{i}}{C}\left(\frac{1}{\sqrt{1+\text{i}C^2}}\int_0^{\infty} \frac{\frac{1}{\sqrt{1+\text{i}C^2}}}{1+\left(\frac{t}{\sqrt{1+\text{i}C^2}}\right)^2}\text{d}t - \frac{1}{\sqrt{1-\text{i}C^2}}\int_0^{\infty} \frac{\frac{1}{\sqrt{1-\text{i}C^2}}}{1+\left(\frac{t}{\sqrt{1-\text{i}C^2}}\right)^2}\text{d}t\right) \\ & = \frac{4\text{i}}{C}\left(\frac{\arctan\left(\frac{t}{\sqrt{1+\text{i}C^2}}\right)}{\sqrt{1+\text{i}C^2}}-\frac{\arctan\left(\frac{t}{\sqrt{1-\text{i}C^2}}\right)}{\sqrt{1-\text{i}C^2}}\right)_{t=0}^{t=\infty} \\ & = \frac{4\text{i}}{C}\left(\frac{\frac{\pi}{2}}{\sqrt{1+\text{i}C^2}}-\frac{\frac{\pi}{2}}{\sqrt{1-\text{i}C^2}}\right) - \frac{4\text{i}}{C}\left(\frac{0}{\sqrt{1+\text{i}C^2}}-\frac{0}{\sqrt{1-\text{i}C^2}}\right) \\ & = \frac{2\pi}{C}\frac{\text{i}\left(\sqrt{1-\text{i}C^2}-\sqrt{1+\text{i}C^2}\right)}{\sqrt{1+C^4}} \\ \end{aligned} and noting that: $$\left(\frac{\text{i}\left(\sqrt{1-\text{i}C^2}-\sqrt{1+\text{i}C^2}\right)}{\sqrt{1+C^4}}\right)^4 = \left(\frac{-2\left(-1+\sqrt{1+C^4}\right)}{1+C^4}\right)^2$$ we get: $$I'(C) = \frac{2\pi}{C}\sqrt{\frac{2\left(-1+\sqrt{1+C^4}\right)}{1+C^4}}\,,$$ while, integrating, we have (2): \begin{aligned} I(C) & = 2\pi\int \frac{2}{C\sqrt{1+C^4}}\sqrt{\frac{-1+\sqrt{1+C^4}}{2}}\,\text{d}C \\ & = 2\pi\int \frac{\frac{2}{C\sqrt{1+C^4}}\sqrt{\frac{-1+\sqrt{1+C^4}}{2}}\left(1+\frac{-1+\sqrt{1+C^4}}{2}\right)}{1+\frac{-1+\sqrt{1+C^4}}{2}}\,\text{d}C \\ & = 2\pi\int \frac{\frac{2}{C\sqrt{1+C^4}}\,\frac{C^4}{4\sqrt{\frac{-1+\sqrt{1+C^4}}{2}}}}{1+\frac{-1+\sqrt{1+C^4}}{2}}\,\text{d}C \\ & = 2\pi\int \frac{\frac{1}{2\sqrt{\frac{-1+\sqrt{1+C^4}}{2}}}\,\frac{C^3}{\sqrt{1+C^4}}}{1+\frac{-1+\sqrt{1+C^4}}{2}}\,\text{d}C \\ & = 2\pi\arctan\left(\sqrt{\frac{-1+\sqrt{1+C^4}}{2}}\,\right) + k\,. \end{aligned} Given that from (1) we have $$I(0) = 0$$ and from (2) we have $$I(0) = k$$, we deduce that $$k = 0$$ and therefore: $$\int_0^{2\pi}\arctan\left(C^2\cos^2 y\right)\text{d}y = 2\pi\arctan\left(\sqrt{\frac{-1+\sqrt{1+C^4}}{2}}\,\right)$$ ie: $$\int_0^{2\pi}\arctan\left(\left(A\cos x+B\sin x\right)^2\right)\text{d}x = 2\pi\arctan\left(\sqrt{\frac{-1+\sqrt{1+\left(A^2+B^2\right)^2}}{2}}\,\right),$$ as we wanted to prove.