1.2.7 Both ends at fixed temperature. Source term depends on x and t

\begin{equation} u_{t}=ku_{xx}+Q\left ( x,t\right ) \tag{1} \end{equation} 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, 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 steady state solution. Let the total solution be\begin{equation} u\left ( x,t\right ) =w\left ( x,t\right ) +r\left ( x\right ) \tag{2} \end{equation} Where \(w\left ( x,t\right ) \) is the transient solution which satisfies 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}\] Substituting (2) back in the original PDE \(u_{t}=ku_{xx}+Q\left ( x,t\right ) \) gives\begin{align} w_{t} & =kw_{xx}+Q\left ( x,t\right ) \tag{3}\\ w\left ( 0,t\right ) & =0\nonumber \\ w\left ( L,t\right ) & =0\nonumber \end{align}

The initial conditions are\begin{align*} w\left ( x,0\right ) & =u\left ( x,0\right ) -r\left ( x\right ) \\ & =f\left ( x\right ) -r\left ( x\right ) \end{align*}

But (3) is the same problem as in one of the earlier cases (homogeneous BC with source that depends on \(x\) and \(t\)) Only difference is that, the initial conditions on the earlier problem was \(f\left ( x\right ) \) and now the initial conditions is \(f\left ( x\right ) -r\left ( x\right ) \). Using the earlier solution found gives (using eigenfunction expansion method)\begin{align*} w\left ( x,t\right ) & =\sum _{n=1}^{\infty }a_{n}\left ( t\right ) \Phi _{n}\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 \\ 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\right ) \right ) \Phi _{n}\left ( x\right ) dx \end{align*}

Therefore the final solution is\[ u\left ( x,t\right ) =\sum _{n=1}^{\infty }a_{n}\left ( t\right ) \Phi _{n}\left ( x\right ) +r\left ( x\right ) \]

Example

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 ) & =T_{1}=20\\ u\left ( 30,0\right ) & =T_{2}=50\\ Q\left ( x,t\right ) & =\frac{x}{10}e^{-t} \end{align*}

From above, the solution is\begin{align*} u\left ( x,t\right ) & =\left ( \sum _{n=1}^{\infty }a_{n}\left ( t\right ) \Phi _{n}\left ( x\right ) \right ) +r\left ( x\right ) \\ \Phi _{n}\left ( x\right ) & =\sin \left ( \frac{n\pi }{L}x\right ) =\sin \left ( \frac{n\pi }{30}x\right ) \\ \lambda _{n} & =\left ( \frac{n\pi }{L}\right ) ^{2}=\left ( \frac{n\pi }{30}\right ) ^{2}\qquad n=1,2,3,\cdots \\ r\left ( x\right ) & =\left ( \frac{T_{2}-T_{1}}{L}\right ) x+T_{1}=x+20\\ a_{n}\left ( 0\right ) & =\frac{2}{L}\int _{0}^{L}\left ( f\left ( x\right ) -r\left ( x\right ) \right ) \Phi _{n}\left ( x\right ) dx=\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\\ q_{n}\left ( t\right ) & =\frac{2}{L}\int _{0}^{L}Q\left ( x,t\right ) \Phi _{n}\left ( x\right ) dx\\ & =\frac{2}{30}\int _{0}^{30}\frac{x}{10}e^{-t}\sin \left ( \frac{n\pi }{30}x\right ) dx\\ & =\frac{2}{300}e^{-t}\int _{0}^{30}x\sin \left ( \frac{n\pi }{30}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 ) e^{-\frac{1}{10}\left ( \frac{n\pi }{30}\right ) ^{2}t}+e^{-\frac{1}{10}\left ( \frac{n\pi }{30}\right ) ^{2}t}\int _{0}^{t}q_{n}\left ( \tau \right ) e^{\frac{1}{10}\left ( \frac{n\pi }{30}\right ) ^{2}t}d\tau \end{align*}

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

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