#### 1.2.5 Left end at ﬁxed temperature, right end zero temperature. Source term depends on $$x$$ and $$t$$.

\begin{align*} \frac{\partial u}{\partial t} & =\frac{\partial ^{2}u}{\partial x^{2}}+\sin \left ( 5x\right ) e^{-2t}\qquad 0<x<\pi ,t>0\\ u\left ( 0,t\right ) & =1\\ u\left ( \pi ,t\right ) & =0\\ u\left ( x,0\right ) & =0 \end{align*}

Solution

This problem has nonhomogeneous B.C. and non-homogenous in the PDE itself (source present). First step is to use reference function to remove the nonhomogeneous B.C. then use the method of eigenfunction expansion on the resulting problem.

Let $r\left ( x\right ) =c_{1}x+c_{2}$ At $$x=0,r\left ( x\right ) =1$$, hence $$1=c_{2}$$ and at $$x=\pi ,r\left ( x\right ) =0$$, hence $$0=c_{1}\pi +1$$ or $$c_{1}=-\frac{1}{\pi }$$, hence$\fbox{r\left ( x\right ) =1-\frac{x}{\pi }}$ Therefore$u\left ( x,t\right ) =v\left ( x,t\right ) +r\left ( x\right )$ Where $$v\left ( x,t\right )$$ solution for the given PDE but with homogeneous B.C., therefore \begin{align} \frac{\partial v\left ( x,t\right ) }{\partial t} & =\frac{\partial ^{2}v\left ( x,t\right ) }{\partial x^{2}}+e^{-2t}\sin 5x\tag{1}\\ v\left ( 0,t\right ) & =0\nonumber \\ v\left ( \pi ,t\right ) & =0\nonumber \\ v\left ( x,0\right ) & =u\left ( x,0\right ) -r\left ( x\right ) =0-\left ( 1-\frac{x}{\pi }\right ) =\frac{x}{\pi }-1\nonumber \end{align}

We now solve (1). This is homogeneous in the PDE itself. To solve, we ﬁrst solve the nonhomogeneous PDE in order to ﬁnd the eigenfunctions.

Hence we need to solve$\frac{\partial v\left ( x,t\right ) }{\partial t}=\frac{\partial ^{2}v\left ( x,t\right ) }{\partial x^{2}}$ This has solution$$v\left ( x,t\right ) =\sum _{n=1}^{\infty }a_{n}\left ( t\right ) \phi _{n}\left ( x\right ) \tag{2}$$ With\begin{align*} \phi _{n}\left ( x\right ) & =\sin \left ( \sqrt{\lambda _{n}}x\right ) \qquad n=1,2,3\cdots \\ \lambda _{n} & =n^{2}\qquad n=1,2,3\cdots \end{align*}

Plug-in (2) back into (1) gives\begin{align*} \sum _{n=1}^{\infty }a_{n}^{\prime }\left ( t\right ) \phi _{n}\left ( x\right ) & =\sum _{n=1}^{\infty }a_{n}\left ( t\right ) \phi _{n}\left ( x\right ) +e^{-2t}\sin 5x\\ & =\sum _{n=1}^{\infty }a_{n}\left ( t\right ) \frac{\partial ^{2}}{\partial x^{2}}\phi _{n}\left ( x\right ) +e^{-2t}\sin 5x \end{align*}

But $$\frac{\partial ^{2}}{\partial x^{2}}\phi _{n}\left ( x\right ) =-\lambda _{n}\phi _{n}=-n\phi _{n}$$, hence the above becomes\begin{align*} \sum _{n=1}^{\infty }a_{n}^{\prime }\left ( t\right ) \phi _{n}\left ( x\right ) +n^{2}a_{n}\left ( t\right ) \phi _{n}\left ( x\right ) & =e^{-2t}\sin 5x\\ \sum _{n=1}^{\infty }\left ( a_{n}^{\prime }\left ( t\right ) +n^{2}a_{n}\left ( t\right ) \right ) \sin \left ( nx\right ) & =e^{-2t}\sin 5x \end{align*}

Therefore, since Fourier series expansion is unique, we can compare coeﬃcients and obtain$a_{n}^{\prime }\left ( t\right ) +n^{2}a_{n}\left ( t\right ) =\left \{ \begin{array} [c]{ccc}e^{-2t} & & n=5\\ 0 & & n\neq 5 \end{array} \right .$ For the case $$n=5$$\begin{align*} a_{5}^{\prime }\left ( t\right ) +25a_{5}\left ( t\right ) & =e^{-2t}\\ \frac{d}{dt}\left ( a_{5}\left ( t\right ) e^{25t}\right ) & =e^{23t}\\ a_{5}\left ( t\right ) e^{25t} & =\int e^{23t}dt+c\\ & =\frac{e^{23t}}{23}+c \end{align*}

Hence$a_{5}\left ( t\right ) =\frac{e^{-2t}}{23}+ce^{-25t}$ At $$t=0,$$ $$a_{5}\left ( 0\right ) =\frac{1}{23}+c$$, hence$c=a_{5}\left ( 0\right ) -\frac{1}{23}$ And the solution becomes$a_{5}\left ( t\right ) =\frac{1}{23}e^{-2t}+\left ( a_{5}\left ( 0\right ) -\frac{1}{23}\right ) e^{-25t}$ For the case $$n\neq 5$$\begin{align*} a_{n}^{\prime }\left ( t\right ) +n^{2}a_{n}\left ( t\right ) & =0\\ \frac{d}{dt}\left ( a_{n}\left ( t\right ) e^{n^{2}t}\right ) & =0\\ a_{n}\left ( t\right ) e^{n^{2}t} & =c\\ a_{n}\left ( t\right ) & =ce^{-n^{2}t} \end{align*}

At $$t=0,$$ $$a_{n}\left ( 0\right ) =c$$, hence$a_{n}\left ( t\right ) =a_{n}\left ( 0\right ) e^{-nt}$ Therefore$a_{n}\left ( t\right ) =\left \{ \begin{array} [c]{ccc}\frac{1}{23}e^{-2t}+\left ( a_{5}\left ( 0\right ) -\frac{1}{23}\right ) e^{-25t} & & n=5\\ a_{n}\left ( 0\right ) e^{-n^{2}t} & & n\neq 5 \end{array} \right .$ To ﬁnd $$a_{n}\left ( 0\right )$$ we use orthogonality.  Since $$u\left ( x,t\right ) =v\left ( x,t\right ) +r\left ( x\right )$$, then$u\left ( x,t\right ) =\left ( \sum _{n=1}^{\infty }a_{n}\left ( t\right ) \sin \left ( nx\right ) \right ) +\left ( 1-\frac{x}{\pi }\right )$ And at $$t=0$$ the above becomes$0=\left ( \sum _{n=1}^{\infty }a_{n}\left ( 0\right ) \sin \left ( nx\right ) \right ) +\left ( 1-\frac{x}{\pi }\right )$ Or$\frac{x}{\pi }-1=\sum _{n=1}^{\infty }a_{n}\left ( 0\right ) \sin \left ( nx\right )$

Applying orthogonality

$\int _{0}^{\pi }\left ( \frac{x}{\pi }-1\right ) \sin \left ( n^{\prime }x\right ) dx=a_{n^{\prime }}\left ( 0\right ) \int _{0}^{\pi }\sin ^{2}\left ( n^{\prime }x\right ) dx$ Therefore\begin{align*} a_{n}\left ( 0\right ) & =\frac{\int _{0}^{\pi }\left ( \frac{x}{\pi }-1\right ) \sin \left ( nx\right ) dx}{\frac{\pi }{2}}\\ & =\frac{2}{\pi }\int _{0}^{\pi }\left ( \frac{x}{\pi }-1\right ) \sin \left ( nx\right ) dx\\ & =\frac{2}{\pi }\left [ -\int _{0}^{\pi }\sin \left ( nx\right ) dx+\frac{1}{\pi }\int _{0}^{\pi }x\sin \left ( nx\right ) dx\right ] \\ & =\frac{2}{\pi }\left [ -\left ( \frac{-\cos \left ( nx\right ) }{n}\right ) _{0}^{\pi }+\frac{1}{\pi }\left ( \frac{\sin \left ( nx\right ) }{n^{2}}-\frac{x\cos \left ( nx\right ) }{n}\right ) _{0}^{\pi }\right ] \\ & =\frac{2}{\pi }\left [ \left ( \frac{\cos \left ( n\pi \right ) }{n}-\frac{1}{n}\right ) +\frac{1}{\pi }\left ( \left ( \frac{\sin \left ( n\pi \right ) }{n^{2}}-\frac{\pi \cos \left ( n\pi \right ) }{n}\right ) -\left ( \frac{\sin \left ( 0\right ) }{n^{2}}-\frac{0\cos \left ( 0\right ) }{n}\right ) \right ) \right ] \\ & =\frac{2}{\pi }\left [ \left ( \frac{-1^{n}}{n}-\frac{1}{n}\right ) +\frac{1}{\pi }\left ( 0-\frac{\pi \left ( -1\right ) ^{n}}{n}\right ) \right ] \\ & =\frac{2}{\pi }\left [ \frac{\left ( -1\right ) ^{n}}{n}-\frac{1}{n}-\frac{\left ( -1\right ) ^{n}}{n}\right ] \\ & =\frac{-2}{n\pi } \end{align*}

Therefore $$a_{5}\left ( 0\right ) =\frac{-2}{5\pi }$$. Hence$a_{n}\left ( t\right ) =\left \{ \begin{array} [c]{ccc}\frac{1}{23}e^{-2t}+\left ( \frac{-2}{5\pi }-\frac{1}{23}\right ) e^{-25t} & & n=5\\ \frac{-2}{n\pi }e^{-n^{2}t} & & n\neq 5 \end{array} \right .$ Where \begin{align*} u\left ( x,t\right ) & =v\left ( x,t\right ) +r\left ( x\right ) \\ & =\left ( \sum _{n=1}^{\infty }a_{n}\left ( t\right ) \sin \left ( nx\right ) \right ) +\left ( 1-\frac{x}{\pi }\right ) \end{align*}

Example

For 3 seconds

Source code