1.1.9 Pure diﬀusion. Both ends at temperature that is time dependent

$$u_{t}=ku_{xx} \tag{1}$$ BC are\begin{align*} u\left ( 0,t\right ) & =A\left ( t\right ) \qquad t>0\\ u\left ( L,t\right ) & =B\left ( t\right ) \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, the ﬁrst step is to reduce the problem to one with homogeneous B.C. to be able to use separation of variables. This is done by using a reference solution $$r\left ( x,t\right )$$ which only needs to satisfy the B.C. Let the total solution be$$u\left ( x,t\right ) =w\left ( x,t\right ) +r\left ( x,t\right ) \tag{2}$$ Where $$w\left ( x,t\right )$$ is the transient solution which satisﬁes the homogeneous B.C. One can easily see that$$r\left ( x,t\right ) =A\left ( t\right ) +\frac{B\left ( t\right ) -A\left ( t\right ) }{L}x \tag{3}$$ Is such a function. Substituting (1) back into the original PDE gives\begin{align*} \frac{\partial }{\partial t}\left ( w\left ( x,t\right ) +r\left ( x,t\right ) \right ) & =k\frac{\partial ^{2}}{\partial x^{2}}\left ( w\left ( x,t\right ) +r\left ( x,t\right ) \right ) \\ w_{t}\left ( x,t\right ) +r_{t}\left ( x,t\right ) & =kw_{xx}\left ( x,t\right ) +kr_{xx}\left ( x,t\right ) \end{align*}

But $$r_{xx}\left ( x,t\right ) =0$$ and $$r_{t}=A^{\prime }\left ( t\right ) +\frac{B^{\prime }\left ( t\right ) -A^{\prime }\left ( t\right ) }{L}x$$ and PDE becomes$w_{t}\left ( x,t\right ) =kw_{xx}\left ( x,t\right ) -r_{t}\left ( x,t\right )$ Let \begin{align*} Q\left ( x,t\right ) & =-r_{t}\left ( x,t\right ) \\ & =-\left ( A^{\prime }\left ( t\right ) +\frac{B^{\prime }\left ( t\right ) -A^{\prime }\left ( t\right ) }{L}x\right ) \end{align*}

Therefore the problem has been transformed to\begin{align*} w_{t} & =kw_{xx}+Q\left ( x,t\right ) \\ w\left ( 0,t\right ) & =0\\ w\left ( L,t\right ) & =0\\ w\left ( 0,x\right ) & =u\left ( x,0\right ) -r\left ( x,0\right ) \\ & =f\left ( x\right ) -\left ( A\left ( 0\right ) +\frac{B\left ( 0\right ) -A\left ( 0\right ) }{L}x\right ) \end{align*}

But the above problem was solved before. It is a homogeneous BC but with a source that depends on $$x,t$$. This is solved using eigenfunction expansion. The solution is\begin{align} w\left ( x,t\right ) & =\sum _{n=1}^{\infty }a_{n}\left ( t\right ) \Phi _{n}\left ( x\right ) \tag{4}\\ \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 \\ q_{n}\left ( t\right ) & =\frac{2}{L}\int _{0}^{L}Q\left ( x,t\right ) \Phi _{n}\left ( x\right ) dx\nonumber \\ a_{n}\left ( t\right ) & =a_{n}\left ( 0\right ) e^{-k\lambda _{n}t}+e^{-k\lambda _{n}t}\int _{0}^{t}q_{n}\left ( \tau \right ) e^{k\lambda _{n}\tau }d\tau \nonumber \\ a_{n}\left ( 0\right ) & =\frac{2}{L}\int _{0}^{L}\left ( f\left ( x\right ) -r\left ( x,0\right ) \right ) \Phi _{n}\left ( x\right ) dx\nonumber \end{align}

The only diﬀerence now is that initial conditions is $$f\left ( x\right ) -r\left ( x,0\right )$$ and not just $$f\left ( x\right )$$ as before.   This completes the solution.  The solution is $$u\left ( x,t\right ) =w\left ( x,t\right ) +r\left ( x,t\right )$$ where $$w\left ( x,t\right )$$ is given by (4) and $$r\left ( x,t\right )$$ is given by (3).

Animation

This example was solved also numerically to verify the above result. Let \begin{align*} L & =30\text{ meter}\\ k & =\frac{1}{10}\frac{m^{2}}{\sec }\\ u\left ( x,0\right ) & =f\left ( x\right ) =60-2x\\ u\left ( 0,t\right ) & =A\left ( t\right ) =\frac{t}{5}\sin \left ( t\right ) \\ u\left ( 30,0\right ) & =B\left ( t\right ) =\frac{t}{10}\cos \left ( t\right ) \end{align*}

The solution is\begin{align*} u\left ( x,t\right ) & =w\left ( x,t\right ) +r\left ( x,t\right ) \\ r\left ( x,t\right ) & =A\left ( t\right ) +\frac{B\left ( t\right ) -A\left ( t\right ) }{L}x\\ & =\frac{t}{5}\sin \left ( t\right ) +\frac{\frac{t}{10}\cos \left ( t\right ) -\frac{t}{5}\sin \left ( t\right ) }{30}x\\ w\left ( x,t\right ) & =\sum _{n=1}^{\infty }a_{n}\left ( t\right ) \Phi _{n}\left ( x\right ) \\ \lambda _{n} & =\left ( \frac{n\pi }{L}\right ) ^{2}\qquad n=1,2,3,\cdots \\ \Phi _{n}\left ( x\right ) & =\sin \left ( \sqrt{\lambda _{n}}x\right ) \\ Q\left ( x,t\right ) & =-\left ( A^{\prime }\left ( t\right ) +\frac{B^{\prime }\left ( t\right ) -A^{\prime }\left ( t\right ) }{L}x\right ) \\ & =-\frac{1}{300}\left ( \left ( x-2t\left ( x-30\right ) \right ) \cos t-\left ( \left ( t+2\right ) x-60\right ) \sin t\right ) \\ q_{n}\left ( t\right ) & =\frac{2}{L}\int _{0}^{L}Q\left ( x,t\right ) \Phi _{n}\left ( x\right ) dx\\ a_{n}\left ( t\right ) & =a_{n}\left ( 0\right ) e^{-k\lambda _{n}t}+e^{-k\lambda _{n}t}\int _{0}^{t}q_{n}\left ( \tau \right ) e^{k\lambda _{n}\tau }d\tau \\ a_{n}\left ( 0\right ) & =\frac{2}{L}\int _{0}^{L}\left ( f\left ( x\right ) -r\left ( x,0\right ) \right ) \Phi _{n}\left ( x\right ) dx \end{align*}

This is an animation of the above, using 50 terms in the sum for 500 seconds.

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