# How I Impressed My Wife: Part 4b

Previously in this series, I have used two different techniques to show that

$Q = \displaystyle \int_0^{2\pi} \frac{dx}{\cos^2 x + 2 a \sin x \cos x + (a^2 + b^2) \sin^2 x} = \displaystyle \frac{2\pi}{|b|}.$

Originally, my wife had asked me to compute this integral by hand because Mathematica 4 and Mathematica 8 gave different answers. At the time, I eventually obtained the solution by multiplying the top and bottom of the integrand by $\sec^2 x$ and then employing the substitution $u = \tan x$ (after using trig identities to adjust the limits of integration).
But this wasn’t the only method I tried. Indeed, I tried two or three different methods before deciding they were too messy and trying something different. So, for the rest of this series, I’d like to explore different ways that the above integral can be computed.
Let me backtrack to a point in the middle of the previous solution:

$Q = \displaystyle \int_0^{2\pi} \frac{dx}{\cos^2 x + 2 a \sin x \cos x + (a^2 + b^2) \sin^2 x}$

$= \displaystyle \int_0^{2\pi} \frac{2 \, dx}{1+\cos 2x + 2 a \sin 2x + (a^2 + b^2)(1-\cos 2x)}$

$= 2 \displaystyle \int_0^{2\pi} \frac{d\theta}{(1+a^2+b^2) + 2 a \sin \theta + (1 - a^2 - b^2) \cos \theta}$

$= 2 \displaystyle \int_{0}^{2\pi} \frac{d\theta}{S + R \cos (\theta - \alpha)}$

$= 2 \displaystyle \int_{0}^{2\pi} \frac{d\phi}{S + R \cos \phi}$,

where $R = \sqrt{(2a)^2 + (1-a^2-b^2)^2}$ and $S = 1 + a^2 + b^2$ (and $\alpha$ is a certain angle that is now irrelevant at this point in the calculation).

Earlier in this series, I used the magic substitution $u = \tan \displaystyle \frac{\phi}{2}$ to evaluate this last integral. Now, I’ll instead use contour integration; see Wikipedia for more details. I will use Euler’s formula as a substitution (see here and here for more details):

$z = e^{i \phi} = \cos \phi + i \sin \phi$,

so that the integral $Q$ is transformed to a contour integral in the complex plane. Under this substitution, as discussed in yesterday’s post,

$\cos \phi = \displaystyle \frac{1}{2} \left[z + \displaystyle \frac{1}{z} \right]$

and

$d\phi = \displaystyle -\frac{i}{z} dz$

Employing this substitution, the region of integration changes from $0 \le \phi \le 2\pi$ to a the unit circle $C$, a closed counterclockwise contour in the complex plane:

$Q = 2 \displaystyle \oint_C \frac{\displaystyle -\frac{i}{z} dz}{S + \displaystyle \frac{R}{2} \left[z + \displaystyle \frac{1}{z} \right]}$

$= -4i \displaystyle \oint_C \frac{dz}{Rz^2 + 2Sz + R}$

$= \displaystyle -\frac{4i}{R} \oint_C \frac{dz}{z^2 + 2\frac{S}{R}z + 1}$

While this looks integral in the complex plane looks a lot more complicated than a regular integral, it’s actually a lot easier to compute using residues. I’ll discuss the computation of this contour integral in tomorrow’s post.