Solution (source code)

= Solution

Set $u(r,\theta)=R(r)\Theta(\theta)$. Periodicity and <separation of variables> give the angular modes $1$, $\cos n\theta$, and $\sin n\theta$. The radial equation is
$$
r^2R''+rR'-n^2R=0,
$$
whose solutions are $r^{\pm n}$ for $n\geq1$; the zero mode has solutions $1$ and $\log r$. Thus a general real harmonic <function> on the annulus is
$$
\begin{aligned}
u(r,\theta)={}&A_0+B_0\log r\\
&+\sum_{n=1}^{\infty}
\left(A_nr^n+B_nr^{-n}\right)\cos n\theta\\
&+\sum_{n=1}^{\infty}
\left(C_nr^n+D_nr^{-n}\right)\sin n\theta.
\end{aligned}
$$

The boundary data contain only the $n=2$ cosine mode, so write
$$
u=(Ar^2+Br^{-2})\cos2\theta.
$$
The condition at $r=a$ gives $B=-Aa^4$, and the condition at $r=b$ fixes $A$. The <Dirichlet problem on an annulus for one Fourier mode> therefore has solution
$$
\boxed{
u(r,\theta)=
\frac{b^2(r^4-a^4)}{r^2(b^4-a^4)}\cos2\theta}.
$$