2

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.

Jay Lemmon
  • 2,228
  • I'm guessing the complex part has something to do with the contour formula for the Legendre polynomials., and I think the integration can probably be done using Chebyshev polynomials. – Matthew Cassell Mar 16 '20 at 10:33
  • 2
    The numerator in the last integral should be $(r \cos \phi - R \cos \theta)^2$. Make the change of variables $z = e^{i \theta}$, then the integral is $2 \pi i$ times the sum of the residues at $0$ and at $r e^{i \phi}/R$, which gives $$\frac {\pi (R^2 - r^2) \cos \psi} {2 R^2}.$$ – Maxim Mar 16 '20 at 12:32
  • @Maxim -- oops, yes, fixed – Jay Lemmon Mar 16 '20 at 12:34
  • @Maxim - Can you expand on what you're doing after the change of variables? I don't follow after that. – Jay Lemmon Mar 16 '20 at 12:37
  • @Maxim Nice one. I didn't think the contour integral would be so easy or I would have done so myself. – user5713492 Mar 16 '20 at 18:17
  • @Maxim This is great! A whole category of math I didn't even know existed, and will make some of the related integrals I did before easier to do/verify. If you want to write up what you did in an answer I'll accept it. Or I'll write up an answer in (hopefully) a few days when I understand the method better. – Jay Lemmon Mar 16 '20 at 22:07
  • Sure, please go ahead and write up an answer. – Maxim Mar 17 '20 at 06:58
  • @Maxim - How did you calculate the residues? Series expansion or limit formula or some other method? The non-zero pole isn't too bad but I think the pole at 0 is of order 4 which makes the limit formula gnarly, but the series expansion doesn't look much better? – Jay Lemmon Mar 17 '20 at 09:44
  • Correct, we have $f(z)/z^4$ with $f$ regular at zero, so we need to evaluate $f^{(3)}(0)/6$. I used a CAS to evaluate the residues. – Maxim Mar 17 '20 at 13:12

1 Answers1

1

Not a full answer yet, but I think I can work on this a little. First off, if $$\tan\xi=\frac{r\sin\phi-R\sin\theta}{r\cos\phi-R\cos\theta}$$ Then it seems to me that $$\cos\xi=\pm\frac{r\cos\phi-R\cos\theta}{\sqrt{r^2+R^2-2rR\cos(\theta-\phi)}}$$ Just consider a right triangle whose opposite side to $\xi$ is $r\sin\phi-R\sin\theta$ and adjacent is $r\cos\phi-R\cos\theta$ and hypotenuse $\sqrt{r^2+R^2-2rR\cos(\theta-\phi)}$. So this would end up with the additive inverse of your integral because $\cos^2\xi=1-\sin^2\xi$ and your integral has $\sin^2\xi$ instead and $$\int_0^{2\pi}\cos(2\theta+\psi)d\theta=0$$ So I am gonna work with my expression for $\cos\xi$ and forge ahead. If I turn out to be wrong for some reason then as I said I would arrive at the additive inverse of the correct answer. I am going to let $\alpha=\theta-\phi$ so that when $\theta$ goes all the way around, so does $\alpha$. Now things start to get bloody. First, $$\begin{align}\cos(2\theta+\psi)&=\cos(2\alpha+2\phi+\psi)=\cos2\alpha\cos(2\phi+\psi)-\sin2\alpha\sin(2\phi+\psi)\\ &=\left(2\cos^2\alpha-1\right)\cos(2\phi+\psi)-2\sin\alpha\cos\alpha\sin(2\phi+\psi)\end{align}$$ Then, $$r^2+R^2-2rR\cos(\theta-\phi)=(r^2+R^2)(1-e\cos\alpha)$$ Where the eccentricity $e=\frac{2rR}{r^2+R^2}$ not to mention $\sqrt{1-e^2}=\frac{R^2-r^2}{R^2+r^2}$ because you said that $r<R$. OK, then $$\begin{align}(r\cos\phi-R\cos\theta)^2&=(r\cos\phi-R\cos(\alpha+\phi))^2\\ &=(r\cos\phi-R\cos\alpha\cos\phi+R\sin\alpha\sin\phi)^2\\ &=r^2\cos^2\phi+R^2\sin^2\phi+R^2\cos^2\alpha\cos2\phi-2rR\cos\alpha\cos^2\phi\\ &\quad+2rR\sin\alpha\sin\phi\cos\phi-2R^2\sin\alpha\cos\alpha\sin\phi\cos\phi\end{align}$$ So now the numerator in your integrand in going to be $$\begin{align}N&=\cos(2\theta+\psi)(r\cos\phi-R\cos\theta)^2&\\ &=\left(2R^2\cos2\phi\cos(2\phi+\psi)-4R^2\sin\phi\cos\phi\sin(2\phi+\psi)\right)&\cos^4\alpha\\ &+\left(-4rR\cos^2\phi\cos(2\phi+\psi)+4rR\sin\phi\cos\phi\sin(2\phi+\psi)\right)&\cos^3\alpha\\ &+\left(2r^2\cos^2\phi\cos(2\phi+\psi)+2R^2\sin^2\phi\cos(2\phi+\psi)-R^2\cos2\phi\cos(2\phi+\psi)\right.&\\ &\quad\quad\left.+4R^2\sin\phi\cos\phi\sin(2\phi+\psi)\right)&\cos^2\alpha\\ &+\left(2rR\cos^2\phi\cos(2\phi+\psi)-4rR\sin\phi\cos\phi\sin(2\phi+\psi)\right)&\cos\alpha\\ &+\left(-r^2\cos^2\phi\cos(2\phi+\psi)-R^2\sin^2\phi\cos(2\phi+\psi)\right)&(1)\\ &+\left(-4R^2\sin\phi\cos\phi\cos(2\phi+\psi)-2R^2\cos2\phi\sin(2\phi+\psi)\right)&\cos^3\alpha\sin\alpha\\ &+\left(4rR\sin\phi\cos\phi\cos(2\phi+\psi)+4rR\cos^2\phi\sin(2\phi+\psi)\right)&\cos^2\alpha\sin\alpha\\ &+\left(2R^2\sin\phi\cos\phi\cos(2\phi+\psi)-2r^2\cos^2\phi\sin(2\phi+\psi)-2R^2\sin^2\phi\sin(2\phi+\psi)\right)&\cos\alpha\sin\alpha\\ &+\left(-2rR\cos\phi\cos\phi\cos(2\phi+\psi)\right)&\sin\alpha\end{align}$$ Now for some actual integrals. If we let $$\sin\beta=\frac{\sqrt{1-e^2}\sin\alpha}{1-e\cos\alpha}$$ Then $$\cos\beta=\frac{\cos\alpha-e}{1-e\cos\alpha}$$ And so $$d\beta=\frac{\sqrt{1-e^2}\,d\alpha}{1-e\cos\alpha}$$ So that $$\int_0^{2\pi}\frac{d\alpha}{1-e\cos\alpha}=\int_0^{2\pi}\frac{d\beta}{\sqrt{1-e^2}}=\frac{2\pi}{\sqrt{1-e^2}}$$ And so... $$\begin{align}\int_0^{2\pi}\frac{\cos^4\alpha\,d\alpha}{1-e\cos\alpha}&=\int_0^{2\pi}\frac{\left(\frac{1-(1-e\cos\alpha)}e\right)^4}{1-e\cos\alpha}d\alpha\\ &=\frac1{e^4}\int_0^{2\pi}\left(\frac1{1-e\cos\alpha}-4+6(1-e\cos\alpha)\right.\\ &\quad\left.-4(1-e\cos\alpha)^2+(1-e\cos\alpha)^3\right)d\alpha\\ &=\frac{2\pi}{e^4}\left(\frac1{\sqrt{1-e^2}}-1-\frac12e^2\right)\end{align}$$ Where we have kept in mind that
$\int_0^{2\pi}d\alpha=2\pi$, $\int_0^{2\pi}\cos^2\alpha\,d\alpha=\pi$, and $\int_0^{2\pi}\cos\alpha\,d\alpha=\int_0^{2\pi}\cos^3\alpha\,d\alpha=0$. So now we can do $$\begin{align}\int_0^{2\pi}\frac{\cos^3\alpha\,d\alpha}{1-e\cos\alpha}&=\int_0^{2\pi}\frac{\left(\frac{1-(1-e\cos\alpha)}e\right)^3}{1-e\cos\alpha}d\alpha\\ &=\frac1{e^3}\int_0^{2\pi}\left(\frac1{1-e\cos\alpha}-3+3(1-e\cos\alpha)-(1-e\cos\alpha)^2\right)d\alpha\\ &=\frac{2\pi}{e^3}\left(\frac1{\sqrt{1-e^2}}-1-\frac12e^2\right)\end{align}$$ $$\begin{align}\int_0^{2\pi}\frac{\cos^2\alpha\,d\alpha}{1-e\cos\alpha}&=\int_0^{2\pi}\frac{\left(\frac{1-(1-e\cos\alpha)}e\right)^2}{1-e\cos\alpha}d\alpha\\ &=\frac1{e^2}\int_0^{2\pi}\left(\frac1{1-e\cos\alpha}-2+1-e\cos\alpha\right)d\alpha\\ &=\frac{2\pi}{e^2}\left(\frac1{\sqrt{1-e^2}}-1\right)\end{align}$$ $$\begin{align}\int_0^{2\pi}\frac{\cos\alpha\,d\alpha}{1-e\cos\alpha}&=\int_0^{2\pi}\frac{\left(\frac{1-(1-e\cos\alpha)}e\right)}{1-e\cos\alpha}d\alpha\\ &=\frac1{e}\int_0^{2\pi}\left(\frac1{1-e\cos\alpha}-1\right)d\alpha\\ &=\frac{2\pi}{e}\left(\frac1{\sqrt{1-e^2}}-1\right)\end{align}$$ And by symmetry $$\begin{align}\int_0^{2\pi}\frac{\sin\alpha\,d\alpha}{1-e\cos\alpha}&=\int_0^{2\pi}\frac{\cos\alpha\sin\alpha\,d\alpha}{1-e\cos\alpha}=\int_0^{2\pi}\frac{\cos^2\alpha\sin\alpha\,d\alpha}{1-e\cos\alpha}\\ &=\int_0^{2\pi}\frac{\cos^3\alpha\sin\alpha\,d\alpha}{1-e\cos\alpha}=0\end{align}$$ Well, that takes us through all the integrals but now there are a bunch of casualties lying around the battlefield waiting to be packed up into body bags and I'm getting a little tired so I'll have to leave you with a partial answer for now. If this is the kind of stuff you want, let me know and I may be able to make some more progress tomorrow. And maybe check what I have so far for errors.

EDIT: So I substituted $e=\frac{2Rr}{R^2+r^2}$ and $\frac1{\sqrt{1-e^2}}=\frac{R^2+r^2}{R^2-r^2}$ in the results of those integrals from last night and simplified terms. So I got $$\begin{align}&2R^2\cos2\phi\cos(2\phi+\psi)-4R^2\sin\phi\cos\phi\sin(2\phi+\psi)=2R^2\cos(4\phi+\psi)\end{align}$$ $$\begin{align}&-4rR\cos^2\phi\cos(2\phi+\psi)+4rR\sin\phi\cos\phi\sin(2\phi+\psi)\\ &\quad=-2Rr\cos(4\phi+\psi)-2Rr\cos(2\phi+\psi)\end{align}$$ $$\begin{align}&2r^2\cos^2\phi\cos(2\phi+\psi)+2R^2\sin^2\phi\cos(2\phi+\psi)-R^2\cos2\phi\cos(2\phi+\psi)&\\ &\quad\quad+4R^2\sin\phi\cos\phi\sin(2\phi+\psi)\\ &\quad=\left(-2R^2+\frac12r^2\right)\cos(4\phi+\psi)+(R^2+r^2)\cos(2\phi+\psi)+\frac12r^2\cos\psi\end{align}$$ $$\begin{align}&2rR\cos^2\phi\cos(2\phi+\psi)-4rR\sin\phi\cos\phi\sin(2\phi+\psi)\\ &\quad=\frac32Rr\cos(4\phi+\psi)+Rr\cos(2\phi+\psi)-\frac12Rr\cos\psi\end{align}$$ $$\begin{align}&-r^2\cos^2\phi\cos(2\phi+\psi)-R^2\sin^2\phi\cos(2\phi+\psi)\\ &\quad=\frac14(R^2-r^2)\cos(4\phi+\psi)-\frac12(R^2+r^2)\cos(2\phi+\psi)+\frac14(R^2-r^2)\cos\psi\end{align}$$ Then I could add up the terms with $\frac{\cos(4\phi+\psi)}{\sqrt{1-e^2}}$ to get $$\frac{2\pi R^2(R^2-r^2)}{8r^4}\cos(4\phi+\psi)$$ Similarly, adding up the terms with $(-1)\cos(4\phi+\psi)$ I got $$\frac{2\pi(-R^4+3R^2r^2-2r^4)}{8r^4}\cos(4\phi+\psi)$$ And then the terms with $-\frac12e^2\cos(4\phi+\psi)$ with result $$\frac{2\pi(-2R^2r^2+2r^4)}{8r^4}\cos(4\phi+\psi)$$ Which added up to $(0)\cos(4\phi+\psi)$. They all canceled! Next page, add up terms with $\frac{\cos(2\phi+\psi)}{\sqrt{1-e^2}}$: $$(0)\cos(2\phi+\psi)$$ So that first chunk canceled but the second chunk, with $(-1)\cos(2\phi+\psi)$ was $$-\frac12(2\pi)\cos(2\phi+\psi)$$ And then of course the terms with $-\frac12e^2\cos(2\phi+\psi)$ was $$\frac12(2\pi)\cos(2\phi+\psi)$$ So again I got $(0)\cos(2\phi+\psi)$. Then the terms with $\frac{\cos\psi}{\sqrt{1-e^2}}$ added up to $$\frac{2\pi(R^2-r^2)}{8R^2}\cos\psi$$ And with $(-1)\cos\psi$ I had $$\frac{2\pi(R^2-r^2)}{8R^2}\cos\psi$$ And there were no terms with $\frac12e^2\cos\psi$ so my grand total was $$\frac{\pi(R^2-r^2)}{2R^2}\cos\psi$$ Just like @Maxim got with much less effort. I didn't think it would have been so much easier to have done the integral via contour integration or I would have done so in the first place. Kind of amazing that I still got the right answer after all that algebra.

user5713492
  • 16,333
  • Thanks! There's a lot to digest here but I'll start playing with it. At the very least I appreciate the effort :) – Jay Lemmon Mar 16 '20 at 11:33