1.1.8 Pure diﬀusion. Both ends at ﬁxed non-zero temperature (not time dependent)

Problem $$u_{t}=ku_{xx} \tag{1}$$ BC are\begin{align*} u\left ( 0,t\right ) & =T_{1}\qquad t>0\\ u\left ( L,t\right ) & =T_{2}\qquad t>0 \end{align*}

Initial conditions$u\left ( x,0\right ) =f\left ( x\right ) \qquad 0<x<L$ Solution

Since boundary conditions are Nonhomogeneous, then the ﬁrst step is to reduce the problem to one with homogeneous B.C. to be able to use separation of variables (separation of variables can only be done on a PDE with homogeneous B.C.)

This is done by using steady state solution. Let the total solution be$$u\left ( x,t\right ) =w\left ( x,t\right ) +r\left ( x\right ) \tag{1}$$ Where $$w\left ( x,t\right )$$ is the transient solution which satisﬁes the homogeneous B.C. and $$r\left ( x\right )$$ is the steady state solution which do not depend on time and just needs to satisfy the nonhomogeneous BC. Since $$r\left ( x\right )$$ is the steady state solution, then the PDE becomes an ODE\begin{align*} 0 & =kr^{\prime \prime }\left ( x\right ) \\ r\left ( 0\right ) & =T_{1}\\ r\left ( L\right ) & =T_{2} \end{align*}

This has the solution $$r\left ( x\right ) =c_{1}x+c_{2}$$. Using BC at $$x=0$$ leads to $$T_{1}=c_{2}$$. Therefore the solution is $$r\left ( x\right ) =c_{1}x+T_{1}$$. Using BC at $$x=L$$ gives $$T_{2}=c_{1}L+T_{1}$$ or $$c_{1}=\frac{T_{2}-T_{1}}{L}$$. Hence$r\left ( x\right ) =\left ( \frac{T_{2}-T_{1}}{L}\right ) x+T_{1}$ Therefore (1) becomes$u\left ( x,t\right ) =w\left ( x,t\right ) +\left ( \frac{T_{2}-T_{1}}{L}\right ) x+T_{1}$ Substituting the above back in the original PDE $$u_{t}=ku_{xx}$$ gives\begin{align*} w_{t} & =kw_{xx}\\ w\left ( 0\right ) & =0\\ w\left ( L\right ) & =0 \end{align*}

The fundamental solution to the above was found earlier. It is gives by\begin{align} w\left ( x,t\right ) & =\sum _{n=1}^{\infty }c_{n}e^{-k\lambda _{n}t}\Phi _{n}\left ( x\right ) \tag{2}\\ \Phi _{n}\left ( x\right ) & =\sin \left ( \sqrt{\lambda _{n}}x\right ) \nonumber \\ \lambda _{n} & =\left ( \frac{n\pi }{L}\right ) ^{2}\qquad n=1,2,3,\cdots \nonumber \end{align}

Substituting (2) back into (1) gives$u\left ( x,t\right ) =\sum _{n=1}^{\infty }c_{n}e^{-k\lambda _{n}t}\Phi _{n}\left ( x\right ) +r\left ( x\right )$ $$c_{n}$$ is now found from initial conditions. The above at $$t=0$$ becomes$f\left ( x\right ) -r\left ( x\right ) =\sum _{n=1}^{\infty }c_{n}\Phi _{n}\left ( x\right )$ Applying orthogonality gives$c_{n}=\frac{2}{L}\int _{0}^{L}\left ( f\left ( x\right ) -r\left ( x\right ) \right ) \Phi _{n}\left ( x\right ) dx$ This completes the solution.

Summary of solution     \begin{align*} u\left ( x,t\right ) & =\sum _{n=1}^{\infty }c_{n}e^{-k\lambda _{n}t}\Phi _{n}\left ( x\right ) +r\left ( x\right ) \\ \Phi _{n}\left ( x\right ) & =\sin \left ( \sqrt{\lambda _{n}}x\right ) \\ \lambda _{n} & =\left ( \frac{n\pi }{L}\right ) ^{2}\qquad n=1,2,3,\cdots \\ r\left ( x\right ) & =\left ( \frac{T_{2}-T_{1}}{L}\right ) x+T_{1}\\ c_{n} & =\frac{2}{L}\int _{0}^{L}\left ( f\left ( x\right ) -r\left ( x\right ) \right ) \Phi _{n}\left ( x\right ) dx \end{align*}

Animation

This example was solved also numerically to verify the above result. Let $$L=30,k=1,f\left ( x\right ) =60-2x$$,$$u\left ( 0,t\right ) =T_{1}=20,u\left ( 30,0\right ) =T_{2}=50$$ Therefore, from above the solution is

\begin{align*} u\left ( x,t\right ) & =\sum _{n=1}^{\infty }c_{n}e^{-k\lambda _{n}t}\Phi _{n}\left ( x\right ) +r\left ( x\right ) \\ \lambda _{n} & =\left ( \frac{n\pi }{L}\right ) ^{2}\\ & =\left ( \frac{n\pi }{30}\right ) ^{2}\qquad n=1,2,3,\cdots \\ f\left ( x\right ) & =60-2x\\ \Phi _{n}\left ( x\right ) & =\sin \left ( \sqrt{\lambda _{n}}x\right ) \\ & =\sin \left ( \frac{n\pi }{30}x\right ) \\ r\left ( x\right ) & =\left ( \frac{T_{2}-T_{1}}{L}\right ) x+T_{1}\\ & =\left ( \frac{30}{30}\right ) x+20\\ & =x+20\\ c_{n} & =\frac{2}{30}\int _{0}^{30}\left ( 60-2x-x-20\right ) \sin \left ( \frac{n\pi }{30}x\right ) dx\\ & =\frac{2}{30}\int _{0}^{30}\left ( 40-3x\right ) \sin \left ( \frac{n\pi }{30}x\right ) dx\\ & =\frac{20}{n\pi }\left ( 4+5\left ( -1\right ) ^{n}\right ) \end{align*}

Hence the solution is$u\left ( x,t\right ) =\left ( \frac{20}{\pi }\sum _{n=1}^{\infty }\frac{1}{n}\left ( 4+5\left ( -1\right ) ^{n}\right ) e^{-\left ( \frac{n\pi }{30}\right ) ^{2}t}\sin \left ( \frac{n\pi }{30}x\right ) \right ) +\left ( x+20\right )$ This is an animation of the above, using 20 terms in the sum for 60 seconds.

Code used to the above, including a Manipulate to compare with the numerical solution is below.