Solution (source code)

= Solution

With $u=\cos\theta$, the boundary data have the finite <Legendre polynomial> expansion
$$
-2+2u+3u^2=-P_0(u)+2P_1(u)+2P_2(u).
$$
Inside the sphere, every $r^{-\ell-1}$ term is singular at the origin and must be absent. Matching at $r=a$ therefore gives
$$
\boxed{\Psi_{\mathrm{in}}(r,\theta)
=-1+2\frac ra\cos\theta+\frac{r^2}{a^2}(3\cos^2\theta-1)}.
$$
In the exterior, decay at infinity excludes all $r^\ell$ terms, including the constant term at $\ell=0$. Thus
$$
\boxed{\Psi_{\mathrm{out}}(r,\theta)
=-\frac ar+2\frac{a^2}{r^2}\cos\theta
+\frac{a^3}{r^3}(3\cos^2\theta-1)}.
$$
Both <harmonic functions> have the prescribed <Dirichlet boundary condition>, and each is finite throughout its own domain. The interior expression is regular even at the origin because $r\cos\theta=z$ and $r^2(3\cos^2\theta-1)=2z^2-x^2-y^2$. <Uniqueness of the Dirichlet problem> identifies these as the respective solutions. Their normal derivatives need not match: the two <Dirichlet problems> do not require a single <harmonic function> across the bounding sphere.