Integral formula for solution of Laplace's equation in polar coordinates I was having a look at this question and was reminded of a nice formula I had seen in my PDE textbook. Given a PDE
$$\boldsymbol{\triangle}u=0~~|~~u(1,\theta)=f(\theta)~~|~~(r,\theta)\in[0,1]\times[0,2\pi)$$
One may write the solution using the Poisson Kernel $\operatorname{PK}$,
$$u(r,\theta)=\frac{1}{2\pi}\int_{-\pi}^\pi f(\phi)~\operatorname{PK}(r,\theta-\phi)\mathrm d\phi
\\ \text{for}~~r\neq1\tag{1}$$
$$\operatorname{PK}(r,\theta)=\frac{1-r^2}{1+r^2-2r\cos\theta}$$
When given the boundary condition $f(\theta)=u(1,\theta)=\sin^2\theta$ one of the answerers was able to find the solution
$$u(r,\theta)=\frac{1-r^2\cos(2\theta)}{2}$$
QUESTION: How would one derive this expression using $(1)$? I tried several approaches, including using Mathematica, geometric series, substitution, Leibniz integral rule, and more, but was completely unable to produce the desired result. Does anyone have any ideas? It is frustrating that this integral should have a simple result, but I am unable to prove it. And yes, I have checked that this works numerically.
 A: What you have is a nice trigonometric integral over a full period, so it can always be calculated using residues. We have
\begin{align}
u(r,\theta)&=\frac{1}{2\pi}\int_{-\pi}^{\pi}\sin^2\phi\frac{1-r^2}{1+r^2-2r\cos(\theta-\phi)}\,d\phi\\
&=\frac{1-r^2}{2\pi}\int_0^{2\pi}\frac{\sin^2t}{1+r^2+2r(\cos\theta\cos t+\sin\theta\sin t)}\,dt,
\end{align}
where I made the substitution $\phi=t-\pi$ and used the addition formula for cosine. Now, observe that the integrand is a rational trigonometric function $R(\sin t,\cos t)$. So, we can rewrite this as an integral over the unit circle in the complex plane by using $z=e^{it}$, hence
\begin{align}
\cos t&=\frac{z+\frac{1}{z}}{2},\quad
\sin t=\frac{z-\frac{1}{z}}{2i},\quad
dt=\frac{dz}{iz}
\end{align}
If you make these substitutions, you should find
\begin{align}
u(r,\theta)&=\frac{r^2-1}{8\pi i}\int_{|z|=1}\underbrace{\frac{1}{z^2}\cdot\frac{(z^2-1)^2}{z^2(re^{-i\theta})+z(1+r^2)+re^{i\theta}}}_{:=f(z)}\,dz
\end{align}
For the rest of the calculation, suppose $0<r<1$ (so that the residue calculations work out nicely and there are no edge cases). Note that $f$ clearly has a double pole at the origin, and it has two other poles which are the roots of the quadratic term in the denominator. The denominator has roots at $-re^{i\theta}$ and at $-\frac{e^{i\theta}}{r}$; now since $0<r<1$, only the first root lies inside the circle. Therefore,
\begin{align}
u(r,\theta)&=\frac{r^2-1}{8\pi i}\cdot 2\pi i\left[\text{Res}(f\,;\,0)+\text{Res}(f\,;\, -re^{i\theta})\right]\\
&=\frac{r^2-1}{4}\left[\frac{-(1+r^2)}{r^2e^{2i\theta}}+\frac{(r^2e^{2i\theta}-1)^2}{r^2e^{2i\theta}\cdot(1-r^2)}\right]\\
&=\frac{-1}{4r^2e^{2i\theta}}\bigg[r^4(1+e^{4i\theta})-2r^2e^{2i\theta}\bigg]\\
&=\frac{1-r^2\cos(2\theta)}{2}
\end{align}
Now, here's few words about how I calculated the residues: note that $f(z)$ is $\frac{1}{z^2}$ times a rational function $\rho(z)$ which is holomorphic at the origin. So, the residue of $f$ at the origin is simply $\rho'(0)$. Next, to calculate the residue of $f$ at $-re^{i\theta}$, we write $f(z)=\frac{(z^2-1)^2}{z^2re^{-i\theta}(z+\frac{e^{i\theta}}{r})}\cdot \frac{1}{z+re^{i\theta}}$ (i.e I simply factored the denominator); now observe that this first part is holomorphic at $z=-re^{i\theta}$, so the residue is simply the value of this function at $-re^{i\theta}$.
I leave it to you to verify all the intermediate algebraic details (this whole calculation took me about 30 mins start to finish, so I'd say this is a reasonable approach... though I'd love to see other methods too).
