1.2.1 Both ends at temperature that depends on time. Source term depends on x only

Problem \begin{equation} u_{t}=ku_{xx}+Q\left ( x\right ) \tag{1} \end{equation} 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 first 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\begin{equation} u\left ( x,t\right ) =w\left ( x,t\right ) +r\left ( x,t\right ) \tag{2} \end{equation} Where \(w\left ( x,t\right ) \) is the transient solution which satisfies the homogeneous B.C. One can easily see that the reference function is\begin{equation} r\left ( x,t\right ) =A\left ( t\right ) +\frac{B\left ( t\right ) -A\left ( t\right ) }{L}x \tag{3} \end{equation} 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 ) +Q\left ( x\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 ) +Q\left ( x\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 ) +Q\left ( x\right ) \] Let \begin{align} \tilde{Q}\left ( x,t\right ) & =-r_{t}\left ( x,t\right ) +Q\left ( x\right ) \nonumber \\ & =-\left ( A^{\prime }\left ( t\right ) +\frac{B^{\prime }\left ( t\right ) -A^{\prime }\left ( t\right ) }{L}x\right ) +Q\left ( x\right ) \tag{4} \end{align}

Therefore the problem has been transformed to

\begin{align*} w_{t} & =kw_{xx}+\tilde{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 above. It is a homogeneous BC but with a source that depends on \(x,t\). This is solved using eigenfunction expansion. The only difference is that now the source is \(-r_{t}\left ( x,t\right ) +Q\left ( x\right ) \) (mean means the new source has become time dependent), while in the last case above, the source was just \(-r_{t}\left ( x,t\right ) \). The solution is therefore

\begin{align} w\left ( x,t\right ) & =\sum _{n=1}^{\infty }a_{n}\left ( t\right ) \Phi _{n}\left ( x\right ) \tag{5}\\ \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}\tilde{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}

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 (5) and \(r\left ( x,t\right ) \) is given by (3) and \(\tilde{Q}\left ( x,t\right ) \) is given by (4).

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 ) \\ Q\left ( x\right ) & =x \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 ) \\ \tilde{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 ) +Q\left ( 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 ) +x\\ q_{n}\left ( t\right ) & =\frac{2}{L}\int _{0}^{L}\tilde{Q}\left ( x,t\right ) \sin \left ( \sqrt{\lambda _{n}}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.