Solution to a Poisson equation I was trying to find the solution $u(x,y)$ to the following Dirichlet problem  for the Poisson's equation
\begin{cases}
-\dfrac{\partial^2 u}{\partial x^2 } - \dfrac{\partial^2 u}{\partial y^2 }= \sin(\pi x)\sin(\pi y) & (x,y)\in D\\
u(x,y)=0 &(x,y)\in \partial D
\end{cases}
where $D$ is the square $[-1,1]\times[-1,1] \in\Bbb R^2$, and $\partial D$ is its boundary.
Reading the book Partial Differential equations with Numerical Methods (by Larsson and Thomée), I saw that a fundamental solution $U(x,y)$ of Poisson's equation is a solution of the following equation
\begin{align}
-\frac{\partial^2 U}{\partial x^2 } - \frac{\partial^2 U}{\partial y^2 }= \delta(x)\delta(y)
\end{align}
where $\delta$ denotes the Dirac delta function.
The function $U(x,y)$ in the $2D$ case is given by
\begin{align}
U(x,y)=-\frac{1}{2\pi}\log(\|(x,y)\|)
\end{align}
With $U$ in hands the solution of the Poisson equation was given by
\begin{align}
  u(x,y)=\int_{-1}^{1}\int_{-1}^1 G(x,y;a,b)\sin(\pi a)\sin(\pi b) \,\,\,da \,\,db
\end{align}
where $G(x,y)=U(x,y)-v_{(a,b)}(x,y)$, and the function $v_{(a,b)}$, for a fixed $(a,b) \in R^2$, is solution of the equation
\begin{align}
-\frac{\partial^2 v_{(a,b)}}{\partial x^2} - \frac{\partial^2 v_{(a,b)}}{\partial y^2}=0
\end{align}
inside the square $[-1,1]\times[-1,1]$, and $v_{(a,b)}=U(x-a,y-b)$ in the boundary of the square.
I understand why the solution can be given by that, my difficulty now is how to find that function $v_{(a,b)}$. Is there a analytical solution to this Poisson Problem?
 A: Well, we can start by finding solutions to the homogeneous problem.
$$-\frac{\partial^2u}{\partial x^2}-\frac{\partial^2u}{\partial x^2}=0$$
$$\implies \nabla^2u(x,y)=0$$
Laplace's equation. Let's construct the solution. Assume $u$ is separable, i.e $u(x,y)=X(x)Y(y)$. Plugging in to the above,
$$X''Y+Y''X=0 \implies \frac{X''}{X}=-\frac{Y''}{Y}$$
The only way this is possible is if both sides are equal to some (possibly complex) constant - call it $k^2$. We then have two ODEs in $x$ and $y$. Let's start with
$$\frac{X''}{X}=k^2 \implies X(x)=a_1e^{kx}+a_2e^{-kx}$$
Now for $y$,
$$-\frac{Y''}{Y}=k^2\implies Y(y)=b_1e^{iky}+b_2e^{-iky}$$
So our homogeneous solution is
$$u_{\text{h}}(x,y)=(a_1e^{kx}+a_2e^{-kx})(b_1e^{iky}+b_2e^{-iky})$$
Now we want a particular solution to the equation
$$\nabla^2 u(x,y)=-\sin(\pi x)\sin(\pi y)$$
Once again, assume separable:
$$X''Y+Y''X=-\sin(\pi x)\sin(\pi y) $$
A little bit of clever guessing might lead you to the fact that
$$u_{\text{p}}(x,y)=\frac{\sin(\pi x)\sin(\pi y)}{2\pi^2}$$
Works. Our solution is now a superposition of the homogeneous and particular solutions,
$$u(x,y)=u_{\text{h}}+u_{\text{p}}=(a_1e^{kx}+a_2e^{-kx})(b_1e^{iky}+b_2e^{-iky})+\frac{\sin(\pi x)\sin(\pi y)}{2\pi^2}$$
We want this equation to have roots when $x=\pm 1\lor y=\pm 1$. Let's do this case by case.
$$u(1,y)=(a_1e^{k}+a_2e^{-k})(b_1e^{iky}+b_2e^{-iky})$$
So we need the parameters $a_1,a_2$ that will make $a_1e^{k}+a_2e^{-k}=0 ~\forall k$. Well, since the functions $\exp(x)$ and $\exp(-x)$ are in fact linearly independent, we require $a_1,a_2=0$. So we can rewrite
$$u(x,y)=b_1e^{iky}+b_2e^{-iky}+\frac{\sin(\pi x)\sin(\pi y)}{2\pi^2}$$
So now
$$u(x,1)=b_1e^{ik}+b_2e^{-ik}$$
Using Euler's formula, we want the parameters $b_1,b_2$ such that
$$b_1(\cos(k)+i\sin(k))+b_2(\cos(k)-i\sin(k))=0 ~ \forall k$$
Let's break up the cosine and sine terms.
$$(b_1+b_2)\cos(k)+i(b_1-b_2)\sin(k)=0$$
Therefore we need
$$b_1+b_2=0;~b_1-b_2=0$$
The only solution, real or complex of such a system is if $b_1=b_2=0.$ So our solution is
$$u(x,y)=\frac{\sin(\pi x)\sin(\pi y)}{2\pi^2}.$$
