I'm working on a 2D fluid simulator and a particularly gnarly integral came up.
First, I have two functions in polar coordinates which look like:
$$F(\theta) = cos(2\theta+\psi)$$ $$ G(\theta) = \arctan \big( \frac{r\sin(\phi) - R\sin(\theta)}{r\cos(\phi) - R\cos(\theta)}\big) $$
where $\psi \in {\rm I\!R}$ is an arbitrary constant and $r, R \in \mathbb{R}^+$, $r < R$ and $\theta, \phi \in {\rm I\!R}$.
Essentially $F(\theta)$ is the strength of a point disturbance of my fluid at a point on a circle at $(R, \theta)$ and $G(\theta)$ is the angle between a point at $(r, \phi)$ (an arbitrary point inside the circle) and my point disturbance. I want to integrate the product of $F(\theta)$ and $\cos(G(\theta))^2$ over the surface of this circle (this is part of the equation for the fluid velocity this point disturbance creates at the given point):
$$ \int_0^{2\pi} F(\theta) \cdot \cos(G(\theta))^2 d\theta$$ $$= \int_0^{2\pi} cos(2\theta+\psi) \cos(\arctan \big( \frac{r\sin(\phi) - R\sin(\theta)}{r\cos(\phi) - R\cos(\theta)}\big))^2d\theta$$ $$= \int_0^{2\pi} cos(2\theta+\psi) \frac{(r\cos(\phi) - R\cos(\theta))^2}{R^2+r^2-2rR\cos(\theta-\phi) }d\theta$$
(Note the denominator on the last integral is just the squared distance between the two points).
Actually evaluating this integral is proving frought, though. I have no idea how to do it by hand and most online integrators choke on it. I managed to get an answer with Wolfram Alpha Notebook after a half hour and it gave me this:
$$-\frac{\pi \left(\left(R^6-r^2 R^4\right) \cos (4 \phi -\psi )+r^4 \left(r^2-R^2\right) \cos (\psi )+4 i r^2 \sin (2 \phi -\psi ) \left(r^4+r^2 \cos (2 \phi ) \left(r^2-R^2\right)+R^4\right)\right)}{4 r^4 R^2}$$
However there's an imaginary term in this and I don't understand where it would be coming from. Naively, $F(\theta) \cdot \cos(G(\theta))^2$ is always real for all $\theta$ so I would expect the integral to be, too. So I think Wolfram just balked and spat out a wrong answer? I've never known it to do that but I don't know what else to think.
Is there some way to approach this integral to make it easier? I feel like there's probably some clever application of Green's theorem, or converting the problem using a Fourier transform (both $F(\theta)$ and $\cos(G(\theta))$ are periodic with compatible periods), that would make things easier, but I don't really know where to begin with either.