Analytical solution of the thermal conductivity equation What is the exact analytical solution of a 1D thermal conductivity PDE:
$\dfrac{\partial T}{\partial t} = \alpha\cdot \dfrac{\partial^2 T}{\partial x^2}$,
where $T$ = temperature, $\alpha$ = thermal conductivity coefficient, $x\in\left(0,\ldots,L\right)$ = distance coordinate,  $t$ = time.
with mixed B.C.

*

*Dirichlet type B.C.: $\:\:T\left(x=0, t\right)\:=\: 30$

*Neumann type B.C.: $\:\:\dfrac{\partial T}{\partial x} \left(x=L, t\right)\:=\: 0$
I would like to implement the analytical solution into my code to compare an error of numerical schemes I used to numerically solve this eq. I have found that this equation has a numerical solution, but only as an information, not the solution itself.
 A: Our partial differential equation (PDE) and boundary conditions (BCs) are:
$$T_t=\alpha T_{xx};$$
$$T(0,t)=30\text{ and }T_x(L,t)=0.$$
Let's use a generic initial condition (IC):
$$T(x,0)=f(x).$$
First, we transform the dependent variable $T(x,t)$:
$$u(x,t)=T(x,t)-30.$$
This means that:
$$\Rightarrow u(0,t)=30-30=0.$$
The derivative $T_x(L,t)$ isn't affected, so:
$$u_x(L,t)=T_x(L,t)=0.$$
Calculate the derivatives:
$$u_t=T_t\text{ and }T_{xx}=u_{xx}.$$
So we've transformed our PDE to:
$$u_t=\alpha u_{xx};$$
$$u(0,t)=0\text{ and }u_x(L,t)=0;$$
$$u(x,0)=f(x)-30.$$

Now the solving process starts. We use separation of variables.
Assume (make an Ansatz) that:
$$u(x,t)=X(x)\Theta(t),$$
where $X(x)$ and $\Theta(t)$ are functions in $x$ and $t$ only, respectively. Insert into the PDE:
$$X\Theta'=\alpha\Theta X''.$$
Divide both sides by $XT$ to get:
$$\frac{\Theta'}{\alpha \Theta}=\frac{X''}{X}=-k^2,$$
where $k^2\in\mathbb{R}$ and $k^2>0$, called the separation constant.
The PDE is now 'broken up' into two ordinary differential equations (ODEs):
$$\frac{\Theta'}{\alpha \Theta}=-k^2\tag{1};$$
$$\frac{X''}{X}=-k^2\tag{2}.$$
Let's start with the second one. Its solution process is:
$$X(x)=A\sin kx+B\cos kx;$$
$$u(0,t)=0\Rightarrow X(x)=0;$$
$$0=A\sin 0+B\cos 0\Rightarrow B=0;$$
$$X(x)=A\sin kx;$$
$$u_x(L,t)=0\Rightarrow X'(L)=0;$$
$$0=kA\cos kL\Rightarrow \cos kL=0;$$
$$\Rightarrow k=\frac{(n+1/2)\pi}{L};$$
$$k=\frac{(1+2n)\pi}{2L}.$$
The $k$ terms are the eigenvalues of the PDE.
So we have:
$$X_n(x)=A_n\sin\left(\frac{(1+2n)\pi x}{2L}\right).$$
for $n=0,1,2,3,...$

From $(1)$, we glean easily that:
$$\Theta_n(t)=\exp{(-\alpha k^2t)}=\exp{\left[-\alpha\left(\frac{(1+2n)\pi}{2L}\right)^2t\right]};$$
Thus:
$$u_n(x,t)=A_n\exp{\left[-\alpha\left(\frac{(1+2n)\pi}{2L}\right)^2t\right]}\sin\left(\frac{(1+2n)\pi x}{2L}\right).$$
With the superposition principle, we get:
$$\boxed{u(x,t)=\displaystyle\sum_{n=0}^{\infty}A_n\exp{\left[-\alpha\left(\frac{(1+2n)\pi}{2L}\right)^2t\right]}\sin\left(\frac{(1+2n)\pi x}{2L}\right)}$$
for $n=0,1,2,3,...$
At $t=0$, we have:
$$f(x)-30=\displaystyle\sum_{n=1}^{\infty}A_n\sin\left(\frac{(1+2n)\pi x}{2L}\right).$$
We can then use the Fourier series to determine the coefficients $A_n$:
$$\boxed{A_n=\frac{2}{L}\int_0^L\mathrm{d}x\left[\big(f(x)-30\big)\sin\left(\frac{(1+2n)\pi x}{2L}\right)\right].}$$
Finally, don't forget that $T(x,t)=u(x,t)+30$.
A: The general solution for $$\partial_t T(x,t)=\alpha\Delta T(x,t) \,\,\,\text{with}\,\,\, T(0,t)=T(L,t)=0$$ is $$u(x,t)=\sum_{k\in\mathbb{N}}a_k e^{-\alpha\lambda_kt}f_k(x),$$ where the functions $f_k$ are eigenfunctions of the La-Place-Operator to the eigenvalue $\lambda_k$ $$\Delta f_k=\lambda_k f_k,\,\,\,\,\,\,\,(1)$$ with boundary conditions $f_k(0,t)=f_k(L,t)=0$. Because this implies $$\partial_t u(x,t)=\sum_{k\in\mathbb{N}}a_k (-\alpha\lambda_k)e^{-\alpha\lambda_kt}f_k(x)\stackrel{(1)}{=}-\alpha\sum_{k\in\mathbb{N}}a_k e^{-\lambda_kt}\Delta f_k(x)=-\alpha\Delta u(x,t)$$ and $$u(0,t)=u(L,t)=0.$$
The eigenvalue problem (1) is easy to solve with the exponential function: $$f_k(x)=C\sin(k\pi x/L)\,\,\,\,\text{and}\,\,\,\,\lambda_k=-\left(\frac{k\pi}{L}\right)^2.$$ The constant $C$ is defined by the inicial condition $T(x,0)$, after plugged in in $u(x,t)$.
For other boundary conditions add linear terms in $x$ to $u(x,t)$, as it will still solve the PDE. For example $$v(x,t)=u(x,t)+30$$ solves your Dirichlet B.C.. For more difficult B.C., solve the eigenvalue problem with according boundary conditions.
