# Solving the 2D heat equation with inhomogenous B.C. by separation of variables

I'm working on a numerical solution to the heat equation on the unit square $[0,1] \times [0,1]$:

\begin{align*} \frac{\partial T}{\partial t} = \alpha \nabla^2 T, \quad T(x,y,0) = 0, \quad \text{B.C.}\begin{cases} T(0,y,t) = T(x,0,t) = 0 \\ T(x,1,t) = 100 \\ \frac{\partial{T}}{\partial x}(1,y,t) = 0 \end{cases} \end{align*}

In words, the temperature is held at zero on the left and bottom sides of the square, at 100 degrees on the top, and is insulated on the right.

I want to find the analytic solution so I can compare the results of my numerical computation. I thought I would attempt a solution by separation of variables, however I quickly ran into trouble trying to formulate a related problem with homogenous boundary conditions. In the 1D-cases in most of my textbooks and old notes, this would be done by finding a function $\psi$ such that $U = T-\psi$ is a similar problem but with homogenous B.C. My attempts to find such a function in this case quickly foundered due to the discontinuity at $(0,1)$. Is it possible to solve this problem by separation of variables, and if so, how would this particular difficulty be overcome?

If you solve Laplace's equation $$\nabla^{2}u=0,\\ u(0,y)=0,\;\;\; u_{x}(1,y)=0,\\ u(x,0)=0,\;\;\; u(x,1) = 100,$$ then $v=T-u$ will satisfy $$v_{t}=\alpha \nabla^{2}v,\\ v(t,0,y)=0,\;\; v_{x}(t,1,y)=0,\\ v(t,x,0)=0,\;\; v(t,x,1)=0,\\ v(0,x,y)=-u(x,y).$$ The Laplace equation solution can be written as $$u(x,y)=\sum_{n=0}^{\infty}A_n\sin(\lambda_n x)\sinh(\lambda_n y)$$ where $\lambda_n$ is chosen so that $u_{x}(1,y)=0$, i.e. $\cos(\lambda_n)=0$, i.e. $$\lambda_n = \frac{\pi}{2}+n\pi = \frac{(2n+1)\pi}{2}.$$ The constants $A_n$ are chosen so that $$u(x,1)=\sum_{n=0}^{\infty}A_n\sin((n+1/2)\pi x)\sinh((n+1/2)\pi) = 100.$$ Using the orthogonality of the functions $\sin((n+1/2)\pi x)$ on $[0,1]$ gives $$A_n =\frac{100}{\sinh((n+1/2)\pi)}\frac{\int_{0}^{1}\sin((n+1/2)\pi x)dx}{\int_{0}^{1}\sin^{2}((n+1/2)x)dx}$$ You should be able to solve for $v$ because that's a solution of the standard heat equation with homogeneous boundary conditions, and then let $T=v+u$. There are obvious convergence issues of $u$ at the corners of the region, but nowhere else.