1.2.6 Both ends at fixed temperature (not time dependent). Source term depends on x only

\begin{equation} u_{t}=ku_{xx}+Q\left ( x\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\right ) \) gives\begin{align} w_{t} & =kw_{xx}+Q\left ( x\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\) only.) 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\begin{align} w\left ( x,t\right ) & =\sum _{n=1}^{\infty }a_{n}\left ( t\right ) \Phi _{n}\left ( x\right ) \tag{3A}\\ \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 \\ a_{n}\left ( t\right ) & =a_{n}\left ( 0\right ) e^{-k\lambda _{n}t}+\frac{q_{n}}{k\lambda _{n}}-\frac{q_{n}}{k\lambda _{n}}e^{-k\lambda _{n}t}\nonumber \\ 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\nonumber \\ q_{n} & =\frac{2}{L}\int _{0}^{L}Q\left ( x\right ) \Phi _{n}\left ( x\right ) dx\nonumber \end{align}

The above solution 3A is the same as the earlier solution, except of the use of \(f\left ( x\right ) -r\left ( x\right ) \) instead of just \(f\left ( x\right ) \). Now that \(w\left ( x,t\right ) \) is found, the solution from (2) becomes\begin{align*} u\left ( x,t\right ) & =w\left ( x,t\right ) +r\left ( x\right ) \\ & =\left ( \sum _{n=1}^{\infty }a_{n}\left ( t\right ) \Phi _{n}\left ( x\right ) \right ) +r\left ( x\right ) \end{align*}

This completes the solution.

Summary of solution\begin{align*} u\left ( x,t\right ) & =w\left ( x,t\right ) +r\left ( x\right ) \\ r\left ( x\right ) & =\left ( \frac{T_{2}-T_{1}}{L}\right ) x+T_{1}\\ 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 \\ a_{n}\left ( t\right ) & =a_{n}\left ( 0\right ) e^{-k\lambda _{n}t}+\frac{q_{n}}{k\lambda _{n}}-\frac{q_{n}}{k\lambda _{n}}e^{-k\lambda _{n}t}\\ 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\\ q_{n} & =\frac{2}{L}\int _{0}^{L}Q\left ( x\right ) \Phi _{n}\left ( x\right ) dx \end{align*}

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\right ) & =\frac{x}{10} \end{align*}

Hence the solution is

\begin{align*} u\left ( x,t\right ) & =w\left ( x,t\right ) +r\left ( x\right ) \\ r\left ( x\right ) & =\left ( \frac{T_{2}-T_{1}}{L}\right ) x+T_{1}\\ & =x+20\\ 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 }{30}\right ) ^{2}\qquad n=1,2,3,\cdots \\ a_{n}\left ( t\right ) & =a_{n}\left ( 0\right ) e^{-\frac{1}{10}\left ( \frac{n\pi }{30}\right ) ^{2}t}+\frac{q_{n}}{\frac{1}{10}\left ( \frac{n\pi }{30}\right ) ^{2}}-\frac{q_{n}}{\frac{1}{10}\left ( \frac{n\pi }{30}\right ) ^{2}}e^{-\left ( \frac{n\pi }{30}\right ) ^{2}t}\\ a_{n}\left ( 0\right ) & =\frac{2}{30}\int _{0}^{30}\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\\ & =\frac{20}{n\pi }\left ( 4+5\left ( -1\right ) ^{n}\right ) \\ q_{n} & =\frac{2}{30}\int _{0}^{30}\frac{x}{10}\Phi _{n}\left ( x\right ) dx\\ & =\frac{2}{30}\int _{0}^{30}\frac{x}{10}\sin \left ( \frac{n\pi }{30}x\right ) dx \end{align*}

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

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