1.2.4 Both ends at zero temperature. Source term depends on \(x\) and \(t\)

   1.2.4.1 Example 1
   1.2.4.2 Example 2

\begin{equation} u_{t}=ku_{xx}+Q\left ( x,t\right ) \tag{1} \end{equation} Where now \(Q\left ( x,t\right ) \) depends on time as well. For example, \(Q\left ( x,t\right ) =e^{-t}\sin \left ( 3x\right ) \)

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.

\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 cases above 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 \] 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,t\right ) \] Expanding \(Q\left ( x,t\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}\left ( t\right ) \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}\left ( t\right ) \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}\left ( t\right ) \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}\left ( t\right ) \nonumber \\ a_{n}^{\prime }\left ( t\right ) +k\lambda _{n}a_{n}\left ( t\right ) & =q_{n}\left ( t\right ) \tag{2} \end{align}

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

Where \(\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}\Phi _{m}^{2}\left ( x\right ) dx=\frac{L}{2}\) and the above simplifies to\begin{align*} \int _{0}^{L}Q\left ( x,t\right ) \Phi _{m}\left ( x\right ) dx & =q_{m}\left ( t\right ) \frac{L}{2}\\ q_{n}\left ( t\right ) & =\frac{2}{L}\int _{0}^{L}Q\left ( x,t\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 ) =\frac{2}{L}\int _{0}^{L}Q\left ( x,t\right ) \Phi _{n}\left ( x\right ) dx \] This ODE can now be solved for \(a_{n}\left ( t\right ) \) using an integrating factor\[ 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 \] Therefore the solution is, from (1A) becomes\[ u\left ( x,t\right ) =\sum _{n}^{\infty }a_{n}\left ( t\right ) \Phi _{n}\left ( x\right ) \] 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 \\ 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}f\left ( x\right ) \Phi _{n}\left ( x\right ) dx \end{align*}

1.2.4.1 Example 1

This example was solved also numerically to verify the above result. Let \begin{align*} L & =\pi \text{ meter}\\ k & =\frac{1}{300}\frac{m^{2}}{\sec }\\ Q\left ( x,t\right ) & =e^{-t}\sin \left ( 3x\right ) \\ u\left ( x,0\right ) & =f\left ( x\right ) =x\left ( \pi -x\right ) \end{align*}

From above, the analytical solution is

\begin{align*} u\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}\\ & =n^{2}\qquad n=1,2,3,\cdots \\ \Phi _{n}\left ( x\right ) & =\sin \left ( \sqrt{\lambda _{n}}x\right ) \\ & =\sin \left ( nx\right ) \qquad n=1,2,3,\cdots \\ q_{n}\left ( t\right ) & =\frac{2}{\pi }e^{-t}\int _{0}^{\pi }\sin \left ( 3x\right ) \sin \left ( nx\right ) dx\\ a_{n}\left ( t\right ) & =a_{n}\left ( 0\right ) e^{-kn^{2}t}+e^{-kn^{2}t}\int _{0}^{t}q_{n}\left ( \tau \right ) e^{kn^{2}\tau }d\tau \\ a_{n}\left ( 0\right ) & =\frac{2}{n^{2}}\int _{0}^{\pi }x\left ( \pi -x\right ) \Phi _{n}\left ( x\right ) dx\\ & =\frac{2}{n^{2}}\int _{0}^{\pi }x\left ( \pi -x\right ) \sin \left ( nx\right ) dx \end{align*}

Hence\begin{align*} 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}{300}n^{2}t}+e^{-\frac{1}{300}n^{2}t}\int _{0}^{t}q_{n}\left ( \tau \right ) e^{-\frac{1}{3}n^{2}\tau }d\tau \end{align*}

For \(n\neq 3\)\[ a_{n}\left ( t\right ) =a_{n}\left ( 0\right ) e^{-\frac{1}{300}n^{2}t}\] For \(n=3\)\begin{align*} a_{n}\left ( t\right ) & =a_{n}\left ( 0\right ) e^{-\frac{1}{300}n^{2}t}+e^{-\frac{1}{300}n^{2}t}\int _{0}^{t}e^{-\tau }e^{-\frac{1}{300}n^{2}\tau }d\tau \\ a_{3}\left ( t\right ) & =a_{3}\left ( 0\right ) e^{-\frac{9}{300}t}+e^{-\frac{1}{300}n^{2}t}\int _{0}^{t}e^{-\tau }e^{-\frac{9}{300}\tau }d\tau \end{align*}

But \(a_{3}\left ( 0\right ) =\frac{-4\left ( -1+\left ( -1\right ) ^{3}\right ) }{27\pi }=\frac{8}{27\pi }\). Hence the above simplifies to\[ a_{3}\left ( t\right ) =-\frac{100}{97}e^{-t}+\frac{100}{97}e^{\frac{-3t}{100}}+\frac{8}{27\pi }e^{\frac{-3t}{100}}\] Therefore\[ a_{n}\left ( t\right ) =\left \{ \begin{array} [c]{cc}\frac{-4\left ( -1+\left ( -1\right ) ^{n}\right ) }{\pi n^{3}}e^{-\frac{1}{3}n^{2}t} & n\neq 3\\ -\frac{100}{97}e^{-t}+\frac{100}{97}e^{\frac{-3t}{100}}+\frac{8}{27\pi }e^{\frac{-3t}{100}} & n=3 \end{array} \right . \] Therefore the full solution is\begin{align*} u\left ( x,t\right ) & =\sum _{n=1}^{\infty }a_{n}\left ( t\right ) \sin \left ( \sqrt{\lambda _{n}}x\right ) \\ & =\left [ \sum _{\substack{n=1\\n\neq 3}}^{\infty }\frac{-4\left ( -1+\left ( -1\right ) ^{n}\right ) }{\pi n^{3}}e^{-\frac{1}{3}n^{2}t}\sin \left ( nx\right ) \right ] +\left ( -\frac{100}{97}e^{-t}+\frac{100}{97}e^{\frac{-3t}{100}}+\frac{8}{27\pi }e^{\frac{-3t}{100}}\right ) \sin \left ( 3x\right ) \end{align*}

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

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

1.2.4.2 Example 2

This example was solved also numerically to verify the above result. Let \(L=\pi ,k=\frac{1}{300},Q\left ( x,t\right ) =xe^{-t},f\left ( x\right ) =x\left ( \pi -x\right ) \). Therefore, from above the solution is\begin{align*} u\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}\\ & =n^{2}\qquad n=1,2,3,\cdots \\ \Phi _{n}\left ( x\right ) & =\sin \left ( \sqrt{\lambda _{n}}x\right ) \\ & =\sin \left ( nx\right ) \qquad n=1,2,3,\cdots \\ q_{n}\left ( t\right ) & =\frac{2}{\pi }e^{-t}\int _{0}^{\pi }x\sin \left ( nx\right ) dx\\ a_{n}\left ( t\right ) & =a_{n}\left ( 0\right ) e^{-kn^{2}t}+e^{-kn^{2}t}\int _{0}^{t}q_{n}\left ( \tau \right ) e^{kn^{2}\tau }d\tau \\ a_{n}\left ( 0\right ) & =\frac{2}{n^{2}}\int _{0}^{\pi }x\left ( \pi -x\right ) \Phi _{n}\left ( x\right ) dx\\ & =\frac{2}{n^{2}}\int _{0}^{\pi }x\left ( \pi -x\right ) \sin \left ( nx\right ) dx \end{align*}

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

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