1.2.3 Both ends at zero temperature. 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 ) & =0\qquad t>0\\ u\left ( L,t\right ) & =0\qquad t>0 \end{align*}

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

Since the boundary conditions are already homogeneous, but there is a source, eigenfunction expansion method is used. Let the solution be\begin{equation} u\left ( x,t\right ) =\sum _{n}^{\infty }a_{n}\left ( t\right ) \Phi _{n}\left ( x\right ) \tag{1A} \end{equation} Where \(\Phi _{n}\left ( x\right ) \) are the eigenfunctions of the corresponding PDE \(u_{t}=ku_{xx}\) with homogeneous conditions. This was in solved above and found to be\[ \Phi _{n}\left ( x\right ) =\sin \left ( \sqrt{\lambda _{n}}x\right ) \] With the eigenvalues\[ \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 ) \] Therefore the original PDE can now be written as\[ \frac{\partial }{\partial t}\left ( \sum _{n=1}^{\infty }a_{n}\left ( t\right ) \Phi _{n}\left ( x\right ) \right ) =k\frac{\partial ^{2}}{\partial x^{2}}\left ( \sum _{n=1}^{\infty }a_{n}\left ( t\right ) \Phi _{n}\left ( x\right ) \right ) +Q\left ( x\right ) \] Expanding \(Q\left ( x\right ) \) using the same eigenfunctions (hence the name), and the above becomes\[ \frac{\partial }{\partial t}\left ( \sum _{n=1}^{\infty }a_{n}\left ( t\right ) \Phi _{n}\left ( x\right ) \right ) =k\frac{\partial ^{2}}{\partial x^{2}}\left ( \sum _{n=1}^{\infty }a_{n}\left ( t\right ) \Phi _{n}\left ( x\right ) \right ) +\sum _{n=1}^{\infty }q_{n}\Phi _{n}\left ( x\right ) \] The above simplifies to (term by term differentiation is justified here, since \(\Phi _{n}\left ( x\right ) \) satisfies the same homogeneous boundary conditions as \(u\left ( x,t\right ) \))\[ \sum _{n=1}^{\infty }a_{n}^{\prime }\left ( t\right ) \Phi _{n}\left ( x\right ) =k\sum _{n=1}^{\infty }a_{n}\left ( t\right ) \Phi _{n}^{\prime \prime }\left ( x\right ) +\sum _{n=1}^{\infty }q_{n}\Phi _{n}\left ( x\right ) \] But \(\Phi _{n}^{\prime \prime }\left ( x\right ) =-\lambda _{n}\Phi _{n}\left ( x\right ) \), since the eigenfunction satisfies the original ODE \(X_{n}^{\prime \prime }\left ( x\right ) +\lambda _{n}X\left ( x\right ) =0\), therefore the above simplifies to\[ \sum _{n=1}^{\infty }a_{n}^{\prime }\left ( t\right ) \Phi _{n}\left ( x\right ) =-k\sum _{n=1}^{\infty }a_{n}\left ( t\right ) \lambda _{n}\Phi _{n}\left ( x\right ) +\sum _{n=1}^{\infty }q_{n}\Phi _{n}\left ( x\right ) \] Or simply \begin{align} a_{n}^{\prime }\left ( t\right ) & =-k\lambda _{n}a_{n}\left ( t\right ) +q_{n}\nonumber \\ a_{n}^{\prime }\left ( t\right ) +k\lambda _{n}a_{n}\left ( t\right ) & =q_{n} \tag{2} \end{align}

This is a first order ODE to solve for \(a_{n}\left ( t\right ) \). First \(q_{n}\) is found by orthogonality. Since \[ Q\left ( x\right ) =\sum _{n=1}^{\infty }q_{n}\Phi _{n}\left ( x\right ) \] Then by orthogonality of eigenfunctions\begin{align*} \int _{0}^{L}Q\left ( x\right ) \Phi _{m}\left ( x\right ) dx & =\int _{0}^{L}\sum _{n=1}^{\infty }q_{n}\Phi _{n}\left ( x\right ) \Phi _{m}\left ( x\right ) dx\\ \int _{0}^{L}Q\left ( x\right ) \Phi _{m}\left ( x\right ) dx & =\int _{0}^{L}q_{n}\Phi _{m}^{2}\left ( x\right ) dx \end{align*}

Since \(\Phi _{m}\left ( x\right ) =\sin \left ( \sqrt{\lambda _{m}}x\right ) =\sin \left ( \frac{m\pi }{L}x\right ) \) in this case (due to the nature of boundary conditions) then \(\int _{0}^{L}\sin ^{2}\left ( \frac{m\pi }{L}x\right ) dx=\frac{L}{2}\) and the above simplifies to\begin{align*} \int _{0}^{L}Q\left ( x\right ) \Phi _{m}\left ( x\right ) dx & =q_{m}\frac{L}{2}\\ q_{n} & =\frac{2}{L}\int _{0}^{L}Q\left ( x\right ) \Phi _{n}\left ( x\right ) dx \end{align*}

Using the above in (2) gives\[ a_{n}^{\prime }\left ( t\right ) +k\lambda _{n}a_{n}\left ( t\right ) =q_{n}\] This ODE can now be solved. It solution will be\begin{align*} a_{n}\left ( t\right ) & =a_{n}\left ( 0\right ) e^{-k\lambda _{n}t}+e^{-k\lambda _{n}t}q_{n}\int _{0}^{t}e^{k\lambda _{n}\tau }d\tau \\ & =a_{n}\left ( 0\right ) e^{-k\lambda _{n}t}+\frac{q_{n}}{k\lambda _{n}}e^{-k\lambda _{n}t}\left ( e^{k\lambda _{n}t}-1\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} \end{align*}

To find \(a_{n}\left ( 0\right ) \), initial conditions are used. At \(t=0\) the above becomes\[ f\left ( x\right ) =\sum _{n}^{\infty }a_{n}\left ( 0\right ) \Phi _{n}\left ( x\right ) \] By orthogonality\begin{align*} a_{n}\left ( 0\right ) & =\frac{\int _{0}^{L}f\left ( x\right ) \Phi _{n}\left ( x\right ) dx}{\int _{0}^{L}\Phi _{n}^{2}\left ( x\right ) dx}\\ & =\frac{2}{L}\int _{0}^{L}f\left ( x\right ) \Phi _{n}\left ( x\right ) dx \end{align*}

This completes the solution.

Summary of solution     

\begin{align*} u\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}f\left ( x\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

Let \(Q\left ( x\right ) =x,L=1\) meter, let \(k\) which is the Thermal diffusivity be \(\frac{1}{100}\) \(\frac{m^{2}}{\sec }\)and let the initial conditions \(f\left ( x\right ) =x\left ( 1-x\right ) .\)

hence the PDE to solve is\begin{equation} u_{t}=\frac{1}{100}u_{xx}+x \tag{1} \end{equation} BC are\begin{align*} u\left ( 0,t\right ) & =0\qquad t>0\\ u\left ( 1,t\right ) & =0\qquad t>0 \end{align*}

Initial conditions\[ u\left ( x,0\right ) =x\left ( 1-x\right ) \qquad 0<x<1 \] Hence the final solution is from above is\begin{align*} u\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 ( n\pi \right ) ^{2}\qquad n=1,2,3,\cdots \\ q_{n} & =\frac{2}{L}\int _{0}^{L}x\Phi _{n}\left ( x\right ) dx\\ a_{n}\left ( 0\right ) & =\frac{2}{L}\int _{0}^{L}x\left ( 1-x\right ) \Phi _{n}\left ( x\right ) dx\\ 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} \end{align*}

The solution above was verified by comparing it to numerical solution. The animation is run for 3 seconds. This animation for \(Q\left ( x\right ) =x\)

This animation below is when \(Q\left ( x\right ) =\sin \left ( 10x\right ) \).

\begin{align*} u\left ( x,t\right ) & =\sum _{n=1}^{\infty }a_{n}\left ( t\right ) \sin \left ( \sqrt{\lambda _{n}}x\right ) \\ \lambda _{n} & =\left ( n\pi \right ) ^{2}\qquad n=1,2,3,\cdots \\ q_{n} & =\frac{2}{L}\int _{0}^{L}\sin \left ( 10x\right ) \sin \left ( \sqrt{\lambda _{n}}x\right ) dx\\ a_{n}\left ( 0\right ) & =\frac{2}{L}\int _{0}^{L}x\left ( 1-x\right ) \sin \left ( \sqrt{\lambda _{n}}x\right ) dx\\ 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} \end{align*}

Code used to the above, including a Manipulate to compare with the numerical solution is below. To use difference source term, just change the source line and revaluate the code.