4.1.5 Finite domain (bar), Both ends nonhomogeneous BC

4.1.5.1 [216] both ends non-homogeneous BC (general case)
4.1.5.2 [217] non-homogeneous BC (special case)
4.1.5.3 [218] Articolo 8.4.1 (special case)
4.1.5.4 [219] With source that depends on space only (general case)
4.1.5.5 [220] With source that depends on space only (special case)
4.1.5.6 [221] With source that depends on space and time only (general case)
4.1.5.7 [222] Both ends depend on time (general case)
4.1.5.8 [223] Both ends depend on time (special case)
4.1.5.9 [224] both ends nonhomogeneous
4.1.5.10 [225] Haberman 8.2.1 (a) (general case)
4.1.5.11 [226] Haberman 8.2.1 (d) (general solution)
4.1.5.12 [227] Both ends depend on time with source that depends on space only (general solution)
4.1.5.13 [228] Both ends depend on time with source that depends on space only (special case)
4.1.5.14 [229] Both ends depend on time with source that depends on time and space (general solution)
4.1.5.15 [230] Both ends depend on time with source present (special case)
4.1.5.16 [231] Pinchover and Rubinstein 6.17
4.1.5.17 [232] nonhomogeneous BC
4.1.5.18 [233] Haberman 8.2.2. (a)
4.1.5.19 [234] Articolo 8.4.3

4.1.5.1 [216] both ends non-homogeneous BC (general case)

problem number 216

Added June 22, 2019

Solve the heat equation \[ u_t = k u_{xx} \] For \(0<x<L\) and \(t>0\). The boundary conditions are \begin {align*} u(0,t) &= A \\ u(L,t) &= B \end {align*}

Initial condition is \(u(x,0)=f(x)\)

Mathematica

ClearAll["Global`*"]; 
pde =  D[u[x, t], t] == k*D[u[x, t], {x, 2}]; 
bc  = {u[0, t] == A, u[L, t] == B}; 
ic  = u[x, 0] == f[x]; 
sol =  AbsoluteTiming[TimeConstrained[DSolve[{pde, ic, bc}, u[x, t], {x, t},Assumptions->{k>0,L>0,t>0}], 60*10]]; 
sol =  sol /. K[1] -> n;
 

\[\left \{\left \{u(x,t)\to \sum _{n=1}^\infty \frac {2 e^{-\frac {k n^2 \pi ^2 t}{L^2}} \left (\int _0^L \left (-A+\frac {(A-B) x}{L}+f(x)\right ) \sin \left (\frac {n \pi x}{L}\right ) \, dx\right ) \sin \left (\frac {n \pi x}{L}\right )}{L}+\frac {x (B-A)}{L}+A\right \}\right \}\]

Maple

restart; 
pde :=  diff(u(x,t),t)=k*diff(u(x,t),x$2); 
ic  :=  u(x,0)=f(x); 
bc  :=  u(0,t)=A, u(L,t)=B; 
cpu_time := timelimit(60*10,CodeTools[Usage](assign('sol',pdsolve([pde,ic,bc],u(x,t)) assuming k>0,L>0,t>0),output='realtime'));
 

\[u \left (x , t\right ) = \frac {A L -2 L \left (\sum _{n=1}^\infty \frac {\left (\int _{0}^{L}\left (B x -L f \left (x \right )+\left (L -x \right ) A \right ) \sin \left (\frac {\pi n x}{L}\right )d x \right ) {\mathrm e}^{-\frac {\pi ^{2} k \,n^{2} t}{L^{2}}} \sin \left (\frac {\pi n x}{L}\right )}{L^{2}}\right )-\left (A -B \right ) x}{L}\]

Hand solution

Solve\begin {equation} u_{t}=ku_{xx}\qquad t>0,0<x<L \tag {1} \end {equation} BC are\begin {align*} u\left ( 0,t\right ) & =A\\ u\left ( L,t\right ) & =B \end {align*}

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

Since boundary conditions are nonhomogeneous, then the first step is to reduce the problem to one with homogeneous B.C. to be able to use separation of variables (separation of variables can only be done on a PDE with homogeneous B.C.)

This is done by using steady state solution. Let the total solution be\begin {equation} u\left ( x,t\right ) =v\left ( x,t\right ) +r\left ( x\right ) \tag {2} \end {equation} Where \(v\left ( x,t\right ) \) is the transient solution which satisfies homogeneous version of the 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 ) & =A\\ r\left ( L\right ) & =B \end {align*}

This has the solution \(r\left ( x\right ) =c_{1}x+c_{2}\). Using BC at \(x=0\) leads to \(A=c_{2}\). Therefore the solution is \(r\left ( x\right ) =c_{1}x+A\). Using BC at \(x=L\) gives \(B=c_{1}L+A\) or \(c_{1}=\frac {B-A}{L}\). Hence\[ r\left ( x\right ) =\left ( \frac {B-A}{L}\right ) x+A \] Therefore (1) becomes\[ u\left ( x,t\right ) =v\left ( x,t\right ) +\left ( \frac {B-A}{L}\right ) x+A \] Substituting the above back in the original PDE \(u_{t}=ku_{xx}\) gives\begin {align} v_{t} & =kv_{xx}\nonumber \\ v\left ( 0\right ) & =0\nonumber \\ v\left ( L\right ) & =0\nonumber \\ v\left ( x,0\right ) & =F\left ( x\right ) \nonumber \\ & =u\left ( x,0\right ) -r\left ( x\right ) \nonumber \\ & =f\left ( x\right ) -\left ( \frac {B-A}{L}x+A\right ) \tag {3} \end {align}

The above PDE was solved in problem 4.1.1.1 on page 405 and the solution is\begin {align} v\left ( x,t\right ) & =\sum _{n=1}^{\infty }\left ( \frac {2}{L}\int _{0}^{L}F\left ( s\right ) \sin \left ( \sqrt {\lambda _{n}}s\right ) ds\right ) e^{-k\lambda _{n}t}\sin \left ( \sqrt {\lambda _{n}}x\right ) \tag {4}\\ \lambda _{n} & =\left ( \frac {n\pi }{L}\right ) ^{2}\qquad n=1,2,3,\cdots \nonumber \end {align}

Substituting (3) into (4) gives\[ v\left ( x,t\right ) =\frac {2}{L}\sum _{n=1}^{\infty }\left ( \int _{0}^{L}\left ( f\left ( s\right ) -\left ( \frac {B-A}{L}s+A\right ) \right ) \sin \left ( \sqrt {\lambda _{n}}s\right ) ds\right ) e^{-k\lambda _{n}t}\sin \left ( \sqrt {\lambda _{n}}x\right ) \] From (2)\begin {align*} u\left ( x,t\right ) & =v\left ( x,t\right ) +r\left ( x\right ) \\ & =A+\left ( \frac {B-A}{L}\right ) x+\frac {2}{L}\sum _{n=1}^{\infty }\left ( \int _{0}^{L}\left ( f\left ( s\right ) -\left ( \frac {B-A}{L}s+A\right ) \right ) \sin \left ( \sqrt {\lambda _{n}}s\right ) ds\right ) e^{-k\lambda _{n}t}\sin \left ( \sqrt {\lambda _{n}}x\right ) \\ & =A+\left ( \frac {B-A}{L}\right ) x+\frac {2}{L}\sum _{n=1}^{\infty }\left ( \int _{0}^{L}\left ( f\left ( s\right ) -\left ( \frac {B-A}{L}s+A\right ) \right ) \sin \left ( \frac {n\pi }{L}s\right ) ds\right ) e^{-k\left ( \frac {n\pi }{L}\right ) ^{2}t}\sin \left ( \frac {n\pi }{L}x\right ) \end {align*}

____________________________________________________________________________________

4.1.5.2 [217] non-homogeneous BC (special case)

problem number 217

Taken from Maple PDE help pages

Solve the heat equation \[ u_t = u_{xx} \] For \(0<x<1\) and \(t>0\). The boundary conditions are \begin {align*} u(0,t) &= 20 \\ u(1,t) &= 50 \end {align*}

Initial condition is \(u(x,0)=0\)

Mathematica

ClearAll["Global`*"]; 
pde =  D[u[x, t], t] == D[u[x, t], {x, 2}]; 
bc  = {u[0, t] == 20, u[1, t] == 50}; 
ic  = u[x, 0] == 0; 
sol =  AbsoluteTiming[TimeConstrained[DSolve[{pde, ic, bc}, u[x, t], x, t], 60*10]]; 
sol =  sol /. K[1] -> n;
 

\[\left \{\left \{u(x,t)\to -\frac {2 \sum _{n=1}^\infty \frac {\left (20-50 (-1)^n\right ) e^{-n^2 \pi ^2 t} \sin (n \pi x)}{n}}{\pi }+30 x+20\right \}\right \}\]

Maple

restart; 
pde :=  diff(u(x,t),t)=diff(u(x,t),x$2); 
ic  :=  u(x,0)=0; 
bc  :=  u(0,t)=20, u(1,t)=50; 
cpu_time := timelimit(60*10,CodeTools[Usage](assign('sol',pdsolve([pde,ic,bc],u(x,t))),output='realtime'));
 

\[u \left (x , t\right ) = 30 x +20 \left (\sum _{n=1}^\infty \frac {\left (5 \left (-1\right )^{n}-2\right ) {\mathrm e}^{-\pi ^{2} n^{2} t} \sin \left (\pi n x \right )}{\pi n}\right )+20\]

Hand solution

The general solution to \begin {equation} u_{t}=ku_{xx}\qquad t>0,0<x<L\tag {1} \end {equation} BC are\begin {align*} u\left ( 0,t\right ) & =A\\ u\left ( L,t\right ) & =B \end {align*}

Initial conditions\[ u\left ( x,0\right ) =f\left ( x\right ) \] Is given in problem 4.1.5.1 on page 698 as\[ u\left ( x,t\right ) =A+\left ( \frac {B-A}{L}\right ) x+\frac {2}{L}\sum _{n=1}^{\infty }\left ( \int _{0}^{L}\left ( f\left ( x\right ) -\left ( \frac {B-A}{L}x+A\right ) \right ) \sin \left ( \sqrt {\lambda _{n}}x\right ) dx\right ) e^{-k\lambda _{n}t}\sin \left ( \sqrt {\lambda _{n}}x\right ) \] Where \(\lambda _{n}=\left ( \frac {n\pi }{L}\right ) ^{2},n=1,2,3,\cdots \). Substituting \(A=20,B=50,L=1,k=1,f\left ( x\right ) =0\) gives the solution as\[ u\left ( x,t\right ) =20+30x+2\sum _{n=1}^{\infty }\left ( \int _{0}^{1}-\left ( 30x+20\right ) \sin \left ( n\pi x\right ) dx\right ) e^{-kn^{2}\pi ^{2}t}\sin \left ( n\pi x\right ) \] But \(\int _{0}^{1}-\left ( 30x+20\right ) \sin \left ( n\pi x\right ) dx=\frac {50\left ( -1\right ) ^{n}-20}{n\pi }\) and the above becomes\begin {align*} u\left ( x,t\right ) & =20+30x+2\sum _{n=1}^{\infty }\left ( \frac {50\left ( -1\right ) ^{n}-20}{n\pi }\right ) e^{-kn^{2}\pi ^{2}t}\sin \left ( n\pi x\right ) \\ & =20+30x+\sum _{n=1}^{\infty }\left ( \frac {100\left ( -1\right ) ^{n}-40}{n\pi }\right ) e^{-kn^{2}\pi ^{2}t}\sin \left ( n\pi x\right ) \end {align*}

____________________________________________________________________________________

4.1.5.3 [218] Articolo 8.4.1 (special case)

problem number 218

Added December 20, 2018.

Example 8.4.1 from Partial differential equations and boundary value problems with Maple by George A. Articolo, 2nd ed.

Solve the heat equation for \(u(x,t)\) \[ u_t= k u_{xx} \] For \(0<x<1\) and \(t>0\). The boundary conditions are \begin {align*} u(0,t)&=10 \\ u(1,t) &= 20\\ \end {align*}

Initial condition is \(u(x,0)=60 x - 50 x^2+10\) and \(k=\frac {1}{20}\)

Mathematica

ClearAll["Global`*"]; 
k = 1/20; 
pde =  D[u[x, t], t] == k*D[u[x, t], {x, 2}]; 
bc  = {u[0, t] == 10, u[1, t] == 20}; 
ic  = u[x, 0] == 60*x - 50*x^2 + 10; 
sol =  AbsoluteTiming[TimeConstrained[DSolve[{pde, ic, bc}, u[x, t], x, t], 60*10]]; 
sol =  sol /. K[1] -> n;
 

\[\left \{\left \{u(x,t)\to \sum _{n=1}^\infty -\frac {200 \left (-1+(-1)^n\right ) e^{-\frac {1}{20} n^2 \pi ^2 t} \sin (n \pi x)}{n^3 \pi ^3}+10 (x+1)\right \}\right \}\]

Maple

restart; 
k := 1/20; 
pde := diff(u(x,t),t)= k*diff(u(x,t),x$2); 
bc  := u(0, t) = 10, u(1, t) = 20; 
ic  := u(x, 0) = 60*x - 50*x^2 + 10; 
cpu_time := timelimit(60*10,CodeTools[Usage](assign('sol', pdsolve([pde, ic, bc], u(x, t))),output='realtime'));
 

\[u \left (x , t\right ) = 10 x -200 \left (\sum _{n=1}^\infty \frac {\left (\left (-1\right )^{n}-1\right ) {\mathrm e}^{-\frac {\pi ^{2} n^{2} t}{20}} \sin \left (\pi n x \right )}{\pi ^{3} n^{3}}\right )+10\]

Hand solution

The general solution to \begin {equation} u_{t}=ku_{xx}\qquad t>0,0<x<L\tag {1} \end {equation} BC are\begin {align*} u\left ( 0,t\right ) & =A\\ u\left ( L,t\right ) & =B \end {align*}

with Initial conditions\[ u\left ( x,0\right ) =f\left ( x\right ) \] Is given in problem 4.1.5.1 on page 698 as\[ u\left ( x,t\right ) =A+\left ( \frac {B-A}{L}\right ) x+\frac {2}{L}\sum _{n=1}^{\infty }\left ( \int _{0}^{L}\left ( f\left ( x\right ) -\left ( \frac {B-A}{L}x+A\right ) \right ) \sin \left ( \sqrt {\lambda _{n}}x\right ) dx\right ) e^{-k\lambda _{n}t}\sin \left ( \sqrt {\lambda _{n}}x\right ) \] Where \(\lambda _{n}=\left ( \frac {n\pi }{L}\right ) ^{2},n=1,2,3,\cdots \). Substituting \(A=10,B=20,L=1,k=\frac {1}{20},f\left ( x\right ) =60x-50x^{2}+10\) gives the solution as\begin {align*} u\left ( x,t\right ) & =10+10x+2\sum _{n=1}^{\infty }\left ( \int _{0}^{1}\left ( 60x-50x^{2}+10-\left ( 10x+10\right ) \right ) \sin \left ( n\pi xx\right ) dx\right ) e^{-\frac {1}{20}n^{2}\pi ^{2}t}\sin \left ( n\pi xx\right ) \\ & =10+10x+2\sum _{n=1}^{\infty }\left ( \int _{0}^{1}\left ( 50x-50x^{2}\right ) \sin \left ( n\pi xx\right ) dx\right ) e^{-\frac {1}{20}n^{2}\pi ^{2}t}\sin \left ( n\pi xx\right ) \end {align*}

But \(\int _{0}^{1}\left ( 50x-50x^{2}\right ) \sin \left ( n\pi xx\right ) dx=\frac {100-100\left ( -1\right ) ^{n}}{n^{3}\pi ^{3}}\) and the above becomes\begin {align*} u\left ( x,t\right ) & =10+10x+2\sum _{n=1}^{\infty }100\left ( \frac {1-\left ( -1\right ) ^{n}}{n^{3}\pi ^{3}}\right ) e^{-\frac {1}{20}n^{2}\pi ^{2}t}\sin \left ( n\pi xx\right ) \\ & =10+10x-\sum _{n=1}^{\infty }200\left ( \frac {\left ( -1\right ) ^{n}-1}{n^{3}\pi ^{3}}\right ) e^{-\frac {1}{20}n^{2}\pi ^{2}t}\sin \left ( n\pi xx\right ) \end {align*}

____________________________________________________________________________________

4.1.5.4 [219] With source that depends on space only (general case)

problem number 219

Added July 6,2019

Solve the heat equation for \(u(x,t)\) \[ u_t= k u_{xx} + Q(x) \] For \(0<x<L\) and \(t>0\). The boundary conditions are \begin {align*} u(0,t) &=A \\ u(1,t) &=B\\ \end {align*}

Initial condition is \(u(x,0)=f(x)\)

Mathematica

ClearAll["Global`*"]; 
pde =  D[u[x, t], t] == k*D[u[x, t], {x, 2}] + Q[x]; 
bc  = {u[0, t] == A, u[L, t] == B}; 
ic  = u[x, 0] == f[x]; 
sol =  AbsoluteTiming[TimeConstrained[DSolve[{pde, ic, bc}, u[x, t], {x, t},Assumptions->{k>0,L>0}], 60*10]];
 

\[\left \{\left \{u(x,t)\to \sum _{K[1]=1}^\infty \frac {\sqrt {2} \left (\frac {\left (1-e^{-\frac {k \pi ^2 t K[1]^2}{L^2}}\right ) \left (\int _0^L \frac {\sqrt {2} Q(x) \sin \left (\frac {\pi x K[1]}{L}\right )}{\sqrt {L}} \, dx\right ) L^2}{k \pi ^2 K[1]^2}+e^{-\frac {k \pi ^2 t K[1]^2}{L^2}} \int _0^L \frac {\sqrt {2} (-B x+A (x-L)+L f(x)) \sin \left (\frac {\pi x K[1]}{L}\right )}{L^{3/2}} \, dx\right ) \sin \left (\frac {\pi x K[1]}{L}\right )}{\sqrt {L}}+\frac {x (B-A)}{L}+A\right \}\right \}\]

Maple

restart; 
pde := diff(u(x,t),t)= k*diff(u(x,t),x$2)+Q(x); 
bc  := u(0, t) = A, u(L, t) = B; 
ic  := u(x, 0) = f(x); 
cpu_time := timelimit(60*10,CodeTools[Usage](assign('sol', pdsolve([pde, ic, bc], u(x, t)) assuming L>0,k>0),output='realtime'));
 

\[u \left (x , t\right ) = \frac {-2 L k \left (\sum _{n=1}^\infty \frac {\left (\int _{0}^{L}-\left (L \left (\int _{0}^{\textit {\_a}}\int _{0}^{\textit {\_z1}}Q \left (\textit {\_z1} \right )d \textit {\_z1} d \textit {\_z1} \right )-\textit {\_a} \left (\int _{0}^{L}\int _{0}^{\textit {\_z1}}Q \left (\textit {\_z1} \right )d \textit {\_z1} d \textit {\_z1} \right )+\left (-A L +L f \left (\textit {\_a} \right )+\left (A -B \right ) \textit {\_a} \right ) k \right ) \sin \left (\frac {\pi \textit {\_a} n}{L}\right )d \textit {\_a} \right ) {\mathrm e}^{-\frac {\pi ^{2} k \,n^{2} t}{L^{2}}} \sin \left (\frac {\pi n x}{L}\right )}{L^{2} k}\right )-L \left (\int _{0}^{x}\int _{0}^{\textit {\_a}}Q \left (\textit {\_a} \right )d \textit {\_a} d \textit {\_a} \right )+x \left (\int _{0}^{L}\int _{0}^{\textit {\_a}}Q \left (\textit {\_a} \right )d \textit {\_a} d \textit {\_a} \right )+\left (A L -\left (A -B \right ) x \right ) k}{L k}\]

Hand solution

Solving\begin {equation} u_{t}=ku_{xx}+Q\left ( x\right ) \tag {1} \end {equation} With initial conditions \(u\left ( x,0\right ) =f\left ( x\right ) \) and boundary conditions \(u\left ( 0,t\right ) =A,u\left ( L,t\right ) =B\) with \(0<x<L,t>0\)

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 ) =v\left ( x,t\right ) +r\left ( x\right ) \tag {2} \end {equation} Where \(v\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 ) & =A\\ r\left ( L\right ) & =B \end {align*}

This has the solution \(r\left ( x\right ) =c_{1}x+c_{2}\). Using BC at \(x=0\) leads to \(A=c_{2}\). Therefore the solution is \(r\left ( x\right ) =c_{1}x+A\). Using BC at \(x=L\) gives \(B=c_{1}L+A\) or \(c_{1}=\frac {B-A}{L}\). Hence\begin {equation} r\left ( x\right ) =\left ( \frac {B-A}{L}\right ) x+A\tag {3} \end {equation} Substituting (2) back in the original PDE \(u_{t}=ku_{xx}+Q\left ( x\right ) \) gives\begin {align} v_{t} & =kv_{xx}+Q\left ( x\right ) \tag {4}\\ v\left ( 0,t\right ) & =0\nonumber \\ v\left ( L,t\right ) & =0\nonumber \end {align}

The initial conditions are\begin {align*} v\left ( x,0\right ) & =F\left ( x\right ) \\ & =u\left ( x,0\right ) -r\left ( x\right ) \\ & =f\left ( x\right ) -\left ( \left ( \frac {B-A}{L}\right ) x+A\right ) \end {align*}

The general solution to (4) was solved in 4.1.1.11 on page 453 and the solution is\begin {align*} v\left ( x,t\right ) & =\sum _{n=1}^{\infty }e^{-k\lambda _{n}t}\Phi _{n}\left ( x\right ) \left ( \frac {2}{L}\int _{0}^{L}F\left ( s\right ) \Phi _{n}\left ( s\right ) ds\right ) +\sum _{n=1}^{\infty }e^{-k\lambda _{n}t}\Phi _{n}\left ( x\right ) \left ( \int _{0}^{t}\frac {2}{L}e^{k\lambda _{n}\tau }\left ( \int _{0}^{L}Q\left ( s\right ) \Phi _{n}\left ( s\right ) ds\right ) d\tau \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 \end {align*}

But \(F\left ( x\right ) =f\left ( x\right ) -\left ( \left ( \frac {B-A}{L}\right ) x+A\right ) \) in this case, hence the solution becomes\begin {align*} v\left ( x,t\right ) & =\sum _{n=1}^{\infty }e^{-k\left ( \frac {n\pi }{L}\right ) ^{2}t}\sin \left ( \frac {n\pi }{L}x\right ) \left ( \frac {2}{L}\int _{0}^{L}\left ( f\left ( s\right ) -\left ( \left ( \frac {B-A}{L}\right ) s+A\right ) \right ) \sin \left ( \frac {n\pi }{L}s\right ) ds\right ) \\ & +\sum _{n=1}^{\infty }e^{-k\left ( \frac {n\pi }{L}\right ) ^{2}t}\sin \left ( \frac {n\pi }{L}x\right ) \left ( \int _{0}^{t}\frac {2}{L}e^{k\left ( \frac {n\pi }{L}\right ) ^{2}\tau }\left ( \int _{0}^{L}Q\left ( s\right ) \sin \left ( \frac {n\pi }{L}s\right ) ds\right ) d\tau \right ) \end {align*}

Since \(u\left ( x,t\right ) =v\left ( x,t\right ) +r\left ( x\right ) \), then the final solution is\begin {align*} u\left ( x,t\right ) & =\left ( \frac {B-A}{L}\right ) x+A+\\ & \sum _{n=1}^{\infty }e^{-k\left ( \frac {n\pi }{L}\right ) ^{2}t}\sin \left ( \frac {n\pi }{L}x\right ) \left ( \frac {2}{L}\int _{0}^{L}\left ( f\left ( s\right ) -\left ( \left ( \frac {B-A}{L}\right ) s+A\right ) \right ) \sin \left ( \frac {n\pi }{L}s\right ) ds\right ) \\ & +\sum _{n=1}^{\infty }e^{-k\left ( \frac {n\pi }{L}\right ) ^{2}t}\sin \left ( \frac {n\pi }{L}x\right ) \left ( \int _{0}^{t}\frac {2}{L}e^{k\left ( \frac {n\pi }{L}\right ) ^{2}\tau }\left ( \int _{0}^{L}Q\left ( s\right ) \sin \left ( \frac {n\pi }{L}s\right ) ds\right ) d\tau \right ) \end {align*}

____________________________________________________________________________________

4.1.5.5 [220] With source that depends on space only (special case)

problem number 220

Added July 6,2019

Solve the heat equation for \(u(x,t)\) \[ u_t= k u_{xx} + Q(x) \] For \(0<x<L\) and \(t>0\). The boundary conditions are \begin {align*} u(0,t) &=A \\ u(1,t) &=B\\ \end {align*}

Initial condition is \(u(x,0)=f(x)\), Using the following values \begin {align*} A &=20 \\ B &=50\\ f(x)&=60-2 x\\ L&=30\\ k&=\frac {1}{10}\\ Q(x) &=\frac {x}{10} \end {align*}

Mathematica

ClearAll["Global`*"]; 
A=20; B=50; f=60-2*x; L=30; k=1/10; Q=x/10; 
pde =  D[u[x, t], t] == k*D[u[x, t], {x, 2}] + Q; 
bc  = {u[0, t] == A, u[L, t] == B}; 
ic  = u[x, 0] == f; 
sol =  AbsoluteTiming[TimeConstrained[DSolve[{pde, ic, bc}, u[x, t], x, t], 60*10]];
 

\[\left \{\left \{u(x,t)\to \sum _{K[1]=1}^\infty -\frac {20 e^{-\frac {\pi ^2 t K[1]^2}{9000}} \left (-\left (\left (4+5 (-1)^{K[1]}\right ) \pi ^2 K[1]^2\right )-2700 (-1)^{K[1]}+2700 (-1)^{K[1]} e^{\frac {\pi ^2 t K[1]^2}{9000}}\right ) \sin \left (\frac {1}{30} \pi x K[1]\right )}{\pi ^3 K[1]^3}+x+20\right \}\right \}\]

Maple

restart; 
A:=20; 
B:=50; 
f:=60-2*x; 
L:=30; 
k:=1/10; 
Q:=x/10; 
pde := diff(u(x,t),t)= k*diff(u(x,t),x$2)+Q; 
bc  := u(0, t) = A, u(L, t) = B; 
ic  := u(x, 0) = f; 
cpu_time := timelimit(60*10,CodeTools[Usage](assign('sol', pdsolve([pde, ic, bc], u(x, t))),output='realtime'));
 

\[u \left (x , t\right ) = -\frac {x^{3}}{6}+151 x +20 \left (\sum _{n=1}^\infty \frac {\left (5 \pi ^{2} n^{2} \left (-1\right )^{n}+4 \pi ^{2} n^{2}+2700 \left (-1\right )^{n}\right ) {\mathrm e}^{-\frac {\pi ^{2} n^{2} t}{9000}} \sin \left (\frac {\pi n x}{30}\right )}{\pi ^{3} n^{3}}\right )+20\]

Hand solution

Solving\begin {align} u_{t} & =kv_{xx}+Q\left ( x\right ) \tag {1}\\ u\left ( 0,t\right ) & =A\nonumber \\ u\left ( L,t\right ) & =B\nonumber \\ u\left ( x,0\right ) & =f\left ( x\right ) \nonumber \end {align}

Where \(A=20,B=50,f\left ( x\right ) =60-2x,Q\left ( x\right ) =\frac {x}{10},k=\frac {1}{10},L=30\).

The general solution to above PDE was solved in 4.1.5.4 on page 708 and the solution is\begin {align*} u\left ( x,t\right ) & =\left ( \frac {B-A}{L}\right ) x+A+\\ & \sum _{n=1}^{\infty }e^{-k\left ( \frac {n\pi }{L}\right ) ^{2}t}\sin \left ( \frac {n\pi }{L}x\right ) \left ( \frac {2}{L}\int _{0}^{L}\left ( f\left ( s\right ) -\left ( \left ( \frac {B-A}{L}\right ) s+A\right ) \right ) \sin \left ( \frac {n\pi }{L}s\right ) ds\right ) \\ & +\sum _{n=1}^{\infty }e^{-k\left ( \frac {n\pi }{L}\right ) ^{2}t}\sin \left ( \frac {n\pi }{L}x\right ) \left ( \int _{0}^{t}\frac {2}{L}e^{k\left ( \frac {n\pi }{L}\right ) ^{2}\tau }\left ( \int _{0}^{L}Q\left ( s\right ) \sin \left ( \frac {n\pi }{L}s\right ) ds\right ) d\tau \right ) \end {align*}

Replacing the specific values, the solution becomes\begin {align*} u\left ( x,t\right ) & =x+20+\sum _{n=1}^{\infty }e^{-k\left ( \frac {n\pi }{L}\right ) ^{2}t}\sin \left ( \frac {n\pi }{L}x\right ) \left ( \frac {2}{30}\int _{0}^{30}\left ( 60-2s-\left ( s+20\right ) \right ) \sin \left ( \frac {n\pi }{30}s\right ) ds\right ) \\ & +\sum _{n=1}^{\infty }e^{-k\left ( \frac {n\pi }{L}\right ) ^{2}t}\sin \left ( \frac {n\pi }{L}x\right ) \left ( \int _{0}^{t}\frac {2}{30}e^{k\left ( \frac {n\pi }{L}\right ) ^{2}\tau }\left ( \int _{0}^{30}\frac {s}{10}\sin \left ( \frac {n\pi }{30}s\right ) ds\right ) d\tau \right ) \end {align*}

Or\begin {align*} u\left ( x,t\right ) & =x+20+\frac {1}{15}\sum _{n=1}^{\infty }e^{-k\left ( \frac {n\pi }{L}\right ) ^{2}t}\sin \left ( \frac {n\pi }{L}x\right ) \left ( \int _{0}^{30}\left ( 40-3s\right ) \sin \left ( \frac {n\pi }{30}s\right ) ds\right ) \\ & +\frac {1}{150}\sum _{n=1}^{\infty }e^{-k\left ( \frac {n\pi }{L}\right ) ^{2}t}\sin \left ( \frac {n\pi }{L}x\right ) \left ( \int _{0}^{t}e^{k\left ( \frac {n\pi }{L}\right ) ^{2}\tau }\left ( \int _{0}^{30}s\sin \left ( \frac {n\pi }{30}s\right ) ds\right ) d\tau \right ) \end {align*}

But \(\int _{0}^{30}\left ( 40-3s\right ) \sin \left ( \frac {n\pi }{30}s\right ) ds=\frac {1500\left ( -1\right ) ^{n}+1200}{n\pi }\) and \(\int _{0}^{30}s\sin \left ( \frac {n\pi }{30}s\right ) ds=\frac {-900\left ( -1\right ) ^{n}}{n\pi }\), hence the above becomes\begin {align*} u\left ( x,t\right ) & =x+20+\frac {1}{15}\sum _{n=1}^{\infty }e^{-k\left ( \frac {n\pi }{L}\right ) ^{2}t}\sin \left ( \frac {n\pi }{L}x\right ) \left ( \frac {1500\left ( -1\right ) ^{n}+1200}{n\pi }\right ) \\ & +\frac {1}{150}\sum _{n=1}^{\infty }e^{-k\left ( \frac {n\pi }{L}\right ) ^{2}t}\sin \left ( \frac {n\pi }{L}x\right ) \left ( \int _{0}^{t}e^{k\left ( \frac {n\pi }{L}\right ) ^{2}\tau }\left ( \frac {-900\left ( -1\right ) ^{n}}{n\pi }\right ) d\tau \right ) \end {align*}

Or\begin {align*} u\left ( x,t\right ) & =x+20+\frac {300}{15}\sum _{n=1}^{\infty }\left ( \frac {5\left ( -1\right ) ^{n}+4}{n\pi }\right ) e^{-k\left ( \frac {n\pi }{L}\right ) ^{2}t}\sin \left ( \frac {n\pi }{L}x\right ) \\ & -\frac {900}{150}\sum _{n=1}^{\infty }\frac {\left ( -1\right ) ^{n}}{n\pi }e^{-k\left ( \frac {n\pi }{L}\right ) ^{2}t}\sin \left ( \frac {n\pi }{L}x\right ) \left ( \int _{0}^{t}e^{k\left ( \frac {n\pi }{L}\right ) ^{2}\tau }d\tau \right ) \end {align*}

But \(\int _{0}^{t}e^{k\left ( \frac {n\pi }{L}\right ) ^{2}\tau }d\tau =\left [ \frac {e^{k\left ( \frac {n\pi }{L}\right ) ^{2}\tau }}{k\left ( \frac {n\pi }{L}\right ) ^{2}}\right ] _{0}^{t}=\frac {e^{k\left ( \frac {n\pi }{L}\right ) ^{2}t}-1}{k\left ( \frac {n\pi }{L}\right ) ^{2}}\), therefore the above becomes\begin {align*} u\left ( x,t\right ) & =x+20+\frac {300}{15}\sum _{n=1}^{\infty }\left ( \frac {5\left ( -1\right ) ^{n}+4}{n\pi }\right ) e^{-k\left ( \frac {n\pi }{L}\right ) ^{2}t}\sin \left ( \frac {n\pi }{L}x\right ) \\ & -\frac {900}{150}\sum _{n=1}^{\infty }\frac {\left ( -1\right ) ^{n}}{n\pi }e^{-k\left ( \frac {n\pi }{L}\right ) ^{2}t}\sin \left ( \frac {n\pi }{L}x\right ) \left ( \frac {e^{k\left ( \frac {n\pi }{L}\right ) ^{2}t}-1}{k\left ( \frac {n\pi }{L}\right ) ^{2}}\right ) \end {align*}

Or\begin {align*} u\left ( x,t\right ) =x+20+20 & \sum _{n=1}^{\infty }\left ( \frac {5\left ( -1\right ) ^{n}+4}{n\pi }\right ) e^{-k\left ( \frac {n\pi }{L}\right ) ^{2}t}\sin \left ( \frac {n\pi }{L}x\right ) \\ & -\frac {900}{150}\sum _{n=1}^{\infty }\frac {\left ( -1\right ) ^{n}}{n\pi k\left ( \frac {n\pi }{L}\right ) ^{2}}\sin \left ( \frac {n\pi }{L}x\right ) \left ( 1-e^{-k\left ( \frac {n\pi }{L}\right ) ^{2}t}\right ) \end {align*}

Finally replacing the remaining variables in the above for \(L,k\,\) gives\begin {align*} u\left ( x,t\right ) =x+20+20 & \sum _{n=1}^{\infty }\left ( \frac {5\left ( -1\right ) ^{n}+4}{n\pi }\right ) e^{-\frac {1}{10}\left ( \frac {n\pi }{30}\right ) ^{2}t}\sin \left ( \frac {n\pi }{30}x\right ) \\ & -\frac {900}{150}\sum _{n=1}^{\infty }\frac {9000\left ( -1\right ) ^{n}}{n^{3}\pi ^{3}}\sin \left ( \frac {n\pi }{30}x\right ) \left ( 1-e^{-\frac {1}{10}\left ( \frac {n\pi }{30}\right ) ^{2}t}\right ) \end {align*}

Or\begin {align*} u\left ( x,t\right ) & =x+20+20\sum _{n=1}^{\infty }\left ( \frac {5\left ( -1\right ) ^{n}+4}{n\pi }\right ) e^{-\frac {1}{10}\left ( \frac {n\pi }{30}\right ) ^{2}t}\sin \left ( \frac {n\pi }{30}x\right ) \\ & -54000\sum _{n=1}^{\infty }\frac {\left ( -1\right ) ^{n}}{n^{3}\pi ^{3}}\sin \left ( \frac {n\pi }{30}x\right ) \left ( 1-e^{-\frac {1}{10}\left ( \frac {n\pi }{30}\right ) ^{2}t}\right ) \end {align*}

Or\[ u\left ( x,t\right ) =\left ( x+20\right ) +20\sum _{n=1}^{\infty }\left ( \frac {5\left ( -1\right ) ^{n}+4}{n\pi }\right ) e^{-\frac {\pi ^{2}n^{2}}{9000}t}\sin \left ( \frac {n\pi }{30}x\right ) -54000\sum _{n=1}^{\infty }\frac {\left ( -1\right ) ^{n}}{n^{3}\pi ^{3}}\sin \left ( \frac {n\pi }{30}x\right ) \left ( 1-e^{-\frac {\pi ^{2}n^{2}}{9000}t}\right ) \] Animation is below

Source code used for the above

____________________________________________________________________________________

4.1.5.6 [221] With source that depends on space and time only (general case)

problem number 221

Added July 6,2019

Solve the heat equation for \(u(x,t)\) \[ u_t= k u_{xx} + Q(x,t) \] For \(0<x<L\) and \(t>0\). The boundary conditions are \begin {align*} u(0,t) &=A \\ u(1,t) &=B\\ \end {align*}

Initial condition is \(u(x,0)=f(x)\)

Mathematica

ClearAll["Global`*"]; 
pde =  D[u[x, t], t] == k*D[u[x, t], {x, 2}] + Q[x,t]; 
bc  = {u[0, t] == A, u[L, t] == B}; 
ic  = u[x, 0] == f[x]; 
sol =  AbsoluteTiming[TimeConstrained[DSolve[{pde, ic, bc}, u[x, t], {x, t},Assumptions->{k>0,L>0}], 60*10]];
 

\[\left \{\left \{u(x,t)\to \sum _{K[1]=1}^\infty \frac {\sqrt {2} \left (\int _0^t e^{-\frac {k \pi ^2 K[1]^2 (t-K[2])}{L^2}} \text {Integrate}\left [\frac {\sqrt {2} Q(x,K[2]) \sin \left (\frac {\pi x K[1]}{L}\right )}{\sqrt {L}},\{x,0,L\},\text {Assumptions}\to k>0\land L>0\right ] \, dK[2]+e^{-\frac {k \pi ^2 t K[1]^2}{L^2}} \int _0^L \frac {\sqrt {2} (-A L+f(x) L+A x-B x) \sin \left (\frac {\pi x K[1]}{L}\right )}{L^{3/2}} \, dx\right ) \sin \left (\frac {\pi x K[1]}{L}\right )}{\sqrt {L}}+\frac {x (B-A)}{L}+A\right \}\right \}\]

Maple

restart; 
pde := diff(u(x,t),t)= k*diff(u(x,t),x$2)+Q(x,t); 
bc  := u(0, t) = A, u(L, t) = B; 
ic  := u(x, 0) = f(x); 
cpu_time := timelimit(60*10,CodeTools[Usage](assign('sol', pdsolve([pde, ic, bc], u(x, t)) assuming L>0,k>0),output='realtime'));
 

\[u \left (x , t\right ) = \frac {A L +L \left (\int _{0}^{t}\left (\sum _{n=1}^\infty \frac {2 \left (\int _{0}^{L}Q \left (x , \tau \right ) \sin \left (\frac {\pi n x}{L}\right )d x \right ) {\mathrm e}^{-\frac {\pi ^{2} \left (t -\tau \right ) k \,n^{2}}{L^{2}}} \sin \left (\frac {\pi n x}{L}\right )}{L}\right )d \tau \right )-2 L \left (\sum _{n=1}^\infty \frac {\left (\int _{0}^{L}\left (A L -L f \left (\tau \right )+\left (-A +B \right ) \tau \right ) \sin \left (\frac {\pi n \tau }{L}\right )d \tau \right ) {\mathrm e}^{-\frac {\pi ^{2} k \,n^{2} t}{L^{2}}} \sin \left (\frac {\pi n x}{L}\right )}{L^{2}}\right )-\left (A -B \right ) x}{L}\]

Hand solution

Solving\begin {equation} u_{t}=ku_{xx}+Q\left ( x,t\right ) \tag {1} \end {equation} With initial conditions \(u\left ( x,0\right ) =f\left ( x\right ) \) and boundary conditions \(u\left ( 0,t\right ) =A,u\left ( L,t\right ) =B\) with \(0<x<L,t>0\)

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 ) =v\left ( x,t\right ) +r\left ( x\right ) \tag {2} \end {equation} Where \(v\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 ) & =A\\ r\left ( L\right ) & =B \end {align*}

This has the solution \(r\left ( x\right ) =c_{1}x+c_{2}\). Using BC at \(x=0\) leads to \(A=c_{2}\). Therefore the solution is \(r\left ( x\right ) =c_{1}x+A\). Using BC at \(x=L\) gives \(B=c_{1}L+A\) or \(c_{1}=\frac {B-A}{L}\). Hence\begin {equation} r\left ( x\right ) =\left ( \frac {B-A}{L}\right ) x+A\tag {3} \end {equation} Substituting (2) back in the original PDE \(u_{t}=ku_{xx}+Q\left ( x,t\right ) \) gives\begin {align} v_{t} & =kv_{xx}+Q\left ( x,t\right ) \tag {4}\\ v\left ( 0,t\right ) & =0\nonumber \\ v\left ( L,t\right ) & =0\nonumber \end {align}

The initial conditions are\begin {align*} v\left ( x,0\right ) & =F\left ( x\right ) \\ & =u\left ( x,0\right ) -r\left ( x\right ) \\ & =f\left ( x\right ) -\left ( \left ( \frac {B-A}{L}\right ) x+A\right ) \end {align*}

The general solution to (4) was solved in 4.1.6.4 on page 806 and the solution is

\begin {align*} v\left ( x,t\right ) & =\sum _{n=1}^{\infty }e^{-k\lambda _{n}t}\Phi _{n}\left ( x\right ) \left ( \frac {2}{L}\int _{0}^{L}f\left ( s\right ) \Phi _{n}\left ( s\right ) ds\right ) +\sum _{n=1}^{\infty }e^{-k\lambda _{n}t}\Phi _{n}\left ( x\right ) \left ( \int _{0}^{t}\frac {2}{L}e^{k\lambda _{n}\tau }\left ( \int _{0}^{L}Q\left ( s,\tau \right ) \Phi _{n}\left ( s\right ) ds\right ) d\tau \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 \end {align*}

But \(F\left ( x\right ) =f\left ( x\right ) -\left ( \left ( \frac {B-A}{L}\right ) x+A\right ) \) in this case, hence the solution becomes\begin {align*} v\left ( x,t\right ) & =\sum _{n=1}^{\infty }e^{-k\left ( \frac {n\pi }{L}\right ) ^{2}t}\sin \left ( \frac {n\pi }{L}x\right ) \left ( \frac {2}{L}\int _{0}^{L}\left ( f\left ( s\right ) -\left ( \left ( \frac {B-A}{L}\right ) s+A\right ) \right ) \sin \left ( \frac {n\pi }{L}s\right ) ds\right ) \\ & +\sum _{n=1}^{\infty }e^{-k\left ( \frac {n\pi }{L}\right ) ^{2}t}\sin \left ( \frac {n\pi }{L}x\right ) \left ( \int _{0}^{t}\frac {2}{L}e^{k\left ( \frac {n\pi }{L}\right ) ^{2}\tau }\left ( \int _{0}^{L}Q\left ( s,\tau \right ) \sin \left ( \frac {n\pi }{L}s\right ) ds\right ) d\tau \right ) \end {align*}

Since \(u\left ( x,t\right ) =v\left ( x,t\right ) +r\left ( x\right ) \), then the final solution is\begin {align*} u\left ( x,t\right ) & =\left ( \frac {B-A}{L}\right ) x+A+\\ & \sum _{n=1}^{\infty }e^{-k\left ( \frac {n\pi }{L}\right ) ^{2}t}\sin \left ( \frac {n\pi }{L}x\right ) \left ( \frac {2}{L}\int _{0}^{L}\left ( f\left ( s\right ) -\left ( \left ( \frac {B-A}{L}\right ) s+A\right ) \right ) \sin \left ( \frac {n\pi }{L}s\right ) ds\right ) \\ & +\sum _{n=1}^{\infty }e^{-k\left ( \frac {n\pi }{L}\right ) ^{2}t}\sin \left ( \frac {n\pi }{L}x\right ) \left ( \int _{0}^{t}\frac {2}{L}e^{k\left ( \frac {n\pi }{L}\right ) ^{2}\tau }\left ( \int _{0}^{L}Q\left ( s,\tau \right ) \sin \left ( \frac {n\pi }{L}s\right ) ds\right ) d\tau \right ) \end {align*}

____________________________________________________________________________________

4.1.5.7 [222] Both ends depend on time (general case)

problem number 222

Added June 23, 2019

Solve the heat equation for \(u(x,t)\) \[ u_t= k u_{xx} \] For \(0<x<L\) and \(t>0\). The boundary conditions are \begin {align*} u(0,t)&=A(t) \\ u(L,t) &= B(t)\\ \end {align*}

Initial condition is \(u(x,0)=f(x)\)

Mathematica

ClearAll["Global`*"]; 
pde =  D[u[x, t], t] == k*D[u[x, t], {x, 2}]; 
bc  = {u[0, t] == A[t], u[L, t] == B[t]}; 
ic  = u[x, 0] == f[x]; 
sol =  AbsoluteTiming[TimeConstrained[DSolve[{pde, ic, bc}, u[x, t], {x, t},Assumptions->{k>0,L>0}], 60*10]];
 

\[\left \{\left \{u(x,t)\to \sum _{K[1]=1}^\infty \frac {\sqrt {2} \left (e^{-\frac {k \pi ^2 t K[1]^2}{L^2}} \int _0^L \frac {\sqrt {2} (-L A(0)+x A(0)-x B(0)+L f(x)) \sin \left (\frac {\pi x K[1]}{L}\right )}{L^{3/2}} \, dx+\int _0^t \frac {\sqrt {2} e^{-\frac {k \pi ^2 K[1]^2 (t-K[2])}{L^2}} \sqrt {L} \left ((-1)^{K[1]} B'(K[2])-A'(K[2])\right )}{\pi K[1]} \, dK[2]\right ) \sin \left (\frac {\pi x K[1]}{L}\right )}{\sqrt {L}}+\frac {x (B(t)-A(t))}{L}+A(t)\right \}\right \}\]

Maple

restart; 
pde := diff(u(x,t),t)= k*diff(u(x,t),x$2); 
bc  := u(0, t) = A(t), u(L, t) = B(t); 
ic  := u(x, 0) = f(x); 
cpu_time := timelimit(60*10,CodeTools[Usage](assign('sol', pdsolve([pde, ic, bc], u(x, t)) assuming L>0,k>0),output='realtime'));
 

\[u \left (x , t\right ) = \frac {L \left (\int _{0}^{t}\left (\sum _{n=1}^\infty \left (-\frac {2 \left (-\left (-1\right )^{n} \left (\frac {d}{d \tau }B \left (\tau \right )\right )+\frac {d}{d \tau }A \left (\tau \right )\right ) {\mathrm e}^{-\frac {\pi ^{2} \left (t -\tau \right ) k \,n^{2}}{L^{2}}} \sin \left (\frac {\pi n x}{L}\right )}{\pi n}\right )\right )d \tau \right )+L \left (\sum _{n=1}^\infty \frac {2 \left (\int _{0}^{L}\frac {\left (L f \left (x \right )-B \left (0\right ) x +A \left (0\right ) \left (-L +x \right )\right ) \sin \left (\frac {\pi n x}{L}\right )}{L}d x \right ) {\mathrm e}^{-\frac {\pi ^{2} k \,n^{2} t}{L^{2}}} \sin \left (\frac {\pi n x}{L}\right )}{L}\right )+x B \left (t \right )+\left (L -x \right ) A \left (t \right )}{L}\]

Hand solution

\begin {align} u_{t} & =ku_{xx}\tag {1}\\ u\left ( 0,t\right ) & =A\left ( t\right ) \nonumber \\ u\left ( L,t\right ) & =B\left ( t\right ) \nonumber \\ u\left ( x,0\right ) & =f\left ( x\right ) \nonumber \end {align}

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 a reference solution \(r\left ( x,t\right ) \) which only needs to satisfy the B.C. Let the total solution be\begin {equation} u\left ( x,t\right ) =v\left ( x,t\right ) +r\left ( x,t\right ) \tag {2} \end {equation} Where \(v\left ( x,t\right ) \) is the transient solution which satisfies the homogeneous B.C. We see that\begin {align} r\left ( x,t\right ) & =A\left ( t\right ) +\frac {B\left ( t\right ) -A\left ( t\right ) }{L}x\nonumber \\ & =A\left ( t\right ) \left ( \frac {L-x}{L}\right ) +\frac {B\left ( t\right ) }{L}x\tag {3} \end {align}

Satisfies the nonhomogeneous. Substituting (2) back into the original PDE (1) gives\begin {align*} \frac {\partial }{\partial t}\left ( v\left ( x,t\right ) +r\left ( x,t\right ) \right ) & =k\frac {\partial ^{2}}{\partial x^{2}}\left ( v\left ( x,t\right ) +r\left ( x,t\right ) \right ) \\ v_{t}\left ( x,t\right ) +r_{t}\left ( x,t\right ) & =kv_{xx}\left ( x,t\right ) +kr_{xx}\left ( x,t\right ) \end {align*}

But \(r_{xx}\left ( x,t\right ) =0\) and \(r_{t}=A^{\prime }\left ( t\right ) \left ( \frac {L-x}{L}\right ) +\frac {B^{\prime }\left ( t\right ) }{L}x\) and the above PDE becomes\[ v_{t}\left ( x,t\right ) =kv_{xx}\left ( x,t\right ) -r_{t}\left ( x,t\right ) \] Let \begin {align*} Q\left ( x,t\right ) & =-r_{t}\left ( x,t\right ) \\ & =-\left ( A^{\prime }\left ( t\right ) \left ( \frac {L-x}{L}\right ) +\frac {B^{\prime }\left ( t\right ) }{L}x\right ) \end {align*}

Therefore the problem has been transformed to\begin {align*} v_{t} & =kv_{xx}+Q\left ( x,t\right ) \\ v\left ( 0,t\right ) & =0\\ v\left ( L,t\right ) & =0\\ v\left ( 0,x\right ) & =F\left ( x\right ) \\ & =u\left ( x,0\right ) -r\left ( x,0\right ) \\ & =f\left ( x\right ) -\left ( A\left ( 0\right ) \left ( \frac {L-x}{L}\right ) +\frac {B\left ( 0\right ) }{L}x\right ) \end {align*}

The above problem was solved in 4.1.6.4 on page 806. The solution is\begin {equation} v\left ( x,t\right ) =\sum _{n=1}^{\infty }\left [ \left ( \frac {2}{L}\int _{0}^{L}F\left ( s\right ) \Phi _{n}\left ( s\right ) ds\right ) e^{-k\lambda _{n}t}+e^{-k\lambda _{n}t}\int _{0}^{t}\frac {2}{L}e^{k\lambda _{n}\tau }\left ( \int _{0}^{L}Q\left ( s,\tau \right ) \Phi _{n}\left ( s\right ) dx\right ) d\tau \right ] \Phi _{n}\left ( x\right ) \tag {4} \end {equation} Where \begin {align*} \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 \end {align*}

Hence (4) becomes

\begin {align*} v\left ( x,t\right ) & =\frac {2}{L}\sum _{n=1}^{\infty }e^{-k\lambda _{n}t}\sin \left ( \frac {n\pi }{L}x\right ) \left ( \int _{0}^{L}F\left ( s\right ) \sin \left ( \frac {n\pi }{L}s\right ) ds\right ) \\ & +\frac {2}{L}\sum _{n=1}^{\infty }e^{-k\lambda _{n}t}\sin \left ( \frac {n\pi }{L}x\right ) \int _{0}^{t}e^{k\lambda _{n}\tau }\left ( \int _{0}^{L}Q\left ( s,\tau \right ) \sin \left ( \frac {n\pi }{L}s\right ) dx\right ) d\tau \end {align*}

Since \(u\left ( x,t\right ) =r\left ( x,t\right ) +v\left ( x,t\right ) \) then the final solution becomes

\begin {align*} u\left ( x,t\right ) & =\left ( A\left ( t\right ) \left ( \frac {L-x}{L}\right ) +\frac {B\left ( t\right ) }{L}x\right ) \\ & +\frac {2}{L}\sum _{n=1}^{\infty }e^{-k\lambda _{n}t}\sin \left ( \frac {n\pi }{L}x\right ) \left ( \int _{0}^{L}F\left ( s\right ) \sin \left ( \frac {n\pi }{L}s\right ) ds\right ) \\ & +\frac {2}{L}\sum _{n=1}^{\infty }e^{-k\lambda _{n}t}\sin \left ( \frac {n\pi }{L}x\right ) \int _{0}^{t}e^{k\lambda _{n}\tau }\left ( \int _{0}^{L}Q\left ( s,\tau \right ) \sin \left ( \frac {n\pi }{L}s\right ) ds\right ) d\tau \end {align*}

Or

\begin {align*} u\left ( x,t\right ) & =\left ( A\left ( t\right ) \left ( \frac {L-x}{L}\right ) +\frac {B\left ( t\right ) }{L}x\right ) \\ & +\frac {2}{L}\sum _{n=1}^{\infty }e^{-k\left ( \frac {n\pi }{L}\right ) ^{2}t}\sin \left ( \frac {n\pi }{L}x\right ) \left ( \int _{0}^{L}\left ( f\left ( s\right ) -\left ( A\left ( 0\right ) \left ( \frac {L-s}{L}\right ) +\frac {B\left ( 0\right ) }{L}s\right ) \right ) \sin \left ( \frac {n\pi }{L}s\right ) ds\right ) \\ & +\frac {2}{L}\sum _{n=1}^{\infty }e^{-k\left ( \frac {n\pi }{L}\right ) ^{2}t}\sin \left ( \frac {n\pi }{L}x\right ) \left ( \int _{0}^{t}e^{k\left ( \frac {n\pi }{L}\right ) ^{2}\tau }\left ( \int _{0}^{L}Q\left ( s,\tau \right ) \sin \left ( \frac {n\pi }{L}s\right ) ds\right ) d\tau \right ) \end {align*}

Or

\begin {align*} u\left ( x,t\right ) & =\left ( A\left ( t\right ) \left ( \frac {L-x}{L}\right ) +\frac {B\left ( t\right ) }{L}x\right ) \\ & +\frac {2}{L^{2}}\sum _{n=1}^{\infty }e^{-k\left ( \frac {n\pi }{L}\right ) ^{2}t}\sin \left ( \frac {n\pi }{L}x\right ) \left ( \int _{0}^{L}\left ( f\left ( s\right ) L-\left ( A\left ( 0\right ) \left ( L-s\right ) +B\left ( 0\right ) s\right ) \right ) \sin \left ( \frac {n\pi }{L}s\right ) ds\right ) \\ & +\frac {2}{L}\sum _{n=1}^{\infty }e^{-k\left ( \frac {n\pi }{L}\right ) ^{2}t}\sin \left ( \frac {n\pi }{L}x\right ) \left ( \int _{0}^{t}e^{k\left ( \frac {n\pi }{L}\right ) ^{2}\tau }\left ( \int _{0}^{L}Q\left ( s,\tau \right ) \sin \left ( \frac {n\pi }{L}s\right ) ds\right ) d\tau \right ) \end {align*}

Or, since here \(Q\left ( x,t\right ) =-\left ( A^{\prime }\left ( t\right ) \left ( \frac {L-x}{L}\right ) +\frac {B^{\prime }\left ( t\right ) }{L}x\right ) \) the above becomes\begin {align*} u\left ( x,t\right ) & =\left ( A\left ( t\right ) \left ( \frac {L-x}{L}\right ) +\frac {B\left ( t\right ) }{L}x\right ) \\ & +\frac {2}{L^{2}}\sum _{n=1}^{\infty }e^{-k\left ( \frac {n\pi }{L}\right ) ^{2}t}\sin \left ( \frac {n\pi }{L}x\right ) \left ( \int _{0}^{L}\left ( f\left ( s\right ) L-\left ( A\left ( 0\right ) \left ( L-s\right ) +B\left ( 0\right ) s\right ) \right ) \sin \left ( \frac {n\pi }{L}s\right ) ds\right ) \\ & +\frac {2}{L}\sum _{n=1}^{\infty }e^{-k\left ( \frac {n\pi }{L}\right ) ^{2}t}\sin \left ( \frac {n\pi }{L}x\right ) \left ( \int _{0}^{t}e^{k\left ( \frac {n\pi }{L}\right ) ^{2}\tau }\left ( \int _{0}^{L}\left ( \frac {B^{\prime }\left ( \tau \right ) }{L}s-A^{\prime }\left ( \tau \right ) \left ( \frac {L-s}{L}\right ) \right ) \sin \left ( \frac {n\pi }{L}s\right ) ds\right ) d\tau \right ) \end {align*}

Or

\begin {align*} u\left ( x,t\right ) & =\left ( A\left ( t\right ) \left ( \frac {L-x}{L}\right ) +\frac {B\left ( t\right ) }{L}x\right ) \\ & +\frac {2}{L^{2}}\sum _{n=1}^{\infty }e^{-k\left ( \frac {n\pi }{L}\right ) ^{2}t}\sin \left ( \frac {n\pi }{L}x\right ) \left ( \int _{0}^{L}f\left ( s\right ) L\sin \left ( \frac {n\pi }{L}s\right ) -A\left ( 0\right ) \left ( L-s\right ) \sin \left ( \frac {n\pi }{L}s\right ) -B\left ( 0\right ) s\sin \left ( \frac {n\pi }{L}s\right ) ds\right ) \\ & +\frac {2}{L}\sum _{n=1}^{\infty }e^{-k\left ( \frac {n\pi }{L}\right ) ^{2}t}\sin \left ( \frac {n\pi }{L}x\right ) \left ( \int _{0}^{t}e^{k\left ( \frac {n\pi }{L}\right ) ^{2}\tau }\left ( \int _{0}^{L}\frac {B^{\prime }\left ( \tau \right ) }{L}s\sin \left ( \frac {n\pi }{L}s\right ) -A^{\prime }\left ( \tau \right ) \left ( \frac {L-s}{L}\right ) \sin \left ( \frac {n\pi }{L}s\right ) ds\right ) d\tau \right ) \end {align*}

Or

\begin {align} u\left ( x,t\right ) & =\left ( A\left ( t\right ) \left ( \frac {L-x}{L}\right ) +\frac {B\left ( t\right ) }{L}x\right ) \tag {5}\\ & +\frac {2}{L^{2}}\sum _{n=1}^{\infty }e^{-k\left ( \frac {n\pi }{L}\right ) ^{2}t}\sin \left ( \frac {n\pi }{L}x\right ) \left ( \int _{0}^{L}f\left ( s\right ) L\sin \left ( \frac {n\pi }{L}s\right ) -A\left ( 0\right ) \left ( L-s\right ) \sin \left ( \frac {n\pi }{L}s\right ) -B\left ( 0\right ) s\sin \left ( \frac {n\pi }{L}s\right ) ds\right ) \nonumber \\ & +\frac {2}{L^{2}}\sum _{n=1}^{\infty }e^{-k\left ( \frac {n\pi }{L}\right ) ^{2}t}\sin \left ( \frac {n\pi }{L}x\right ) \left ( \int _{0}^{t}e^{k\left ( \frac {n\pi }{L}\right ) ^{2}\tau }\left ( \int _{0}^{L}B^{\prime }\left ( \tau \right ) s\sin \left ( \frac {n\pi }{L}s\right ) -A^{\prime }\left ( \tau \right ) \left ( L-s\right ) \sin \left ( \frac {n\pi }{L}s\right ) ds\right ) d\tau \right ) \nonumber \end {align}

But \begin {multline*} \int _{0}^{L}f\left ( s\right ) L\sin \left ( \frac {n\pi }{L}s\right ) -A\left ( 0\right ) \left ( L-s\right ) \sin \left ( \frac {n\pi }{L}s\right ) -B\left ( 0\right ) s\sin \left ( \frac {n\pi }{L}s\right ) ds=\\ L\int _{0}^{L}f\left ( s\right ) \sin \left ( \frac {n\pi }{L}s\right ) ds-A\left ( 0\right ) \int _{0}^{L}\left ( L-s\right ) \sin \left ( \frac {n\pi }{L}s\right ) ds-B\left ( 0\right ) \int _{0}^{L}s\sin \left ( \frac {n\pi }{L}s\right ) ds \end {multline*}

Since \(\int _{0}^{L}\left ( L-s\right ) \sin \left ( \frac {n\pi }{L}s\right ) ds=\frac {L^{2}}{n\pi }\) and \(\int _{0}^{L}s\sin \left ( \frac {n\pi }{L}s\right ) dx=-\frac {L^{2}\left ( -1\right ) ^{n}}{n\pi }\), then the above becomes\begin {multline} \int _{0}^{L}f\left ( s\right ) \sin \left ( \frac {n\pi }{L}s\right ) -A\left ( 0\right ) \left ( \frac {L-s}{L}\right ) \sin \left ( \frac {n\pi }{L}s\right ) -\frac {B\left ( 0\right ) }{L}s\sin \left ( \frac {n\pi }{L}s\right ) ds=\tag {6}\\ L\int _{0}^{L}f\left ( s\right ) \sin \left ( \frac {n\pi }{L}s\right ) ds-A\left ( 0\right ) \frac {L^{2}}{n\pi }+B\left ( 0\right ) \frac {L^{2}\left ( -1\right ) ^{n}}{n\pi }\nonumber \end {multline}

And \begin {align} \int _{0}^{L}B^{\prime }\left ( \tau \right ) s\sin \left ( \frac {n\pi }{L}s\right ) -A^{\prime }\left ( \tau \right ) \left ( L-s\right ) \sin \left ( \frac {n\pi }{L}s\right ) ds & =-A^{\prime }\left ( \tau \right ) \int _{0}^{L}\left ( L-s\right ) \sin \left ( \frac {n\pi }{L}s\right ) ds+B^{\prime }\left ( \tau \right ) \int _{0}^{L}s\sin \left ( \frac {n\pi }{L}s\right ) ds\tag {7}\\ & =-A^{\prime }\left ( \tau \right ) \frac {L^{2}}{n\pi }+B^{\prime }\left ( \tau \right ) \frac {L^{2}\left ( -1\right ) ^{n}}{n\pi }\nonumber \end {align}

Substituting (6,7) back into (5) gives

\begin {align*} u\left ( x,t\right ) & =\left ( A\left ( t\right ) \left ( \frac {L-x}{L}\right ) +\frac {B\left ( t\right ) }{L}x\right ) \\ & +\frac {2}{L^{2}}\sum _{n=1}^{\infty }e^{-k\left ( \frac {n\pi }{L}\right ) ^{2}t}\sin \left ( \frac {n\pi }{L}x\right ) \left ( L\int _{0}^{L}f\left ( s\right ) \sin \left ( \frac {n\pi }{L}s\right ) ds-A\left ( 0\right ) \frac {L^{2}}{n\pi }+B\left ( 0\right ) \frac {L^{2}\left ( -1\right ) ^{n}}{n\pi }\right ) \\ & -\frac {2}{L^{2}}\sum _{n=1}^{\infty }e^{-k\left ( \frac {n\pi }{L}\right ) ^{2}t}\sin \left ( \frac {n\pi }{L}x\right ) \left ( \int _{0}^{t}e^{k\left ( \frac {n\pi }{L}\right ) ^{2}\tau }\left ( -B^{\prime }\left ( \tau \right ) \frac {L^{2}\left ( -1\right ) ^{n}}{n\pi }+A^{\prime }\left ( \tau \right ) \frac {L^{2}}{n\pi }\right ) d\tau \right ) \end {align*}

Or

\begin {align*} u\left ( x,t\right ) & =\left ( A\left ( t\right ) \left ( \frac {L-x}{L}\right ) +\frac {B\left ( t\right ) }{L}x\right ) \\ & +\frac {2}{L^{2}}\sum _{n=1}^{\infty }e^{-k\left ( \frac {n\pi }{L}\right ) ^{2}t}\sin \left ( \frac {n\pi }{L}x\right ) \left ( \int _{0}^{L}f\left ( s\right ) L\sin \left ( \frac {n\pi }{L}s\right ) ds-A\left ( 0\right ) \frac {L^{2}}{n\pi }+B\left ( 0\right ) \frac {L^{2}\left ( -1\right ) ^{n}}{n\pi }\right ) \\ & -2\sum _{n=1}^{\infty }e^{-k\left ( \frac {n\pi }{L}\right ) ^{2}t}\sin \left ( \frac {n\pi }{L}x\right ) \left ( \frac {1}{n\pi }\int _{0}^{t}e^{k\left ( \frac {n\pi }{L}\right ) ^{2}\tau }\left ( -\left ( -1\right ) ^{n}B^{\prime }\left ( \tau \right ) +A^{\prime }\left ( \tau \right ) \right ) d\tau \right ) \end {align*}

____________________________________________________________________________________

4.1.5.8 [223] Both ends depend on time (special case)

problem number 223

Added June 26, 2019

Solve the heat equation for \(u(x,t)\) \[ u_t= k u_{xx} \] For \(0<x<L\) and \(t>0\). The boundary conditions are \begin {align*} u(0,t) &=A(t) \\ u(L,t) &= B(t)\\ \end {align*}

Initial condition is \(u(x,0)=f(x)\) using the following values \begin {align*} L&=2 \\ k&=\frac {1}{10}\\ f(x)&= x \\ A(t)&= \sin (t)\\ B(t)&= 2 \cos (t) \end {align*}

Mathematica

ClearAll["Global`*"]; 
f=x; 
L=2; 
k=1/10; 
A=Sin[t]; 
B=2*Cos[t]; 
pde =  D[u[x, t], t] == k*D[u[x, t], {x, 2}]; 
bc  = {u[0, t] == A, u[L, t] == B}; 
ic  = u[x, 0] == f; 
sol =  AbsoluteTiming[TimeConstrained[DSolve[{pde, ic, bc}, u[x, t], {x, t}], 60*10]];
 

\[\left \{\left \{u(x,t)\to \sum _{K[1]=1}^\infty \frac {80 \left (e^{-\frac {1}{40} \pi ^2 t K[1]^2} \pi ^2 K[1]^2-80 (-1)^{K[1]} e^{-\frac {1}{40} \pi ^2 t K[1]^2}+\cos (t) \left (80 (-1)^{K[1]}-\pi ^2 K[1]^2\right )-2 \left ((-1)^{K[1]} \pi ^2 K[1]^2+20\right ) \sin (t)\right ) \sin \left (\frac {1}{2} \pi x K[1]\right )}{\pi K[1] \left (\pi ^4 K[1]^4+1600\right )}-\frac {1}{2} x \sin (t)+x \cos (t)+\sin (t)\right \}\right \}\]

Maple

restart; 
f:=x; 
L:=2; 
k:=1/10; 
A:=sin(t); 
B:=2*cos(t); 
pde := diff(u(x,t),t)= k*diff(u(x,t),x$2); 
bc  := u(0, t) = A, u(L, t) = B; 
ic  := u(x, 0) = f; 
cpu_time := timelimit(60*10,CodeTools[Usage](assign('sol', pdsolve([pde, ic, bc], u(x, t)) ),output='realtime'));
 

\[u \left (x , t\right ) = x \cos \left (t \right )-\frac {x \sin \left (t \right )}{2}-80 \left (\sum _{n=1}^\infty \frac {\left (\pi ^{2} n^{2} \cos \left (t \right )+\left (2 \pi ^{2} n^{2} \sin \left (t \right )-80 \cos \left (t \right )\right ) \left (-1\right )^{n}+\left (-\pi ^{2} n^{2}+80 \left (-1\right )^{n}\right ) {\mathrm e}^{-\frac {\pi ^{2} n^{2} t}{40}}+40 \sin \left (t \right )\right ) \sin \left (\frac {\pi n x}{2}\right )}{\pi \left (\pi ^{4} n^{4}+1600\right ) n}\right )+\sin \left (t \right )\]

Hand solution

The basic solution for this type of PDE was already given in problem 4.1.5.7 on page 726 as

\begin {align*} u\left ( x,t\right ) & =\left ( A\left ( t\right ) \left ( \frac {L-x}{L}\right ) +\frac {B\left ( t\right ) }{L}x\right ) \\ & +\frac {2}{L^{2}}\sum _{n=1}^{\infty }e^{-k\left ( \frac {n\pi }{L}\right ) ^{2}t}\sin \left ( \frac {n\pi }{L}x\right ) \left ( \int _{0}^{L}f\left ( s\right ) L\sin \left ( \frac {n\pi }{L}s\right ) ds-A\left ( 0\right ) \frac {L^{2}}{n\pi }+B\left ( 0\right ) \frac {L^{2}\left ( -1\right ) ^{n}}{n\pi }\right ) \\ & -2\sum _{n=1}^{\infty }e^{-k\left ( \frac {n\pi }{L}\right ) ^{2}t}\sin \left ( \frac {n\pi }{L}x\right ) \left ( \frac {1}{n\pi }\int _{0}^{t}e^{k\left ( \frac {n\pi }{L}\right ) ^{2}\tau }\left ( -\left ( -1\right ) ^{n}B^{\prime }\left ( \tau \right ) +A^{\prime }\left ( \tau \right ) \right ) d\tau \right ) \end {align*}

In this problem we have \begin {align*} L & =2\\ k & =\frac {1}{10}\\ f\left ( x\right ) & =x\\ A\left ( t\right ) & =\sin \left ( t\right ) \\ B\left ( t\right ) & =2\cos \left ( t\right ) \end {align*}

This is animation of the above solution using these specific values for \(20\) seconds. (Animation will only show in the HTML version)

Source code used for the above

____________________________________________________________________________________

4.1.5.9 [224] both ends nonhomogeneous

problem number 224

Added January 18, 2019.

Solve the heat equation for \(u(x,t)\) \[ u_t = u_{xx} \] For \(0<x<\pi \) and \(t>0\). The boundary conditions are \begin {align*} u_x(0,t) &= 1\\ u_x(1,t) &= -1 \end {align*}

Initial condition is \(u(x,0)=\sin (x)\)

Mathematica

ClearAll["Global`*"]; 
pde =  D[u[x, t], t] == D[u[x, t], {x, 2}] + (x - (1*x^2)/Pi); 
ic  = u[x, 0] == Sin[x]; 
bc  = {Derivative[1, 0][u][0, t] == 1, Derivative[1, 0][u][Pi, t] == -1}; 
sol =  AbsoluteTiming[TimeConstrained[DSolve[{pde, ic, bc}, u[x, t], {x, t}], 60*10]];
 

\[\left \{\left \{u(x,t)\to \sum _{K[1]=1}^\infty \frac {e^{-t K[1]^2} \cos (x K[1]) \left (\sqrt {2 \pi } K[1]^4 \left (\begin {array}{cc} \{ & \begin {array}{cc} 0 & K[1]=1 \\ -\frac {\left (1+(-1)^{K[1]}\right ) \sqrt {\frac {2}{\pi }}}{K[1]^2 \left (K[1]^2-1\right )} & \text {True} \\\end {array} \\\end {array}\right )-2 \left (1+(-1)^{K[1]}\right ) \left (-1+e^{t K[1]^2}\right )\right )}{\pi K[1]^4}-\frac {2 t+x^2-2}{\pi }+\frac {1}{6} \pi (t-1)+x\right \}\right \}\]

Maple

restart; 
pde := diff(u(x, t), t) = diff(u(x, t), x$2): 
ic  := u(x, 0) = sin(x): 
bc  := eval(diff(u(x,t),x),x=0)=1,  eval( diff(u(x,t),x),x=Pi)=-1: 
cpu_time := timelimit(60*10,CodeTools[Usage](assign('sol', pdsolve({pde, ic, bc}, u(x, t))),output='realtime'));
 

\[u \left (x , t\right ) = -\frac {x^{2}}{\pi }-\frac {2 t}{\pi }+x +\sum _{n=2}^\infty \left (-\frac {2 \left (\left (-1\right )^{n}+1\right ) \cos \left (n x \right ) {\mathrm e}^{-n^{2} t}}{\left (n^{2}-1\right ) \pi \,n^{2}}\right )+\frac {2-\frac {\pi ^{2}}{6}}{\pi }\]

Hand solution

Since the boundary conditions are not homogeneous, we can’t use separation of variables. Let the solution  be

\[ u=v\left ( x,t\right ) +r\left ( x\right ) \] Where \(v\left ( x,t\right ) \) is the solution to \(v_{t}=v_{xx}\) and homogenous B.C. \(v_{x}\left ( 0,t\right ) =0,v_{x}\left ( \pi ,t\right ) =0\) and \(r\left ( x\right ) \) is any reference solution which only needs to satisfy the nonhomogeneous boundary conditions: \(r^{\prime }\left ( 0\right ) =1,r^{\prime }\left ( \pi \right ) =-1\). By guessing, let \(r\left ( x\right ) =Ax+Bx^{2}\). Let see if this satisfies the boundary conditions. \(r^{\prime }=A+2Bx\). At \(x=0\) this implies \(1=A\). Hence \(r=x+Bx^{2}\). Now \(r^{\prime }=1+2Bx\). At \(x=\pi \) this gives \(-1=1+2B\pi \) or \(B=-\frac {1}{\pi }\). Therefore \[ r\left ( x\right ) =x-\frac {1}{\pi }x^{2}\] Substituting \(u=v\left ( x,t\right ) +r\left ( x\right ) \) into the PDE \(u_{t}=u_{xx}\) and noting that \(r^{\prime \prime }\left ( x\right ) =-\frac {2}{\pi }\) gives\begin {equation} v_{t}=v_{xx}-\frac {2}{\pi }\tag {1} \end {equation} PDE (1) is now solved using eigenfunction expansion. We need to find eigenfunctions and eigenvalues of \(v_{t}=v_{xx}\) with \(v_{x}\left ( 0,t\right ) =0,v_{x}\left ( \pi ,t\right ) =0\). This is known PDE and have eigenfunctions and eigenvalues as follows. For zero eigenvalue, the eigenfunction is an arbitrary constant. Say \(\beta \). let \(\beta =1\) since scale is not important.\[ \Phi _{0}\left ( x\right ) =1 \] And for \(n=1,2,3,\cdots \) \begin {align*} \Phi _{n}\left ( x\right ) & =\cos \left ( \sqrt {\lambda _{n}}x\right ) \\ & =\cos \left ( nx\right ) \end {align*}

with eigenvalues \(\lambda _{n}=n^{2}\) for \(n=1,2,3,\cdots \). Now we can eigenfunction expansion and assume the solution to (1) is \begin {equation} v\left ( x,t\right ) =\sum _{n=0}^{\infty }A_{n}\left ( t\right ) \Phi _{n}\left ( x\right ) \tag {2} \end {equation} Plugging this into the PDE (1) gives\[ \sum _{n=0}^{\infty }A_{n}^{\prime }\left ( t\right ) \Phi _{n}\left ( x\right ) =\sum _{n=0}^{\infty }A_{n}\left ( t\right ) \Phi _{n}^{\prime \prime }\left ( x\right ) -\frac {2}{\pi }\] But \(\Phi _{n}^{\prime \prime }\left ( x\right ) =-\lambda _{n}\Phi _{n}\left ( x\right ) \) and the above simplifies to\[ \sum _{n=0}^{\infty }A_{n}^{\prime }\left ( t\right ) \Phi _{n}\left ( x\right ) =-\sum _{n=0}^{\infty }A_{n}\left ( t\right ) \lambda _{n}\Phi _{n}\left ( x\right ) -\frac {2}{\pi }\] Since eigenfunctions are complete, we can expand \(\frac {2}{\pi }\) using them and the above becomes\begin {align} \sum _{n=0}^{\infty }A_{n}^{\prime }\left ( t\right ) \Phi _{n}\left ( x\right ) & =-\sum _{n=0}^{\infty }A_{n}\left ( t\right ) \lambda _{n}\Phi _{n}\left ( x\right ) -\sum _{n=0}^{\infty }C_{n}\Phi _{n}\left ( x\right ) \nonumber \\ A_{n}^{\prime }\left ( t\right ) \Phi _{n}\left ( x\right ) +A_{n}\left ( t\right ) \lambda _{n}\Phi _{n}\left ( x\right ) & =-C_{n}\Phi _{n}\left ( x\right ) \nonumber \\ A_{n}^{\prime }\left ( t\right ) +A_{n}\left ( t\right ) \lambda _{n} & =-C_{n}\tag {3} \end {align}

To find \(C_{n}\)\[ \sum _{n=0}^{\infty }C_{n}\Phi _{n}\left ( x\right ) =\frac {2}{\pi }\] For \(n=0\)\[ C_{0}\Phi _{0}\left ( x\right ) =\frac {2}{\pi }\] But \(\Phi _{0}\left ( x\right ) =1\), hence \[ C_{0}=\frac {2}{\pi }\] All other \(C_{m}\,\ \) for \(m>0\) are zero. Hence (3) becomes, for \(n=0\) (since \(\lambda _{0}=0\))\begin {align*} A_{0}^{\prime }\left ( t\right ) & =-\frac {2}{\pi }\\ A_{0}\left ( t\right ) & =-\frac {2}{\pi }t+B_{0} \end {align*}

Where \(B_{0}\) is integration constant. For \(n>0\) (3) becomes\[ A_{n}^{\prime }\left ( t\right ) +A_{n}\left ( t\right ) n^{2}=0 \] This has the solution\[ A_{n}\left ( t\right ) =B_{n}e^{-n^{2}t}\] Where \(B_{n}\) is constant of integration. Hence from (2)\begin {align*} v\left ( x,t\right ) & =\sum _{n=0}^{\infty }A_{n}\left ( t\right ) \Phi _{n}\left ( x\right ) \\ & =A_{0}\left ( t\right ) +\sum _{n=1}^{\infty }A_{n}\left ( t\right ) \Phi _{n}\left ( x\right ) \\ & =-\frac {2}{\pi }t+B_{0}+\sum _{n=1}^{\infty }B_{n}e^{-n^{2}t}\cos \left ( nx\right ) \end {align*}

Since \(u=v\left ( x,t\right ) +r\left ( x\right ) \) then the solution becomes\begin {equation} u\left ( x,t\right ) =\left ( x-\frac {1}{\pi }x^{2}\right ) -\frac {2}{\pi }t+B_{0}+\sum _{n=1}^{\infty }B_{n}e^{-n^{2}t}\cos \left ( nx\right ) \tag {4} \end {equation} At \(t=0\)\begin {equation} \sin \left ( x\right ) =\left ( x-\frac {1}{\pi }x^{2}\right ) +B_{0}+\sum _{n=1}^{\infty }B_{n}\cos \left ( nx\right ) \tag {5} \end {equation} case \(n=0\)\[ \int _{0}^{\pi }\sin \left ( x\right ) \cos \left ( \sqrt {\lambda _{0}}x\right ) dx=\int _{0}^{\pi }\left ( x-\frac {1}{\pi }x^{2}\right ) \cos \left ( \sqrt {\lambda _{0}}x\right ) dx+\int _{0}^{\pi }B_{0}\cos \left ( \sqrt {\lambda _{0}}x\right ) dx \] But \(\lambda _{0}=0\) hence\begin {align*} \int _{0}^{\pi }\sin \left ( x\right ) dx & =\int _{0}^{\pi }\left ( x-\frac {1}{\pi }x^{2}\right ) dx+\int _{0}^{\pi }B_{0}dx\\ 2 & =\frac {\pi ^{2}}{6}+B_{0}\pi \\ B_{0} & =\frac {2}{\pi }-\frac {\pi }{6} \end {align*}

For \(n>0\), Multiplying both sides of (5) by \(\cos \left ( mx\right ) \) and integrating\[ \int _{0}^{\pi }\sin \left ( x\right ) \cos \left ( mx\right ) dx=\int _{0}^{\pi }\left ( x-\frac {1}{\pi }x^{2}\right ) \cos \left ( mx\right ) dx+\sum _{n=1}^{\infty }B_{n}\int _{0}^{\pi }\cos \left ( nx\right ) \cos \left ( mx\right ) dx \] For \(m=1\)\begin {align*} 0 & =0+B_{1}\frac {\pi }{2}\\ B_{1} & =0 \end {align*}

For \(m>1\)\begin {align*} -\frac {1+\left ( -1\right ) ^{m}}{m^{2}\left ( -1+m^{2}\right ) } & =\frac {\pi }{2}B_{m}\\ B_{m} & =\frac {-2}{\pi }\left ( \frac {1}{m^{2}}\frac {\left ( -1\right ) ^{m}+1}{m^{2}-1}\right ) \end {align*}

Hence solution (4) becomes\begin {align*} u\left ( x,t\right ) & =\left ( x-\frac {1}{\pi }x^{2}\right ) -\frac {2}{\pi }t-\frac {\pi }{6}+\frac {2}{\pi }+\sum _{n=1}^{\infty }B_{n}e^{-n^{2}t}\cos \left ( nx\right ) \\ u\left ( x,t\right ) & =\left ( x-\frac {1}{\pi }x^{2}\right ) -\frac {2}{\pi }t-\frac {\pi }{6}+\frac {2}{\pi }+\sum _{n=2}^{\infty }\frac {-2}{\pi }\left ( \frac {1}{n^{2}}\frac {\left ( -1\right ) ^{n}+1}{n^{2}-1}\right ) e^{-n^{2}t}\cos \left ( nx\right ) \end {align*}

____________________________________________________________________________________

4.1.5.10 [225] Haberman 8.2.1 (a) (general case)

problem number 225

Added Nov 27, 2018

This is problem 8.2.1 part(a) from Richard Haberman applied partial differential equations 5th edition.

Solve the heat equation

\[ \frac { \partial u}{\partial t} = k \frac { \partial ^2 u}{\partial x^2} \]

For \(0<x<L\) and \(t>0\). The boundary conditions are \begin {align*} u(0,t) &= A \\ \frac { \partial u}{\partial x}(L,t) &= B \end {align*}

Initial condition is \(u(x,0)=f(x)\)

Mathematica

ClearAll["Global`*"]; 
pde =  D[u[x, t], t] == k*D[u[x, t], {x, 2}]; 
bc  = {u[0, t] == A, Derivative[1, 0][u][L, t] == B}; 
ic  = u[x, 0] == f[x]; 
sol =  AbsoluteTiming[TimeConstrained[DSolve[{pde, ic, bc}, u[x, t], x, t, Assumptions -> L > 0], 60*10]];
 

\[\left \{\left \{u(x,t)\to \sum _{K[1]=1}^\infty \frac {\sqrt {2} e^{-\frac {k \pi ^2 t (1-2 K[1])^2}{4 L^2}} \left (\int _0^L -\frac {\sqrt {2} (A+B x-f(x)) \sin \left (\frac {\pi x (2 K[1]-1)}{2 L}\right )}{\sqrt {L}} \, dx\right ) \sin \left (\frac {\pi x (2 K[1]-1)}{2 L}\right )}{\sqrt {L}}+A+B x\right \}\right \}\]

Maple

restart; 
interface(showassumed=0); 
pde :=  diff(u(x,t),t)=k*diff(u(x,t),x$2); 
ic  :=  u(x,0)=f(x); 
bc  := u(0,t)=A, eval( diff(u(x,t),x),x=L)=B; 
cpu_time := timelimit(60*10,CodeTools[Usage](assign('sol',pdsolve([pde,ic,bc],u(x,t)) assuming L>0),output='realtime'));
 

\[u \left (x , t\right ) = B x +A -2 \left (\sum _{n=0}^\infty \frac {\left (\int _{0}^{L}\left (B x +A -f \left (x \right )\right ) \sin \left (\frac {\left (2 n +1\right ) \pi x}{2 L}\right )d x \right ) {\mathrm e}^{-\frac {\pi ^{2} \left (2 n +1\right )^{2} k t}{4 L^{2}}} \sin \left (\frac {\left (2 n +1\right ) \pi x}{2 L}\right )}{L}\right )\]

Hand solution

Let \begin {equation} u\left ( x,t\right ) =v\left ( x,t\right ) +u_{E}\left ( x\right ) \tag {1} \end {equation} We can look for \(u_{E}\left ( x\right ) \) which is the steady state solution that satisfies the non-homogenous boundary conditions. In (1) \(v\left ( x,t\right ) \) satisfies the PDE itself but with homogenous boundary conditions. The first step is to find \(u_{E}\left ( x\right ) \). We use the equilibrium solution in this case. At equilibrium \(\frac {\partial u_{E}\left ( x,t\right ) }{\partial t}=0\) and hence the solution is given \(\frac {d^{2}u_{E}}{\partial x^{2}}=0\) or \[ u_{E}\left ( x\right ) =c_{1}x+c_{2}\] At \(x=0,u_{E}\left ( x\right ) =A\), Hence \[ c_{2}=A \] And solution becomes \(u_{E}\left ( x\right ) =c_{1}x+A\). at \(x=L,\frac {\partial u_{E}\left ( x\right ) }{\partial x}=c_{1}=B\), Therefore\[ u_{E}\left ( x\right ) =Bx+A \] Now we plug-in (1) into the original PDE, this gives\[ \frac {\partial v\left ( x,t\right ) }{\partial t}=k\left ( \frac {\partial ^{2}v\left ( x,t\right ) }{\partial x}+\frac {\partial ^{2}u_{E}\left ( x\right ) }{\partial x}\right ) \] But \(\frac {\partial ^{2}u_{E}\left ( x\right ) }{\partial x}=0\), hence we need to solve \[ \frac {\partial v\left ( x,t\right ) }{\partial t}=k\frac {\partial ^{2}v\left ( x,t\right ) }{\partial x}\] for \(v\left ( x,t\right ) =u\left ( x,t\right ) -u_{E}\left ( x\right ) \) with homogenous boundary conditions \(v\left ( 0,t\right ) =0,\frac {\partial v\left ( L,t\right ) }{\partial t}=0\) and initial conditions \begin {align*} v\left ( x,0\right ) & =u\left ( x,0\right ) -u_{E}\left ( x\right ) \\ & =f\left ( x\right ) -\left ( Bx+A\right ) \end {align*}

This PDE we already solved before and we know that it has the following solution\begin {align} v\left ( x,t\right ) & =\sum _{n=1,3,5,\cdots }^{\infty }b_{n}\sin \left ( \sqrt {\lambda _{n}}x\right ) e^{-k\lambda _{n}t}\nonumber \\ \lambda _{n} & =\left ( \frac {n\pi }{2L}\right ) ^{2}\qquad n=1,3,5,\cdots \tag {2} \end {align}

With \(b_{n}\) found from orthogonality using initial conditions \(v\left ( x,0\right ) =f\left ( x\right ) -\left ( Bx+A\right ) \)\begin {align*} v\left ( x,0\right ) & =\sum _{n=1,3,5,\cdots }^{\infty }b_{n}\sin \left ( \sqrt {\lambda _{n}}x\right ) \\ \int _{0}^{L}\left ( f\left ( x\right ) -\left ( Bx+A\right ) \right ) \sin \left ( \sqrt {\lambda _{m}}x\right ) dx & =\int _{0}^{L}\sum _{n=1,3,5,\cdots }^{\infty }b_{n}\sin \left ( \sqrt {\lambda _{n}}x\right ) \sin \left ( \sqrt {\lambda _{m}}x\right ) dx\\ \int _{0}^{L}\left ( f\left ( x\right ) -\left ( Bx+A\right ) \right ) \sin \left ( \sqrt {\lambda _{m}}x\right ) dx & =b_{m}\frac {L}{2} \end {align*}

Hence\begin {equation} b_{n}=\frac {2}{L}\int _{0}^{L}\left ( f\left ( x\right ) -\left ( Bx+A\right ) \right ) \sin \left ( \sqrt {\lambda _{n}}x\right ) dx\qquad n=1,3,5,\cdots \tag {3} \end {equation} Therefore, from (1) the solution is\begin {align*} u\left ( x,t\right ) & =\sum _{n=1,3,5,\cdots }^{\infty }b_{n}\sin \left ( \sqrt {\lambda _{n}}x\right ) e^{-k\lambda _{n}t}+\overset {u_{E}\left ( x\right ) }{\overbrace {Bx+A}}\\ & =Bx+A+\sum _{n=1,3,5,\cdots }^{\infty }\left ( \frac {2}{L}\int _{0}^{L}\left ( f\left ( x\right ) -\left ( Bx+A\right ) \right ) \sin \left ( \sqrt {\frac {n\pi }{L}}x\right ) dx\right ) \sin \left ( \sqrt {\frac {n\pi }{L}}x\right ) e^{-k\left ( \frac {n\pi }{L}\right ) ^{2}t} \end {align*}

Or

\[ u\left ( x,t\right ) =Bx+A+\sum _{n=0}^{\infty }\left ( \frac {2}{L}\int _{0}^{L}\left ( f\left ( x\right ) -\left ( Bx+A\right ) \right ) \sin \left ( \sqrt {\frac {\left ( 2n+1\right ) \pi }{2L}}x\right ) dx\right ) \sin \left ( \sqrt {\frac {\left ( 2n+1\right ) \pi }{2L}}x\right ) e^{-k\left ( \frac {\left ( 2n+1\right ) \pi }{2L}\right ) ^{2}t}\]

____________________________________________________________________________________

4.1.5.11 [226] Haberman 8.2.1 (d) (general solution)

problem number 226

This is problem 8.2.1 part(d) from Richard Haberman applied partial differential equations 5th edition.

Solve the heat equation \[ \frac { \partial u}{\partial t} = k \frac { \partial ^2 u}{\partial x^2} + k \] For \(0<x<1\) and \(t>0\). The boundary conditions are \begin {align*} u(0,t) &= A \\ u(L,t) &= B \end {align*}

Initial condition is \(u(x,0)=f(x)\)

Mathematica

ClearAll["Global`*"]; 
pde =  D[u[x, t], t] == k*D[u[x, t], {x, 2}] + k; 
bc  = {u[0, t] == A0, u[L0, t] == B0}; 
ic  = u[x, 0] == f[x]; 
sol =  AbsoluteTiming[TimeConstrained[DSolve[{pde, ic, bc}, u[x, t], x, t], 60*10]];
 

\[\left \{\left \{u(x,t)\to \sum _{K[1]=1}^\infty -\frac {e^{-\frac {k \pi ^2 t K[1]^2}{\text {L0}^2}} \left (2 \left (-1+(-1)^{K[1]}\right ) \left (-1+e^{\frac {k \pi ^2 t K[1]^2}{\text {L0}^2}}\right ) \text {L0}^2-\sqrt {2} \sqrt {\frac {1}{\text {L0}}} \pi ^3 \left (\int _0^{\text {L0}} \sqrt {2} \left (\frac {1}{\text {L0}}\right )^{3/2} (-\text {A0} \text {L0}+f(x) \text {L0}+\text {A0} x-\text {B0} x) \sin \left (\frac {\pi x K[1]}{\text {L0}}\right ) \, dx\right ) K[1]^3\right ) \sin \left (\frac {\pi x K[1]}{\text {L0}}\right )}{\pi ^3 K[1]^3}+\frac {x (\text {B0}-\text {A0})}{\text {L0}}+\text {A0}\right \}\right \}\]

Maple

restart; 
interface(showassumed=0); 
pde :=  diff(u(x,t),t)=k*diff(u(x,t),x$2)+k; 
ic  :=  u(x,0)=f(x); 
bc  :=  u(0,t)=A, u(L,t)=B; 
cpu_time := timelimit(60*10,CodeTools[Usage](assign('sol',pdsolve([pde,ic,bc],u(x,t))),output='realtime'));
 

\[u \left (x , t\right ) = -\frac {x^{2}}{2}+A +\sum _{n=1}^\infty \left (-\frac {\left (\int _{0}^{L}2 \left (\frac {L^{2} x}{2}-L f \left (x \right )+\left (-\frac {x^{2}}{2}+A \right ) L -\left (A -B \right ) x \right ) \sin \left (\frac {\pi n x}{L}\right )d x \right ) {\mathrm e}^{-\frac {\pi ^{2} k \,n^{2} t}{L^{2}}} \sin \left (\frac {\pi n x}{L}\right )}{L^{2}}\right )+\frac {\left (L^{2}-2 A +2 B \right ) x}{2 L}\]

Hand solution

Let \begin {equation} u\left ( x,t\right ) =v\left ( x,t\right ) +u_{E}\left ( x\right ) \tag {1} \end {equation} Where \(u_{E}\left ( x\right ) \) is the equilibrium solution which needs to satisfy only the nonhomogeneous B.C. And \(v\left ( x,t\right ) \) is transient solution to heat PDE with homogeneous B.C.

At equilibrium, \(u_{t}=ku_{xx}+Q\left ( x\right ) \) becomes\begin {align*} 0 & =ku_{E}^{\prime \prime }+Q\left ( x\right ) \\ & =ku_{E}^{\prime \prime }+k\\ & =k\left ( u_{E}^{\prime \prime }+1\right ) \end {align*}

Hence\[ u_{E}^{\prime \prime }=-1 \] The solution to this ODE is \[ u_{E}=c_{1}x+c_{2}-\frac {1}{2}x^{2}\] At \(x=0\), the above gives\[ A=c_{2}\] And at \(x=L\)\begin {align*} B & =c_{1}L+A-\frac {1}{2}L^{2}\\ c_{1} & =\frac {B-A+\frac {1}{2}L^{2}}{L}\\ & =\frac {B}{L}-\frac {A}{L}+\frac {1}{2}L \end {align*}

Hence \[ u_{E}=\left ( \frac {B}{L}-\frac {A}{L}+\frac {1}{2}L\right ) x+A-\frac {1}{2}x^{2}\] Hence from (1)\begin {align} u\left ( x,t\right ) & =v\left ( x,t\right ) +u_{E}\tag {1A}\\ & =v\left ( x,t\right ) +\left ( \frac {B}{L}-\frac {A}{L}+\frac {1}{2}L\right ) x+A-\frac {1}{2}x^{2}\nonumber \end {align}

Substituting this in \(u_{t}=ku_{xx}+k\) gives\begin {align} v_{t} & =k\left ( v_{xx}-1\right ) +k\nonumber \\ & =kv_{xx}\tag {2} \end {align}

We need to solve the above for \(v\left ( x,t\right ) \), but with homogeneous B.C. \(v\left ( 0,t\right ) =0,v\left ( L,t\right ) =0\). The eigenvalues for the homogeneous PDE \(v_{t}=kv_{xx}\) with these boundary conditions is known to be \(\lambda _{n}=\left ( \frac {n\pi }{L}\right ) ^{2}\,\), for \(n=1,2,\cdots \) and the corresponding eigenfunctions are \(X_{n}\left ( x\right ) =\sin \left ( \sqrt {\lambda _{n}}x\right ) \). Now, using eigenfunction expansion, let\begin {equation} v\left ( x,t\right ) =\sum _{n=1}^{\infty }b_{n}\left ( t\right ) X_{n}\left ( x\right ) \tag {3} \end {equation} Substituting (3) into (2) gives\[ \sum _{n=1}^{\infty }b_{n}^{\prime }\left ( t\right ) X_{n}\left ( x\right ) =k\sum _{n=1}^{\infty }b_{n}\left ( t\right ) X_{n}^{\prime \prime }\left ( x\right ) \] But \(X_{n}^{\prime \prime }\left ( x\right ) =-\lambda _{n}X_{n}\left ( x\right ) \), therefore the above becomes\[ \sum _{n=1}^{\infty }b_{n}^{\prime }\left ( t\right ) X_{n}\left ( x\right ) +k\sum _{n=1}^{\infty }\lambda _{n}b_{n}\left ( t\right ) X_{n}\left ( x\right ) =0 \] Since the above is true for each \(n\) and since eigenfunctions can not be zero, the above simplifies to\begin {equation} b_{n}^{\prime }\left ( t\right ) +k\lambda _{n}b_{n}\left ( t\right ) =0\tag {4} \end {equation} This is linear in \(b\left ( t\right ) \). The solution using integrating factor is\[ b_{n}\left ( t\right ) =b_{0}\left ( 0\right ) e^{-k\left ( \frac {n\pi }{L}\right ) ^{2}t}\] Therefore (3) becomes\begin {align*} v\left ( x,t\right ) & =\sum _{n=1}^{\infty }b_{n}\left ( t\right ) X_{n}\left ( x\right ) \\ & =\sum _{n=1}^{\infty }b_{0}\left ( 0\right ) e^{-k\left ( \frac {n\pi }{L}\right ) ^{2}t}\sin \left ( \frac {n\pi }{L}x\right ) \end {align*}

And from (1)\begin {align} u\left ( x,t\right ) & =v\left ( x,t\right ) +u_{E}\left ( x\right ) \nonumber \\ & =\overset {u_{E}}{\overbrace {\left ( \frac {B}{L}-\frac {A}{L}+\frac {1}{2}L\right ) x+A-\frac {1}{2}x^{2}}}+\sum _{n=1}^{\infty }b_{0}\left ( 0\right ) e^{-k\left ( \frac {n\pi }{L}\right ) ^{2}t}\sin \left ( \frac {n\pi }{L}x\right ) \tag {5} \end {align}

At \(t=0\) the above becomes\[ f\left ( x\right ) =\frac {Bx}{L}-\frac {Ax}{L}+\frac {1}{2}Lx+A-\frac {1}{2}x^{2}+\sum _{n=1}^{\infty }b_{0}\left ( 0\right ) \sin \left ( \frac {n\pi }{L}x\right ) \] For \(n>0\), and applying orthogonality\[ \int _{0}^{L}f\left ( x\right ) \sin \left ( \frac {n\pi }{L}x\right ) dx=\int _{0}^{L}\left ( \frac {Bx}{L}-\frac {Ax}{L}+\frac {1}{2}Lx+A-\frac {1}{2}x^{2}\right ) \sin \left ( \frac {n\pi }{L}x\right ) dx+\int _{0}^{L}b_{0}\left ( 0\right ) \sin ^{2}\left ( \frac {n\pi }{L}x\right ) dx \] Hence\[ \int _{0}^{L}\left ( f\left ( x\right ) -\left ( \frac {Bx}{L}-\frac {Ax}{L}+\frac {1}{2}Lx+A-\frac {1}{2}x^{2}\right ) \right ) \sin \left ( \frac {n\pi }{L}x\right ) dx=\frac {L}{2}b_{0}\left ( 0\right ) \] Therefore\[ b_{0}\left ( 0\right ) =\frac {2}{L}\int _{0}^{L}\left ( f\left ( x\right ) -\left ( \frac {Bx}{L}-\frac {Ax}{L}+\frac {1}{2}Lx+A-\frac {1}{2}x^{2}\right ) \right ) \sin \left ( \frac {n\pi }{L}x\right ) dx \] Substituting the above in (5) gives\begin {align*} u\left ( x,t\right ) & =\left ( \frac {Bx}{L}-\frac {Ax}{L}+\frac {1}{2}Lx+A-\frac {1}{2}x^{2}\right ) \\ & +\sum _{n=1}^{\infty }\left ( \frac {2}{L}\int _{0}^{L}\left ( f\left ( x\right ) -\left ( \frac {Bx}{L}-\frac {Ax}{L}+\frac {1}{2}Lx+A-\frac {1}{2}x^{2}\right ) \right ) \sin \left ( \frac {n\pi }{L}x\right ) dx\right ) e^{-k\frac {n\pi }{L}t}\sin \left ( \frac {n\pi }{L}x\right ) \end {align*}

____________________________________________________________________________________

4.1.5.12 [227] Both ends depend on time with source that depends on space only (general solution)

problem number 227

Added July 3, 2019

Solve the heat equation \[ u_t = k u_{xx} + Q(x) \] For \(0<x<L\) and \(t>0\). The boundary conditions are \begin {align*} u(0,t) &= A(t) \\ u(L,t) &= B(t) \end {align*}

Initial condition is \(u(x,0)=f(x)\)

Mathematica

ClearAll["Global`*"]; 
pde =  D[u[x, t], t] == k*D[u[x, t], {x, 2}] + Q[x]; 
bc  = {u[0, t] == A[t], u[L, t] == B[t]}; 
ic  = u[x, 0] == f[x]; 
sol =  AbsoluteTiming[TimeConstrained[DSolve[{pde, ic, bc}, u[x, t], {x, t},Assumptions->{L>0,k>0}], 60*10]];
 

\[\left \{\left \{u(x,t)\to \sum _{K[1]=1}^\infty \frac {\sqrt {2} \left (\int _0^t e^{-\frac {k \pi ^2 K[1]^2 (t-K[2])}{L^2}} \text {Integrate}\left [\frac {\sqrt {2} \sin \left (\frac {\pi x K[1]}{L}\right ) \left (L Q(x)+(x-L) A'(K[2])-x B'(K[2])\right )}{L^{3/2}},\{x,0,L\},\text {Assumptions}\to k>0\land L>0\right ] \, dK[2]+e^{-\frac {k \pi ^2 t K[1]^2}{L^2}} \int _0^L \frac {\sqrt {2} (-L A(0)+x A(0)-x B(0)+L f(x)) \sin \left (\frac {\pi x K[1]}{L}\right )}{L^{3/2}} \, dx\right ) \sin \left (\frac {\pi x K[1]}{L}\right )}{\sqrt {L}}+\frac {x (B(t)-A(t))}{L}+A(t)\right \}\right \}\]

Maple

restart; 
interface(showassumed=0); 
pde :=  diff(u(x,t),t)=k*diff(u(x,t),x$2)+Q(x); 
ic  :=  u(x,0)=f(x); 
bc  :=  u(0,t)=A(t), u(L,t)=B(t); 
cpu_time := timelimit(60*10,CodeTools[Usage](assign('sol',pdsolve([pde,ic,bc],u(x,t)) assuming L>0,k>0),output='realtime'));
 

time expired Possible bug. Maple can solve with \(Q(x,t)\) source but not with \(Q(x)\)

Hand solution

Solve \begin {align*} u_{t} & =ku_{xx}+Q\left ( x\right ) \\ u\left ( 0,t\right ) & =A\left ( t\right ) \\ u\left ( L,0\right ) & =B\left ( t\right ) \\ u\left ( x,0\right ) & =f\left ( x\right ) \end {align*}

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 a reference solution \(r\left ( x,t\right ) \) which only needs to satisfy the B.C. Let the total solution be\begin {equation} u\left ( x,t\right ) =v\left ( x,t\right ) +r\left ( x,t\right ) \tag {2} \end {equation} Where \(v\left ( x,t\right ) \) is the transient solution which satisfies the homogeneous B.C. One can easily see that the reference function is\begin {equation} r\left ( x,t\right ) =A\left ( t\right ) +\frac {B\left ( t\right ) -A\left ( t\right ) }{L}x\tag {3} \end {equation} Substituting (1) back into the original PDE gives\begin {align*} \frac {\partial }{\partial t}\left ( v\left ( x,t\right ) +r\left ( x,t\right ) \right ) & =k\frac {\partial ^{2}}{\partial x^{2}}\left ( v\left ( x,t\right ) +r\left ( x,t\right ) \right ) +Q\left ( x\right ) \\ v_{t}\left ( x,t\right ) +r_{t}\left ( x,t\right ) & =kv_{xx}\left ( x,t\right ) +kr_{xx}\left ( x,t\right ) +Q\left ( x\right ) \end {align*}

But \(r_{xx}\left ( x,t\right ) =0\) and \(r_{t}=A^{\prime }\left ( t\right ) +\frac {B^{\prime }\left ( t\right ) -A^{\prime }\left ( t\right ) }{L}x\) and PDE becomes\[ v_{t}\left ( x,t\right ) =kv_{xx}\left ( x,t\right ) -r_{t}\left ( x,t\right ) +Q\left ( x\right ) \] Let \begin {align} \tilde {Q}\left ( x\right ) & =Q\left ( x\right ) -r_{t}\left ( x,t\right ) \nonumber \\ & =Q\left ( x\right ) -\left ( A^{\prime }\left ( t\right ) +\frac {B^{\prime }\left ( t\right ) -A^{\prime }\left ( t\right ) }{L}x\right ) \tag {4} \end {align}

Therefore the problem has been transformed to\begin {align*} v_{t} & =kv_{xx}+\tilde {Q}\left ( x\right ) \\ v\left ( 0,t\right ) & =0\\ v\left ( L,t\right ) & =0\\ v\left ( 0,x\right ) & =F\left ( x\right ) \\ & =u\left ( x,0\right ) -r\left ( x,0\right ) \\ & =f\left ( x\right ) -\left ( A\left ( 0\right ) +\frac {B\left ( 0\right ) -A\left ( 0\right ) }{L}x\right ) \end {align*}

The basic solution for this type of PDE was already given in problem 4.1.1.11 on page 453 and the solution is

\begin {align*} v\left ( x,t\right ) & =\sum _{n=1}^{\infty }e^{-k\lambda _{n}t}\Phi _{n}\left ( x\right ) \left ( \frac {2}{L}\int _{0}^{L}F\left ( s\right ) \Phi _{n}\left ( s\right ) ds\right ) \\ & +\sum _{n=1}^{\infty }e^{-k\lambda _{n}t}\Phi _{n}\left ( x\right ) \left ( \int _{0}^{t}\frac {2}{L}e^{k\lambda _{n}\tau }\left ( \int _{0}^{L}Q\left ( s\right ) \Phi _{n}\left ( s\right ) ds\right ) d\tau \right ) \end {align*}

Where \begin {align*} \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 \end {align*}

Hence, using our \(\tilde {Q}\left ( x\right ) \) and \(F\left ( x\right ) \) found above into this solution gives

\begin {align*} v\left ( x,t\right ) & =\frac {2}{L}\sum _{n=1}^{\infty }e^{-k\left ( \frac {n\pi }{L}\right ) ^{2}t}\sin \left ( \frac {n\pi }{L}x\right ) \left ( \int _{0}^{L}\left ( f\left ( s\right ) -\left ( A\left ( 0\right ) +\frac {B\left ( 0\right ) -A\left ( 0\right ) }{L}s\right ) \right ) \sin \left ( \frac {n\pi }{L}s\right ) ds\right ) \\ & +\frac {2}{L}\sum _{n=1}^{\infty }e^{-k\left ( \frac {n\pi }{L}\right ) ^{2}t}\sin \left ( \frac {n\pi }{L}x\right ) \left ( \int _{0}^{t}e^{k\left ( \frac {n\pi }{L}\right ) ^{2}\tau }\left ( \int _{0}^{L}\left ( Q\left ( s\right ) -\left ( A^{\prime }\left ( \tau \right ) +\frac {B^{\prime }\left ( \tau \right ) -A^{\prime }\left ( \tau \right ) }{L}s\right ) \right ) \sin \left ( \frac {n\pi }{L}s\right ) ds\right ) d\tau \right ) \end {align*}

Since \(u\left ( x,t\right ) =v\left ( x,t\right ) +r\left ( x,t\right ) \) then the final solution is\begin {align*} u\left ( x,t\right ) & =A\left ( t\right ) +\frac {B\left ( t\right ) -A\left ( t\right ) }{L}x\\ & +\frac {2}{L}\sum _{n=1}^{\infty }e^{-k\left ( \frac {n\pi }{L}\right ) ^{2}t}\sin \left ( \frac {n\pi }{L}x\right ) \left ( \int _{0}^{L}\left ( f\left ( s\right ) -\left ( A\left ( 0\right ) +\frac {B\left ( 0\right ) -A\left ( 0\right ) }{L}s\right ) \right ) \sin \left ( \frac {n\pi }{L}s\right ) ds\right ) \\ & +\frac {2}{L}\sum _{n=1}^{\infty }e^{-k\left ( \frac {n\pi }{L}\right ) ^{2}t}\sin \left ( \frac {n\pi }{L}x\right ) \left ( \int _{0}^{t}e^{k\left ( \frac {n\pi }{L}\right ) ^{2}\tau }\left ( \int _{0}^{L}\left ( Q\left ( s\right ) -\left ( A^{\prime }\left ( \tau \right ) +\frac {B^{\prime }\left ( \tau \right ) -A^{\prime }\left ( \tau \right ) }{L}s\right ) \right ) \sin \left ( \frac {n\pi }{L}s\right ) ds\right ) d\tau \right ) \end {align*}

____________________________________________________________________________________

4.1.5.13 [228] Both ends depend on time with source that depends on space only (special case)

problem number 228

Added July 4, 2019

Solve the heat equation

\[ u_t = k u_{xx} + Q(x) \]

For \(0<x<L\) and \(t>0\). The boundary conditions are \begin {align*} u(0,t) &= A(t) \\ u(L,t) &= B(t) \end {align*}

Initial condition is \(u(x,0)=f(x)\) using these values \begin {align*} L&=2\\ k&=\frac {1}{10}\\ A(t)&=\sin (t)\\ B(t)&=2 \cos (t)\\ Q(x)&= x \\ f(x)&=x \end {align*}

Mathematica

ClearAll["Global`*"]; 
L=2; 
k=1/10; 
A=Sin[t]; 
B=Cos[t]; 
f=x; 
Q=x; 
pde =  D[u[x, t], t] == k*D[u[x, t], {x, 2}] + Q; 
bc  = {u[0, t] == A, u[L, t] == B}; 
ic  = u[x, 0] == f; 
sol =  AbsoluteTiming[TimeConstrained[DSolve[{pde, ic, bc}, u[x, t], {x, t}], 60*10]];
 

\[\left \{\left \{u(x,t)\to \sum _{K[1]=1}^\infty \left (-\frac {80 \left (\pi ^4 \cos (t) K[1]^4+40 \pi ^2 \sin (t) K[1]^2-e^{-\frac {1}{40} \pi ^2 t K[1]^2} \left (\pi ^4 K[1]^4+2 (-1)^{K[1]} \left (\pi ^4 K[1]^4-20 \pi ^2 K[1]^2+1600\right )\right )+(-1)^{K[1]} \left (\pi ^4 (\sin (t)+2) K[1]^4-40 \pi ^2 \cos (t) K[1]^2+3200\right )\right )}{\pi ^3 K[1]^3 \left (\pi ^4 K[1]^4+1600\right )}-\frac {2 (-1)^{K[1]} e^{-\frac {1}{40} \pi ^2 t K[1]^2}}{\pi K[1]}\right ) \sin \left (\frac {1}{2} \pi x K[1]\right )+\frac {1}{2} x (\cos (t)-\sin (t))+\sin (t)\right \}\right \}\]

Maple

restart; 
L:=2; 
k:=1/10; 
A:=sin(t); 
B:=cos(t); 
f:=x; 
Q:=x; 
pde :=  diff(u(x,t),t)=k*diff(u(x,t),x$2)+Q; 
ic  :=  u(x,0)=f; 
bc  :=  u(0,t)=A, u(L,t)=B; 
cpu_time := timelimit(60*10,CodeTools[Usage](assign('sol',pdsolve([pde,ic,bc],u(x,t)) ),output='realtime'));
 

\[u \left (x , t\right ) = -\frac {5 x^{3}}{3}-\frac {\left (-3 \cos \left (t \right )+3 \sin \left (t \right )-40\right ) x}{6}+\sum _{n=1}^\infty \left (-\frac {2 \left (40 \pi ^{2} \left (\pi ^{2} n^{2} \cos \left (t \right )+\left (\pi ^{2} n^{2} \sin \left (t \right )-40 \cos \left (t \right )\right ) \left (-1\right )^{n}+40 \sin \left (t \right )\right ) n^{2}+\left (-40 \pi ^{4} n^{4}+\left (\pi ^{6} n^{6}-80 \pi ^{4} n^{4}+3200 \pi ^{2} n^{2}-128000\right ) \left (-1\right )^{n}\right ) {\mathrm e}^{-\frac {\pi ^{2} n^{2} t}{40}}\right ) \sin \left (\frac {\pi n x}{2}\right )}{\pi ^{3} \left (\pi ^{4} n^{4}+1600\right ) n^{3}}\right )+\sin \left (t \right )\]

Hand solution

Solve \begin {align*} u_{t} & =ku_{xx}+Q\left ( x\right ) \\ u\left ( 0,t\right ) & =A\left ( t\right ) \\ u\left ( L,0\right ) & =B\left ( t\right ) \\ u\left ( x,0\right ) & =f\left ( x\right ) \end {align*}

With \(k=\frac {1}{10},L=2,f\left ( x\right ) =x,Q\left ( x\right ) =x,A\left ( t\right ) =\sin \left ( t\right ) ,B\left ( t\right ) =2\cos \left ( t\right ) \).

The general problem above was solved in 4.1.5.12 on page 751 and the solution is

\begin {align*} u\left ( x,t\right ) & =A\left ( t\right ) +\frac {B\left ( t\right ) -A\left ( t\right ) }{L}x\\ & +\frac {2}{L}\sum _{n=1}^{\infty }e^{-k\left ( \frac {n\pi }{L}\right ) ^{2}t}\sin \left ( \frac {n\pi }{L}x\right ) \left ( \int _{0}^{L}\left ( f\left ( s\right ) -\left ( A\left ( 0\right ) +\frac {B\left ( 0\right ) -A\left ( 0\right ) }{L}s\right ) \right ) \sin \left ( \frac {n\pi }{L}s\right ) ds\right ) \\ & +\frac {2}{L}\sum _{n=1}^{\infty }e^{-k\left ( \frac {n\pi }{L}\right ) ^{2}t}\sin \left ( \frac {n\pi }{L}x\right ) \left ( \int _{0}^{t}e^{k\left ( \frac {n\pi }{L}\right ) ^{2}\tau }\left ( \int _{0}^{L}\left ( Q\left ( s\right ) -\left ( A^{\prime }\left ( \tau \right ) +\frac {B^{\prime }\left ( \tau \right ) -A^{\prime }\left ( \tau \right ) }{L}s\right ) \right ) \sin \left ( \frac {n\pi }{L}s\right ) ds\right ) d\tau \right ) \end {align*}

Substituting the specific values given above into this solution gives\begin {align*} u\left ( x,t\right ) & =\sin \left ( t\right ) +\frac {2\cos \left ( t\right ) -\sin \left ( t\right ) }{2}x\\ & +\sum _{n=1}^{\infty }e^{-\frac {1}{10}\left ( \frac {n\pi }{2}\right ) ^{2}t}\sin \left ( \frac {n\pi }{2}x\right ) \left ( \int _{0}^{2}\left ( s-\left ( A\left ( 0\right ) +\frac {B\left ( 0\right ) -A\left ( 0\right ) }{2}s\right ) \right ) \sin \left ( \frac {n\pi }{2}s\right ) ds\right ) \\ & +\sum _{n=1}^{\infty }e^{-\frac {1}{10}\left ( \frac {n\pi }{2}\right ) ^{2}t}\sin \left ( \frac {n\pi }{2}x\right ) \int _{0}^{t}e^{\frac {1}{10}\left ( \frac {n\pi }{2}\right ) ^{2}\tau }\left ( \int _{0}^{2}\left ( s-\left ( A^{\prime }\left ( \tau \right ) +\frac {B^{\prime }\left ( \tau \right ) -A^{\prime }\left ( \tau \right ) }{2}s\right ) \right ) \sin \left ( \frac {n\pi }{2}s\right ) ds\right ) d\tau \end {align*}

But \(A\left ( 0\right ) =0,B\left ( 0\right ) =2,A^{\prime }\left ( t\right ) =\cos \left ( t\right ) ,B^{\prime }\left ( t\right ) =-2\sin \left ( t\right ) \) and the above becomes\begin {align*} u\left ( x,t\right ) & =\sin \left ( t\right ) +\frac {2\cos \left ( t\right ) -\sin \left ( t\right ) }{2}x\\ & +\sum _{n=1}^{\infty }e^{-\frac {1}{10}\left ( \frac {n\pi }{2}\right ) ^{2}t}\sin \left ( \frac {n\pi }{2}x\right ) \left ( \int _{0}^{2}\left ( s-\left ( 0+\frac {2-0}{2}s\right ) \right ) \sin \left ( \frac {n\pi }{2}s\right ) ds\right ) \\ & +\sum _{n=1}^{\infty }e^{-\frac {1}{10}\left ( \frac {n\pi }{2}\right ) ^{2}t}\sin \left ( \frac {n\pi }{2}x\right ) \int _{0}^{t}e^{\frac {1}{10}\left ( \frac {n\pi }{2}\right ) ^{2}\tau }\left ( \int _{0}^{2}\left ( s-\left ( \cos \left ( \tau \right ) +\left ( \frac {-2\sin \left ( \tau \right ) -\cos \left ( \tau \right ) }{2}\right ) s\right ) \right ) \sin \left ( \frac {n\pi }{2}s\right ) ds\right ) d\tau \end {align*}

Or\begin {align*} u\left ( x,t\right ) & =\sin \left ( t\right ) +\frac {2\cos \left ( t\right ) -\sin \left ( t\right ) }{2}x\\ & +\sum _{n=1}^{\infty }e^{-\frac {1}{10}\left ( \frac {n\pi }{2}\right ) ^{2}t}\sin \left ( \frac {n\pi }{2}x\right ) \int _{0}^{t}e^{\frac {1}{10}\left ( \frac {n\pi }{2}\right ) ^{2}\tau }\left ( \int _{0}^{2}\left ( s-\left ( \cos \left ( \tau \right ) -\left ( \frac {2\sin \left ( \tau \right ) +\cos \left ( \tau \right ) }{2}\right ) s\right ) \right ) \sin \left ( \frac {n\pi }{2}s\right ) ds\right ) d\tau \end {align*}

Animation is below

Source code used for the above

____________________________________________________________________________________

4.1.5.14 [229] Both ends depend on time with source that depends on time and space (general solution)

problem number 229

Added June 27, 2019

Solve the heat equation \[ u_t = k u_{xx} + Q(x,t) \] For \(0<x<L\) and \(t>0\). The boundary conditions are \begin {align*} u(0,t) &= A(t) \\ u(L,t) &= B(t) \end {align*}

Initial condition is \(u(x,0)=f(x)\)

Mathematica

ClearAll["Global`*"]; 
pde =  D[u[x, t], t] == k*D[u[x, t], {x, 2}] + Q[x,t]; 
bc  = {u[0, t] == A[t], u[L, t] == B[t]}; 
ic  = u[x, 0] == f[x]; 
sol =  AbsoluteTiming[TimeConstrained[DSolve[{pde, ic, bc}, u[x, t], {x, t},Assumptions->{L>0,k>0}], 60*10]];
 

\[\left \{\left \{u(x,t)\to \sum _{K[1]=1}^\infty \frac {\sqrt {2} \left (\int _0^t e^{-\frac {k \pi ^2 K[1]^2 (t-K[2])}{L^2}} \text {Integrate}\left [\frac {\sqrt {2} \sin \left (\frac {\pi x K[1]}{L}\right ) \left (L Q(x,K[2])+(x-L) A'(K[2])-x B'(K[2])\right )}{L^{3/2}},\{x,0,L\},\text {Assumptions}\to k>0\land L>0\right ] \, dK[2]+e^{-\frac {k \pi ^2 t K[1]^2}{L^2}} \int _0^L \frac {\sqrt {2} (-L A(0)+x A(0)-x B(0)+L f(x)) \sin \left (\frac {\pi x K[1]}{L}\right )}{L^{3/2}} \, dx\right ) \sin \left (\frac {\pi x K[1]}{L}\right )}{\sqrt {L}}+\frac {x (B(t)-A(t))}{L}+A(t)\right \}\right \}\]

Maple

restart; 
interface(showassumed=0); 
pde :=  diff(u(x,t),t)=k*diff(u(x,t),x$2)+Q(x,t); 
ic  :=  u(x,0)=f(x); 
bc  :=  u(0,t)=A(t), u(L,t)=B(t); 
cpu_time := timelimit(60*10,CodeTools[Usage](assign('sol',pdsolve([pde,ic,bc],u(x,t)) assuming L>0,k>0),output='realtime'));
 

\[u \left (x , t\right ) = \frac {L \left (\int _{0}^{t}\left (\sum _{n=1}^\infty \frac {2 \left (\int _{0}^{L}\left (-\frac {x \left (\frac {d}{d \tau }B \left (\tau \right )\right )}{L}+Q \left (x , \tau \right )-\left (-\frac {x}{L}+1\right ) \left (\frac {d}{d \tau }A \left (\tau \right )\right )\right ) \sin \left (\frac {\pi n x}{L}\right )d x \right ) {\mathrm e}^{-\frac {\pi ^{2} \left (t -\tau \right ) k \,n^{2}}{L^{2}}} \sin \left (\frac {\pi n x}{L}\right )}{L}\right )d \tau \right )+L \left (\sum _{n=1}^\infty \frac {2 \left (\int _{0}^{L}\frac {\left (L f \left (x \right )-B \left (0\right ) x +A \left (0\right ) \left (-L +x \right )\right ) \sin \left (\frac {\pi n x}{L}\right )}{L}d x \right ) {\mathrm e}^{-\frac {\pi ^{2} k \,n^{2} t}{L^{2}}} \sin \left (\frac {\pi n x}{L}\right )}{L}\right )+x B \left (t \right )+\left (L -x \right ) A \left (t \right )}{L}\]

Hand solution

Solve \begin {align*} u_{t} & =ku_{xx}+Q\left ( x,t\right ) \\ u\left ( 0,t\right ) & =A\left ( t\right ) \\ u\left ( L,0\right ) & =B\left ( t\right ) \\ u\left ( x,0\right ) & =f\left ( x\right ) \end {align*}

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 a reference solution \(r\left ( x,t\right ) \) which only needs to satisfy the B.C. Let the total solution be\begin {equation} u\left ( x,t\right ) =v\left ( x,t\right ) +r\left ( x,t\right ) \tag {2} \end {equation} Where \(v\left ( x,t\right ) \) is the transient solution which satisfies the homogeneous B.C. One can easily see that the reference function is\begin {equation} r\left ( x,t\right ) =A\left ( t\right ) +\frac {B\left ( t\right ) -A\left ( t\right ) }{L}x\tag {3} \end {equation} Substituting (1) back into the original PDE gives\begin {align*} \frac {\partial }{\partial t}\left ( v\left ( x,t\right ) +r\left ( x,t\right ) \right ) & =k\frac {\partial ^{2}}{\partial x^{2}}\left ( v\left ( x,t\right ) +r\left ( x,t\right ) \right ) +Q\left ( x,t\right ) \\ v_{t}\left ( x,t\right ) +r_{t}\left ( x,t\right ) & =kv_{xx}\left ( x,t\right ) +kr_{xx}\left ( x,t\right ) +Q\left ( x,t\right ) \end {align*}

But \(r_{xx}\left ( x,t\right ) =0\) and \(r_{t}=A^{\prime }\left ( t\right ) +\frac {B^{\prime }\left ( t\right ) -A^{\prime }\left ( t\right ) }{L}x\) and PDE becomes\[ v_{t}\left ( x,t\right ) =kv_{xx}\left ( x,t\right ) -r_{t}\left ( x,t\right ) +Q\left ( x,t\right ) \] Let \begin {align} \tilde {Q}\left ( x,t\right ) & =Q\left ( x,t\right ) -r_{t}\left ( x,t\right ) \nonumber \\ & =Q\left ( x,t\right ) -\left ( A^{\prime }\left ( t\right ) +\frac {B^{\prime }\left ( t\right ) -A^{\prime }\left ( t\right ) }{L}x\right ) \tag {4} \end {align}

Therefore the problem has been transformed to\begin {align*} v_{t} & =kv_{xx}+\tilde {Q}\left ( x,t\right ) \\ v\left ( 0,t\right ) & =0\\ v\left ( L,t\right ) & =0\\ v\left ( 0,x\right ) & =F\left ( x\right ) \\ & =u\left ( x,0\right ) -r\left ( x,0\right ) \\ & =f\left ( x\right ) -\left ( A\left ( 0\right ) +\frac {B\left ( 0\right ) -A\left ( 0\right ) }{L}x\right ) \end {align*}

The basic solution for this type of PDE was already given in problem 4.1.6.4 on page 806 and the solution is\begin {align*} v\left ( x,t\right ) & =\sum _{n=1}^{\infty }e^{-k\lambda _{n}t}\Phi _{n}\left ( x\right ) \left ( \frac {2}{L}\int _{0}^{L}F\left ( s\right ) \Phi _{n}\left ( s\right ) ds\right ) \\ & +\sum _{n=1}^{\infty }e^{-k\lambda _{n}t}\Phi _{n}\left ( x\right ) \left ( \int _{0}^{t}\frac {2}{L}e^{k\lambda _{n}\tau }\left ( \int _{0}^{L}\tilde {Q}\left ( s,\tau \right ) \Phi _{n}\left ( s\right ) ds\right ) d\tau \right ) \end {align*}

Where \begin {align*} \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 \end {align*}

Hence, using our \(\tilde {Q}\left ( x,\tau \right ) \) and \(F\left ( x\right ) \) found above into this solution gives

\begin {align*} v\left ( x,t\right ) & =\frac {2}{L}\sum _{n=1}^{\infty }e^{-k\left ( \frac {n\pi }{L}\right ) ^{2}t}\sin \left ( \frac {n\pi }{L}x\right ) \left ( \int _{0}^{L}\left ( f\left ( s\right ) -\left ( A\left ( 0\right ) +\frac {B\left ( 0\right ) -A\left ( 0\right ) }{L}s\right ) \right ) \sin \left ( \frac {n\pi }{L}s\right ) ds\right ) \\ & +\frac {2}{L}\sum _{n=1}^{\infty }e^{-k\left ( \frac {n\pi }{L}\right ) ^{2}t}\sin \left ( \frac {n\pi }{L}x\right ) \left ( \int _{0}^{t}e^{k\left ( \frac {n\pi }{L}\right ) ^{2}\tau }\left ( \int _{0}^{L}\left ( Q\left ( s,\tau \right ) -\left ( A^{\prime }\left ( \tau \right ) +\frac {B^{\prime }\left ( \tau \right ) -A^{\prime }\left ( \tau \right ) }{L}s\right ) \right ) \sin \left ( \frac {n\pi }{L}s\right ) ds\right ) d\tau \right ) \end {align*}

Since \(u\left ( x,t\right ) =v\left ( x,t\right ) +r\left ( x,t\right ) \) then the final solution is\begin {align*} u\left ( x,t\right ) & =A\left ( t\right ) +\frac {B\left ( t\right ) -A\left ( t\right ) }{L}x\\ & +\frac {2}{L}\sum _{n=1}^{\infty }e^{-k\left ( \frac {n\pi }{L}\right ) ^{2}t}\sin \left ( \frac {n\pi }{L}x\right ) \left ( \int _{0}^{L}\left ( f\left ( s\right ) -\left ( A\left ( 0\right ) +\frac {B\left ( 0\right ) -A\left ( 0\right ) }{L}s\right ) \right ) \sin \left ( \frac {n\pi }{L}s\right ) ds\right ) \\ & +\frac {2}{L}\sum _{n=1}^{\infty }e^{-k\left ( \frac {n\pi }{L}\right ) ^{2}t}\sin \left ( \frac {n\pi }{L}x\right ) \left ( \int _{0}^{t}e^{k\left ( \frac {n\pi }{L}\right ) ^{2}\tau }\left ( \int _{0}^{L}\left ( Q\left ( s,\tau \right ) -\left ( A^{\prime }\left ( \tau \right ) +\frac {B^{\prime }\left ( \tau \right ) -A^{\prime }\left ( \tau \right ) }{L}s\right ) \right ) \sin \left ( \frac {n\pi }{L}s\right ) ds\right ) d\tau \right ) \end {align*}

____________________________________________________________________________________

4.1.5.15 [230] Both ends depend on time with source present (special case)

problem number 230

Added June 27, 2019

Solve the heat equation \[ u_t = k u_{xx} + Q(x,t) \] For \(0<x<L\) and \(t>0\). The boundary conditions are \begin {align*} u(0,t) &= A(t) \\ u(L,t) &= B(t) \end {align*}

Initial condition is \(u(x,0)=f(x)\) using these values \begin {align*} L&=2\\ k&=\frac {1}{10}\\ A(t)&=\sin (t)\\ B(t)&=2 \cos (t)\\ Q(x,t)&= x t e^{-t} \cos (t) \\ f(x)&=x \end {align*}

Mathematica

ClearAll["Global`*"]; 
L=2; 
k=1/10; 
A=Sin[t]; 
B=Cos[t]; 
f=x; 
Q=x*t*Exp[-t]*Cos[t]; 
pde =  D[u[x, t], t] == k*D[u[x, t], {x, 2}] + Q; 
bc  = {u[0, t] == A, u[L, t] == B}; 
ic  = u[x, 0] == f; 
sol =  AbsoluteTiming[TimeConstrained[DSolve[{pde, ic, bc}, u[x, t], {x, t}], 60*10]];
 

\[\left \{\left \{u(x,t)\to \sum _{K[1]=1}^\infty \frac {2 e^{-\frac {1}{40} \pi ^2 t K[1]^2} \left (\frac {40 \left (-80 (-1)^{K[1]} \pi ^2 \left (\pi ^2 K[1]^2-80\right ) \left (\pi ^4 K[1]^4+1600\right ) K[1]^2-\left (40 (-1)^{K[1]}-\pi ^2 K[1]^2\right ) \left (\pi ^4 K[1]^4-80 \pi ^2 K[1]^2+3200\right )^2-e^{\frac {1}{40} t \left (\pi ^2 K[1]^2-40\right )} \left (\cos (t) \left (2 (-1)^{K[1]} \left (\pi ^4 K[1]^4+1600\right ) \left (t \left (\pi ^6 K[1]^6-120 \pi ^4 K[1]^4+6400 \pi ^2 K[1]^2-128000\right )-40 \pi ^2 K[1]^2 \left (\pi ^2 K[1]^2-80\right )\right )-e^t \left (40 (-1)^{K[1]}-\pi ^2 K[1]^2\right ) \left (\pi ^4 K[1]^4-80 \pi ^2 K[1]^2+3200\right )^2\right )+\left (e^t \left ((-1)^{K[1]} \pi ^2 K[1]^2+40\right ) \left (\pi ^4 K[1]^4-80 \pi ^2 K[1]^2+3200\right )^2+80 (-1)^{K[1]} \left (\pi ^4 K[1]^4+1600\right ) \left (t \left (\pi ^4 K[1]^4-80 \pi ^2 K[1]^2+3200\right )-80 \left (\pi ^2 K[1]^2-40\right )\right )\right ) \sin (t)\right )\right )}{\left (\pi ^4 K[1]^4+1600\right ) \left (\pi ^4 K[1]^4-80 \pi ^2 K[1]^2+3200\right )^2}+(-1)^{K[1]+1}\right ) \sin \left (\frac {1}{2} \pi x K[1]\right )}{\pi K[1]}+\frac {1}{2} x (\cos (t)-\sin (t))+\sin (t)\right \}\right \}\]

Maple

restart; 
L:=2; 
k:=1/10; 
A:=sin(t); 
B:=cos(t); 
f:=x; 
Q:=x*t*exp(-t)*cos(t); 
pde :=  diff(u(x,t),t)=k*diff(u(x,t),x$2)+Q; 
ic  :=  u(x,0)=f; 
bc  :=  u(0,t)=A, u(L,t)=B; 
cpu_time := timelimit(60*10,CodeTools[Usage](assign('sol',pdsolve([pde,ic,bc],u(x,t)) ),output='realtime'));
 

\[u \left (x , t\right ) = \frac {x \cos \left (t \right )}{2}+\sum _{n=1}^\infty \left (-\frac {2 \left (80 \left (\left (\pi ^{6} n^{6} t -120 \left (t +\frac {1}{3}\right ) \pi ^{4} n^{4}+6400 \left (t +\frac {1}{2}\right ) \pi ^{2} n^{2}-128000 t \right ) \cos \left (t \right )+40 \left (\pi ^{4} n^{4} t -80 \pi ^{2} \left (t +1\right ) n^{2}+3200 t +3200\right ) \sin \left (t \right )\right ) \left (\pi ^{4} n^{4}+1600\right ) \left (-1\right )^{n} {\mathrm e}^{-t}+\left (-40 \pi ^{2} \left (\pi ^{4} n^{4}-80 \pi ^{2} n^{2}+3200\right )^{2} n^{2}+\left (\pi ^{12} n^{12}-160 \pi ^{10} n^{10}+19200 \pi ^{8} n^{8}-1280000 \pi ^{6} n^{6}+56320000 \pi ^{4} n^{4}-2048000000 \pi ^{2} n^{2}+32768000000\right ) \left (-1\right )^{n}\right ) {\mathrm e}^{-\frac {\pi ^{2} n^{2} t}{40}}+40 \left (\pi ^{4} n^{4}-80 \pi ^{2} n^{2}+3200\right )^{2} \left (\pi ^{2} n^{2} \cos \left (t \right )+\left (\pi ^{2} n^{2} \sin \left (t \right )-40 \cos \left (t \right )\right ) \left (-1\right )^{n}+40 \sin \left (t \right )\right )\right ) \sin \left (\frac {\pi n x}{2}\right )}{\pi \left (\pi ^{4} n^{4}+1600\right ) \left (\pi ^{4} n^{4}-80 \pi ^{2} n^{2}+3200\right )^{2} n}\right )-\frac {\left (x -2\right ) \sin \left (t \right )}{2}\]

Hand solution

Solve \begin {align*} u_{t} & =ku_{xx}+Q\left ( x,t\right ) \\ u\left ( 0,t\right ) & =A\left ( t\right ) \\ u\left ( L,0\right ) & =B\left ( t\right ) \\ u\left ( x,0\right ) & =f\left ( x\right ) \end {align*}

With \(k=\frac {1}{10},L=2,f\left ( x\right ) =x,Q\left ( x,t\right ) =xte^{-t}\cos \left ( t\right ) ,A\left ( t\right ) =\sin \left ( t\right ) ,B\left ( t\right ) =2\cos \left ( t\right ) \).

The general problem above was solved in 4.1.5.14 on page 764 and the solution is\begin {align*} u\left ( x,t\right ) & =A\left ( t\right ) +\frac {B\left ( t\right ) -A\left ( t\right ) }{L}x\\ & +\frac {2}{L}\sum _{n=1}^{\infty }e^{-k\left ( \frac {n\pi }{L}\right ) ^{2}t}\sin \left ( \frac {n\pi }{L}x\right ) \left ( \int _{0}^{L}\left ( f\left ( s\right ) -\left ( A\left ( 0\right ) +\frac {B\left ( 0\right ) -A\left ( 0\right ) }{L}s\right ) \right ) \sin \left ( \frac {n\pi }{L}s\right ) ds\right ) \\ & +\frac {2}{L}\sum _{n=1}^{\infty }e^{-k\left ( \frac {n\pi }{L}\right ) ^{2}t}\sin \left ( \frac {n\pi }{L}x\right ) \int _{0}^{t}e^{k\left ( \frac {n\pi }{L}\right ) ^{2}\tau }\left ( \int _{0}^{L}\left ( Q\left ( s,\tau \right ) -\left ( A^{\prime }\left ( \tau \right ) +\frac {B^{\prime }\left ( \tau \right ) -A^{\prime }\left ( \tau \right ) }{L}x\right ) \right ) \sin \left ( \frac {n\pi }{L}s\right ) ds\right ) d\tau \end {align*}

Substituting the specific values given above into this solution gives\begin {align*} u\left ( x,t\right ) & =\sin \left ( t\right ) +\frac {2\cos \left ( t\right ) -\sin \left ( t\right ) }{2}x\\ & +\sum _{n=1}^{\infty }e^{-\frac {1}{10}\left ( \frac {n\pi }{2}\right ) ^{2}t}\sin \left ( \frac {n\pi }{2}x\right ) \left ( \int _{0}^{2}\left ( s-\left ( A\left ( 0\right ) +\frac {B\left ( 0\right ) -A\left ( 0\right ) }{2}s\right ) \right ) \sin \left ( \frac {n\pi }{2}s\right ) ds\right ) \\ & +\sum _{n=1}^{\infty }e^{-\frac {1}{10}\left ( \frac {n\pi }{2}\right ) ^{2}t}\sin \left ( \frac {n\pi }{2}x\right ) \int _{0}^{t}e^{\frac {1}{10}\left ( \frac {n\pi }{2}\right ) ^{2}\tau }\left ( \int _{0}^{2}\left ( s\tau e^{-\tau }\cos \left ( \tau \right ) -\left ( A^{\prime }\left ( \tau \right ) +\frac {B^{\prime }\left ( \tau \right ) -A^{\prime }\left ( \tau \right ) }{2}s\right ) \right ) \sin \left ( \frac {n\pi }{2}s\right ) ds\right ) d\tau \end {align*}

But \(A\left ( 0\right ) =0,B\left ( 0\right ) =2,A^{\prime }\left ( t\right ) =\cos \left ( t\right ) ,B^{\prime }\left ( t\right ) =-2\sin \left ( t\right ) \) and the above becomes\begin {align*} u\left ( x,t\right ) & =\sin \left ( t\right ) +\frac {2\cos \left ( t\right ) -\sin \left ( t\right ) }{2}x\\ & +\sum _{n=1}^{\infty }e^{-\frac {1}{10}\left ( \frac {n\pi }{2}\right ) ^{2}t}\sin \left ( \frac {n\pi }{2}x\right ) \left ( \int _{0}^{2}\left ( s-\left ( 0+\frac {2-0}{2}s\right ) \right ) \sin \left ( \frac {n\pi }{2}s\right ) ds\right ) \\ & +\sum _{n=1}^{\infty }e^{-\frac {1}{10}\left ( \frac {n\pi }{2}\right ) ^{2}t}\sin \left ( \frac {n\pi }{2}x\right ) \int _{0}^{t}e^{\frac {1}{10}\left ( \frac {n\pi }{2}\right ) ^{2}\tau }\left ( \int _{0}^{2}\left ( s\tau e^{-\tau }\cos \left ( \tau \right ) -\left ( \cos \left ( \tau \right ) +\left ( \frac {-2\sin \left ( \tau \right ) -\cos \left ( \tau \right ) }{2}\right ) s\right ) \right ) \sin \left ( \frac {n\pi }{2}s\right ) ds\right ) d\tau \end {align*}

Or\begin {align*} u\left ( x,t\right ) & =\sin \left ( t\right ) +\frac {2\cos \left ( t\right ) -\sin \left ( t\right ) }{2}x\\ & +\sum _{n=1}^{\infty }e^{-\frac {1}{10}\left ( \frac {n\pi }{2}\right ) ^{2}t}\sin \left ( \frac {n\pi }{2}x\right ) \int _{0}^{t}e^{\frac {1}{10}\left ( \frac {n\pi }{2}\right ) ^{2}\tau }\left ( \int _{0}^{2}\left ( s\tau e^{-\tau }\cos \left ( \tau \right ) -\left ( \cos \left ( \tau \right ) -\left ( \frac {2\sin \left ( \tau \right ) +\cos \left ( \tau \right ) }{2}\right ) s\right ) \right ) \sin \left ( \frac {n\pi }{2}s\right ) ds\right ) d\tau \end {align*}

Animation is below

Source code used for the above

____________________________________________________________________________________

4.1.5.16 [231] Pinchover and Rubinstein 6.17

problem number 231

Added July 2, 2018.

Pinchover and Rubinstein’s exercise 6.17. Taken from Maple document for new improvements in Maple 2018.1

Solve the heat equation

\[ {\frac {\partial }{\partial t}}u \left ( x,t \right ) -{\frac {\partial ^{2}}{\partial {x}^{2}}}u \left ( x,t \right ) =1+x\cos \left ( t\right ) \]

For \(0<x<1\) and \(t>0\). The boundary conditions are \begin {align*} \frac {\partial u}{\partial x}(0,t) &=\sin (t) \\ \frac {\partial u}{\partial x}(1,t) &=\sin (t) \end {align*}

Initial condition is \(u (x,0) =1+ \cos ( 2 \pi x)\).

Mathematica

ClearAll["Global`*"]; 
pde = D[u[x, t], x] == D[u[x, t], {x, 2}] + 1 + x*Cos[t]; 
bc  = {Derivative[1, 0][u][0, t] == Sin[t], Derivative[1, 0][u][1, t] == Sin[t]}; 
ic  = u[x, 0] == 1 + Cos[2*Pi*x]; 
sol =  AbsoluteTiming[TimeConstrained[Simplify[DSolve[{pde, ic, bc}, u[x, t], x, t]], 60*10]];
 

Failed

Maple

restart; 
pde := diff(u(x, t), t)= (diff(u(x, t), x, x)) + 1+x*cos(t); 
bc  := (D[1](u))(0, t) = sin(t), (D[1](u))(1, t) = sin(t); 
ic  := u(x, 0) = 1+cos(2*Pi*x); 
cpu_time := timelimit(60*10,CodeTools[Usage](assign('sol', pdsolve([pde, ic, bc],u(x,t))),output='realtime'));
 

\[u \left (x , t\right ) = x \sin \left (t \right )+\cos \left (2 \pi x \right ) {\mathrm e}^{-4 \pi ^{2} t}+t +1\]

____________________________________________________________________________________

4.1.5.17 [232] nonhomogeneous BC

problem number 232

Added March 28, 2018. A problem from my PDE animation page.

Solve the heat equation

\[ u_t = k u_{xx} + x \]

For \(0<x<\pi \) and \(t>0\). The boundary conditions are \begin {align*} u(0,t) &= \frac {t \sin t}{5} \\ u(\pi ,t) &= \frac {t \cos t}{10} \\ \end {align*}

Initial condition is \(u(x,0)=60 - 20 x\).

Mathematica

ClearAll["Global`*"]; 
pde =  D[u[x, t], t] == D[u[x, t], {x, 2}] + x; 
bc  = {u[0, t] == (t*Sin[t])/5, u[Pi, t] == (t*Cos[t])/10}; 
ic  = u[x, 0] == 60 - 2*x; 
sol =  AbsoluteTiming[TimeConstrained[DSolve[{pde, ic, bc}, u[x, t], x, t, Assumptions -> {t > 0, x > 0}], 60*10]];
 

\[\left \{\left \{u(x,t)\to \frac {10 \pi \sum _{K[1]=1}^\infty \frac {e^{-t K[1]^2} \left (20 \left (30+(-1)^{K[1]} (-30+\pi )\right ) K[1]^2+\frac {(-1)^{K[1]+1} K[1]^8+10 (-1)^{K[1]} \pi K[1]^8-10 (-1)^{K[1]} e^{t K[1]^2} \pi K[1]^8-4 K[1]^6+(-1)^{K[1]} K[1]^4+20 (-1)^{K[1]} \pi K[1]^4-20 (-1)^{K[1]} e^{t K[1]^2} \pi K[1]^4+e^{t K[1]^2} \cos (t) \left (\left ((-1)^{K[1]} K[1]^4+4 K[1]^2+(-1)^{K[1]+1}\right ) K[1]^2+t \left ((-1)^{K[1]}-2 K[1]^2\right ) \left (K[1]^4+1\right )\right ) K[1]^2-e^{t K[1]^2} \left (2 \left (K[1]^4+(-1)^{K[1]+1} K[1]^2-1\right ) K[1]^2+t \left ((-1)^{K[1]} K[1]^2+2\right ) \left (K[1]^4+1\right )\right ) \sin (t) K[1]^2+10 (-1)^{K[1]} \pi -10 (-1)^{K[1]} e^{t K[1]^2} \pi }{\left (K[1]^4+1\right )^2}\right ) \sin (x K[1])}{5 \pi K[1]^3}+2 t (\pi -x) \sin (t)+t x \cos (t)}{10 \pi }\right \}\right \}\]

Maple

restart; 
interface(showassumed=0); 
pde :=  diff(u(x,t),t)=diff(u(x,t),x$2)+x; 
ic  :=  u(x,0)=(60-2*x); 
bc  :=  u(0,t)=t/5*sin(t), u(Pi,t)=t/10*cos(t); 
cpu_time := timelimit(60*10,CodeTools[Usage](assign('sol', pdsolve([pde,ic,bc],u(x,t)) assuming t>0,x>0),output='realtime'));
 

\[u \left (x , t\right ) = \frac {\left (x \cos \left (t \right )+\left (-2 x +2 \pi \right ) \sin \left (t \right )\right ) t +2 \pi \left (\sum _{n=1}^\infty \frac {20 \left (-\frac {\left (\left (n^{4} t -2 n^{2}+t \right ) n^{2} \cos \left (t \right )+\left (n^{6}+n^{4} t -n^{2}+t \right ) \sin \left (t \right )\right ) n^{2}}{10}+\left (-\frac {\left (n^{4} t -2 n^{2}+t \right ) n^{4} \sin \left (t \right )}{20}+\frac {\left (n^{6}+n^{4} t -n^{2}+t \right ) n^{2} \cos \left (t \right )}{20}-\frac {\pi \left (n^{4}+1\right )^{2}}{2}\right ) \left (-1\right )^{n}+\left (30 n^{10}+\frac {299 n^{6}}{5}+30 n^{2}+\left (\left (\pi -30\right ) n^{10}+\left (\frac {\pi }{2}-\frac {1}{20}\right ) n^{8}+\left (2 \pi -60\right ) n^{6}+\left (\pi +\frac {1}{20}\right ) n^{4}+\left (\pi -30\right ) n^{2}+\frac {\pi }{2}\right ) \left (-1\right )^{n}\right ) {\mathrm e}^{-n^{2} t}\right ) \sin \left (n x \right )}{\pi \left (n^{4}+1\right )^{2} n^{3}}\right )}{10 \pi }\]

____________________________________________________________________________________

4.1.5.18 [233] Haberman 8.2.2. (a)

problem number 233

Added Nov 27, 2018.

Problem 8.2.2 part(a) from Richard Haberman applied partial differential equations book, 5th edition

Solve the heat equation for \(u(x,t)\)

\[ u_t=u_{xx} + Q(x,t) \]

For \(0<x<L\) and \(t>0\). The boundary conditions are \begin {align*} \frac { \partial u}{\partial x}(0,t) &= A(t) \\ \frac { \partial u}{\partial x}(L,t) &= B(t)\\ \end {align*}

Initial condition is \(u(x,0)=f(x)\)

For hand solution see my HW9, Math 322, UW Madison. The text does not actually asks to solve this PDE but only to reduce the problem to one with homogeneous B.C.

Mathematica

ClearAll["Global`*"]; 
pde =  D[u[x, t], t] == k*D[u[x, t], {x, 2}] + Q[x, t]; 
bc  = {Derivative[1, 0][u][0, t] == A[t], Derivative[1, 0][u][L, t] == B[t]}; 
ic  = u[x, 0] == f[x]; 
sol =  AbsoluteTiming[TimeConstrained[DSolve[{pde, ic, bc}, u[x, t], x, t, Assumptions -> L > 0], 60*10]];
 

\[\left \{\left \{u(x,t)\to \sum _{K[1]=1}^\infty \frac {\sqrt {2} \cos \left (\frac {\pi x K[1]}{L}\right ) \left (e^{-\frac {k \pi ^2 t K[1]^2}{L^2}} \int _0^L \frac {\cos \left (\frac {\pi x K[1]}{L}\right ) (x (x (A(0)-B(0))-2 L A(0))+2 L f(x))}{\sqrt {2} L^{3/2}} \, dx+\int _0^t e^{-\frac {k \pi ^2 K[1]^2 (t-K[2])}{L^2}} \text {Integrate}\left [\frac {\cos \left (\frac {\pi x K[1]}{L}\right ) \left (A'(K[2]) x^2-B'(K[2]) x^2-2 L A'(K[2]) x-2 k A(K[2])+2 k B(K[2])+2 L Q(x,K[2])\right )}{\sqrt {2} L^{3/2}},\{x,0,L\},\text {Assumptions}\to L>0\right ] \, dK[2]\right )}{\sqrt {L}}+\frac {\int _0^t \text {Integrate}\left [\frac {2 L Q(x,K[2])-2 L x A'(K[2])+x^2 A'(K[2])-2 k A(K[2])-x^2 B'(K[2])+2 k B(K[2])}{2 L^{3/2}},\{x,0,L\},\text {Assumptions}\to L>0\right ] \, dK[2]+\int _0^L \frac {-2 A(0) L x+A(0) x^2-B(0) x^2+2 L f(x)}{2 L^{3/2}} \, dx}{\sqrt {L}}+\frac {x^2 (B(t)-A(t))}{2 L}+x A(t)\right \}\right \}\]

Maple

restart; 
interface(showassumed=0); 
pde :=  diff(u(x,t),t)+k*diff(u(x,t),x$2)+Q(x,t); 
ic  :=  u(x,0)=f(x); 
bc  := eval( diff(u(x,t),x),x=0)=A(t), eval( diff(u(x,t),x),x=L)=B(t); 
cpu_time := timelimit(60*10,CodeTools[Usage](assign('sol', pdsolve([pde,ic,bc],u(x,t)) assuming L>0),output='realtime'));
 

\[u \left (x , t\right ) = \frac {x^{2} B \left (t \right )}{2 L}+\left (-\frac {x^{2}}{2 L}+x \right ) A \left (t \right )+\int _{0}^{t}\left (\left (\sum _{n=1}^\infty \frac {2 \left (\int _{0}^{L}-\frac {\left (\frac {x^{2} \left (\frac {d}{d \tau }B \left (\tau \right )\right )}{2}+L Q \left (x , \tau \right )+\left (L -\frac {x}{2}\right ) x \left (\frac {d}{d \tau }A \left (\tau \right )\right )-\left (A \left (\tau \right )-B \left (\tau \right )\right ) k \right ) \cos \left (\frac {\pi n x}{L}\right )}{L}d x \right ) \cos \left (\frac {\pi n x}{L}\right ) {\mathrm e}^{\frac {\pi ^{2} \left (t -\tau \right ) k \,n^{2}}{L^{2}}}}{L}\right )+\frac {\int _{0}^{L}\frac {-x^{2} \left (\frac {d}{d \tau }B \left (\tau \right )\right )-2 L Q \left (x , \tau \right )+2 \left (A \left (\tau \right )-B \left (\tau \right )\right ) k +\left (-2 L x +x^{2}\right ) \left (\frac {d}{d \tau }A \left (\tau \right )\right )}{2 L}d x}{L}\right )d \tau +\left (\sum _{n=1}^\infty \frac {2 \left (\int _{0}^{L}\frac {\left (2 L f \left (x \right )-B \left (0\right ) x^{2}+\left (-2 L x +x^{2}\right ) A \left (0\right )\right ) \cos \left (\frac {\pi n x}{L}\right )}{2 L}d x \right ) \cos \left (\frac {\pi n x}{L}\right ) {\mathrm e}^{\frac {\pi ^{2} k \,n^{2} t}{L^{2}}}}{L}\right )+\frac {\int _{0}^{L}\frac {2 L f \left (x \right )-B \left (0\right ) x^{2}+\left (-2 L x +x^{2}\right ) A \left (0\right )}{2 L}d x}{L}\]

Hand solution

Solve \begin {align*} u_{t} & =ku_{xx}+Q\left ( x,t\right ) \\ u_{x}\left ( 0,t\right ) & =A\left ( t\right ) \\ u_{x}\left ( L,0\right ) & =B\left ( t\right ) \\ u\left ( x,0\right ) & =f\left ( x\right ) \end {align*}

Let \begin {equation} u\left ( x,t\right ) =v\left ( x,t\right ) +r\left ( x,t\right ) \tag {1} \end {equation} Since the problem has time dependent source function \(Q\left ( x,t\right ) \) then \(r\left ( x,t\right ) \) is now a reference function that only needs to satisfy the non-homogenous boundary conditions which in this problem are at both ends and \(v\left ( x,t\right ) \) has homogenous boundary conditions. The first step is to find \(r\left ( x,t\right ) \). Let\[ r\left ( x,t\right ) =c_{1}\left ( t\right ) x+c_{2}\left ( t\right ) x^{2}\] Then\[ \frac {\partial r\left ( x,t\right ) }{\partial x}=c_{1}\left ( t\right ) +2c_{2}\left ( t\right ) x \] At \(x=0\)\[ A\left ( t\right ) =c_{1}\left ( t\right ) \] And at \(x=L\)\begin {align*} B\left ( t\right ) & =c_{1}\left ( t\right ) +2c_{2}\left ( t\right ) L\\ c_{2}\left ( t\right ) & =\frac {B\left ( t\right ) -c_{1}\left ( t\right ) }{2L} \end {align*}

Solving for \(c_{1},c_{2}\) gives\begin {equation} r\left ( x,t\right ) =A\left ( t\right ) x+\left ( \frac {B\left ( t\right ) -A\left ( t\right ) }{2L}\right ) x^{2} \tag {2} \end {equation} Replacing (1) into the original PDE \(u_{t}=ku_{xx}+Q\left ( x,t\right ) \) gives\begin {align*} \frac {\partial }{\partial t}\left ( v\left ( x,t\right ) -r\left ( x,t\right ) \right ) & =k\frac {\partial ^{2}}{\partial x}\left ( v\left ( x,t\right ) -r\left ( x,t\right ) \right ) +Q\left ( x,t\right ) \\ \frac {\partial v}{\partial t}-\frac {\partial r}{\partial t} & =k\frac {\partial ^{2}v}{\partial x^{2}}-k\frac {\partial ^{2}r}{\partial x^{2}}+Q\left ( x,t\right ) \end {align*}

But \(r_{xx}=\frac {B\left ( t\right ) -A\left ( t\right ) }{L}\), hence the above reduces to\begin {equation} v_{t}=kv_{xx}+Q\left ( x,t\right ) -k\frac {B\left ( t\right ) -A\left ( t\right ) }{L}+r_{t} \tag {3} \end {equation} Let \[ \tilde {Q}\left ( x,t\right ) =Q\left ( x,t\right ) +r_{t}-k\frac {B\left ( t\right ) -A\left ( t\right ) }{L}\] Then (3) becomes\begin {align} v_{t} & =kv_{xx}+\tilde {Q}\left ( x,t\right ) \tag {4}\\ v_{t}\left ( 0,t\right ) & =0\nonumber \\ v_{t}\left ( L,t\right ) & =0\nonumber \end {align}

And initial condition is \begin {align*} v\left ( x,0\right ) & =F\left ( x\right ) \\ & =u\left ( x,0\right ) -r\left ( x,0\right ) \\ & =f\left ( x\right ) -\left ( A\left ( 0\right ) x+\left ( \frac {B\left ( 0\right ) -A\left ( 0\right ) }{2L}\right ) x^{2}\right ) \end {align*}

PDE (4) with its homogenous boundary conditions is standard one, its corresponding eigenvalue boundary value ODE \(X^{\prime \prime }+\lambda X=0\) has \(\lambda =0\) as eigenvalue with corresponding eigenfunction \(\Phi _{0}\left ( x\right ) =1\) and \(\lambda _{n}=\left ( \frac {n\pi }{L}\right ) ^{2}\) for \(n=1,2,3,\cdots \) with corresponding eigenfunctions \(\Phi _{n}\left ( x\right ) =\cos \left ( \sqrt {\lambda _{n}}x\right ) \). Using these, we can write the solution to (4) using eigenfunction expansion as\begin {equation} v\left ( x,t\right ) =\sum _{n=0}^{\infty }c_{n}\left ( t\right ) \Phi _{n}\left ( x\right ) \tag {4A} \end {equation} Hence \(v_{t}\left ( x,t\right ) =\sum _{n=0}^{\infty }c_{n}^{\prime }\left ( t\right ) \Phi _{n}\left ( x\right ) \) and \(v_{xx}\left ( x,t\right ) =\sum _{n=0}^{\infty }c_{n}\left ( t\right ) \Phi _{n}^{\prime \prime }\left ( x\right ) \). Substituting these into (4) gives\[ \sum _{n=0}^{\infty }c_{n}^{\prime }\left ( t\right ) \Phi _{n}\left ( x\right ) =\sum _{n=0}^{\infty }c_{n}\left ( t\right ) \Phi _{n}^{\prime \prime }\left ( x\right ) +\tilde {Q}\left ( x,t\right ) \] Expanding \(\tilde {Q}\left ( x,t\right ) \) using same eigenfunctions since they are complete, the above becomes\[ \sum _{n=0}^{\infty }c_{n}^{\prime }\left ( t\right ) \Phi _{n}\left ( x\right ) =\sum _{n=0}^{\infty }c_{n}\left ( t\right ) \Phi _{n}^{\prime \prime }\left ( x\right ) +\sum _{n=0}^{\infty }b_{n}\left ( t\right ) \Phi _{n}\left ( x\right ) \] But \(\Phi _{n}^{\prime \prime }\left ( x\right ) =-\lambda _{n}\Phi _{n}\left ( x\right ) \) and the above becomes\begin {align} \sum _{n=0}^{\infty }c_{n}^{\prime }\left ( t\right ) \Phi _{n}\left ( x\right ) & =-\sum _{n=0}^{\infty }c_{n}\left ( t\right ) \lambda _{n}\Phi _{n}\left ( x\right ) +\sum _{n=0}^{\infty }b_{n}\left ( t\right ) \Phi _{n}\left ( x\right ) \nonumber \\ c_{n}^{\prime }\left ( t\right ) \Phi _{n}\left ( x\right ) +c_{n}\left ( t\right ) \lambda _{n}\Phi _{n}\left ( x\right ) & =b_{n}\left ( t\right ) \Phi _{n}\left ( x\right ) \nonumber \\ c_{n}^{\prime }\left ( t\right ) +c_{n}\left ( t\right ) \lambda _{n} & =b_{n}\left ( t\right ) \nonumber \\ c_{n}^{\prime }\left ( t\right ) +c_{n}\left ( t\right ) \frac {n^{2}\pi ^{2}}{L^{2}} & =b_{n}\left ( t\right ) \tag {5} \end {align}

To find \(b_{n}\left ( t\right ) \), since \(\tilde {Q}\left ( x,t\right ) =Q\left ( x,t\right ) +\frac {\partial r}{\partial t}-k\frac {B\left ( t\right ) -A\left ( t\right ) }{L}\) then\[ Q\left ( x,t\right ) +\frac {\partial r}{\partial t}-k\frac {B\left ( t\right ) -A\left ( t\right ) }{L}=\sum _{n=0}^{\infty }b_{n}\left ( t\right ) \Phi _{n}\left ( x\right ) \] Multiplying both sides by \(\Phi _{m}\left ( x\right ) \) and integrating gives\begin {align*} \int _{0}^{L}\left ( Q\left ( x,t\right ) +\frac {\partial r}{\partial t}-k\frac {B\left ( t\right ) -A\left ( t\right ) }{L}\right ) \Phi _{m}\left ( x\right ) dx & =\int _{0}^{L}\sum _{n=0}^{\infty }b_{n}\left ( t\right ) \Phi _{n}\left ( x\right ) \Phi _{m}\left ( x\right ) dx\\ & =\sum _{n=0}^{\infty }b_{n}\left ( t\right ) \left ( \int _{0}^{L}\Phi _{n}\left ( x\right ) \Phi _{m}\left ( x\right ) dx\right ) \end {align*}

By orthogonality\[ \int _{0}^{L}\left ( Q\left ( x,t\right ) +r_{t}-k\frac {B\left ( t\right ) -A\left ( t\right ) }{L}\right ) \Phi _{m}\left ( x\right ) dx=b_{m}\left ( t\right ) \int _{0}^{L}\Phi _{m}^{2}\left ( x\right ) dx \] When \(m=0,\Phi _{0}\left ( x\right ) =1\) and the above gives\begin {align*} \int _{0}^{L}Q\left ( x,t\right ) +r_{t}-k\frac {B\left ( t\right ) -A\left ( t\right ) }{L}dx & =b_{0}\left ( t\right ) \int _{0}^{L}dx\\ b_{0}\left ( t\right ) & =\frac {1}{L}\int _{0}^{L}Q\left ( x,t\right ) +r_{t}-k\frac {B\left ( t\right ) -A\left ( t\right ) }{L}dx \end {align*}

When \(m=1,2,3,\cdots \)\begin {align*} \int _{0}^{L}\left ( Q\left ( x,t\right ) +r_{t}-k\frac {B\left ( t\right ) -A\left ( t\right ) }{L}\right ) \cos \left ( \frac {m\pi }{L}x\right ) dx & =b_{m}\left ( t\right ) \int _{0}^{L}\cos ^{2}\left ( \frac {m\pi }{L}x\right ) dx\\ \int _{0}^{L}\left ( Q\left ( x,t\right ) +r_{t}-k\frac {B\left ( t\right ) -A\left ( t\right ) }{L}\right ) \cos \left ( \frac {m\pi }{L}x\right ) dx & =b_{m}\left ( t\right ) \frac {L}{2}\\ b_{m}\left ( t\right ) & =\frac {2}{L}\int _{0}^{L}\left ( Q\left ( x,t\right ) +r_{t}-k\frac {B\left ( t\right ) -A\left ( t\right ) }{L}\right ) \cos \left ( \frac {m\pi }{L}x\right ) dx \end {align*}

Therefore (5) is now solved. When \(n=0\) (5) becomes\begin {align*} c_{0}^{\prime }\left ( t\right ) +c_{0}\left ( t\right ) \frac {n^{2}\pi ^{2}}{L^{2}} & =b_{0}\left ( t\right ) \\ c_{0}^{\prime }\left ( t\right ) & =b_{0}\left ( t\right ) \\ c_{0}^{\prime }\left ( t\right ) & =\frac {1}{L}\int _{0}^{L}Q\left ( x,t\right ) +r_{t}-k\frac {B\left ( t\right ) -A\left ( t\right ) }{L}dx \end {align*}

Hence\[ c_{0}\left ( t\right ) =\int _{0}^{t}\left ( \frac {1}{L}\int _{0}^{L}Q\left ( x,\tau \right ) +r_{\tau }-k\frac {B\left ( \tau \right ) -A\left ( \tau \right ) }{L}dx\right ) dt+C_{0}\] For \(n=1,2,3,\cdots \) (5) becomes\begin {align*} c_{n}^{\prime }\left ( t\right ) +c_{n}\left ( t\right ) \frac {n^{2}\pi ^{2}}{L^{2}} & =b_{n}\left ( t\right ) \\ & =\frac {2}{L}\int _{0}^{L}\left ( Q\left ( x,\tau \right ) +r_{\tau }-k\frac {B\left ( \tau \right ) -A\left ( \tau \right ) }{L}\right ) \cos \left ( \frac {n\pi }{L}x\right ) dx \end {align*}

Integrating factor is \(I=e^{\int \frac {n^{2}\pi ^{2}}{L^{2}}dt}=e^{\frac {n^{2}\pi ^{2}}{L^{2}}t}\) and the solution to the above becomes

\begin {align*} \frac {d}{dt}\left ( c_{n}\left ( t\right ) e^{\frac {n^{2}\pi ^{2}}{L^{2}}t}\right ) & =\frac {2e^{\frac {n^{2}\pi ^{2}}{L^{2}}t}}{L}\int _{0}^{L}\left ( Q\left ( x,t\right ) +r_{t}-k\frac {B\left ( t\right ) -A\left ( t\right ) }{L}\right ) \cos \left ( \frac {n\pi }{L}x\right ) dx\\ c_{n}\left ( t\right ) e^{\frac {n^{2}\pi ^{2}}{L^{2}}t} & =\int _{0}^{t}\left ( \frac {2e^{\frac {n^{2}\pi ^{2}}{L^{2}}\tau }}{L}\int _{0}^{L}\left ( Q\left ( x,\tau \right ) +r_{\tau }-k\frac {B\left ( \tau \right ) -A\left ( \tau \right ) }{L}\right ) \cos \left ( \frac {n\pi }{L}x\right ) dx\right ) dt+C_{n}\\ c_{n}\left ( t\right ) & =e^{-\frac {n^{2}\pi ^{2}}{L^{2}}t}\int _{0}^{t}\left ( \frac {2e^{\frac {n^{2}\pi ^{2}}{L^{2}}\tau }}{L}\int _{0}^{L}\left ( Q\left ( x,\tau \right ) +r_{\tau }-k\frac {B\left ( \tau \right ) -A\left ( \tau \right ) }{L}\right ) \cos \left ( \frac {n\pi }{L}x\right ) dx\right ) dt+C_{n}e^{-\frac {n^{2}\pi ^{2}}{L^{2}}t} \end {align*}

Now that we found \(c_{n}\left ( t\right ) \) for \(n=0,1,2,3,\cdots \) the solution for \(v\left ( x,t\right ) \) is found from 4A.

\begin {align*} v\left ( x,t\right ) & =\sum _{n=0}^{\infty }c_{n}\left ( t\right ) \Phi _{n}\left ( x\right ) \\ & =\int _{0}^{t}\left ( \frac {1}{L}\int _{0}^{L}Q\left ( x,\tau \right ) +r_{\tau }-k\frac {B\left ( \tau \right ) -A\left ( \tau \right ) }{L}dx\right ) dt+C_{0}+\sum _{n=1}^{\infty }c_{n}\left ( t\right ) \Phi _{n}\left ( x\right ) \\ & \\ & =\int _{0}^{t}\left ( \frac {1}{L}\int _{0}^{L}Q\left ( x,\tau \right ) +r_{\tau }-k\frac {B\left ( \tau \right ) -A\left ( \tau \right ) }{L}dx\right ) dt+C_{0}\\ & +\sum _{n=1}^{\infty }\left ( e^{-\frac {n^{2}\pi ^{2}}{L^{2}}t}\int _{0}^{t}\left ( \frac {2e^{\frac {n^{2}\pi ^{2}}{L^{2}}\tau }}{L}\int _{0}^{L}\left ( Q\left ( x,\tau \right ) +r_{\tau }-k\frac {B\left ( \tau \right ) -A\left ( \tau \right ) }{L}\right ) \cos \left ( \frac {n\pi }{L}x\right ) dx\right ) dt+C_{n}e^{-\frac {n^{2}\pi ^{2}}{L^{2}}t}\right ) \cos \left ( \frac {n\pi }{L}x\right ) \end {align*}

But \[ u\left ( x,t\right ) =v\left ( x,t\right ) +r\left ( x,t\right ) \] Hence

\begin {align*} u\left ( x,t\right ) & =A\left ( t\right ) x+\left ( \frac {B\left ( t\right ) -A\left ( t\right ) }{2L}\right ) x^{2}+\int _{0}^{t}\left ( \frac {1}{L}\int _{0}^{L}Q\left ( x,\tau \right ) +r_{\tau }-k\frac {B\left ( \tau \right ) -A\left ( \tau \right ) }{L}dx\right ) dt+C_{0}\\ & +\sum _{n=1}^{\infty }\left ( e^{-\frac {n^{2}\pi ^{2}}{L^{2}}t}\int _{0}^{t}\left ( \frac {2e^{\frac {n^{2}\pi ^{2}}{L^{2}}\tau }}{L}\int _{0}^{L}\left ( Q\left ( x,\tau \right ) +r_{\tau }-k\frac {B\left ( \tau \right ) -A\left ( \tau \right ) }{L}\right ) \cos \left ( \frac {n\pi }{L}x\right ) dx\right ) dt+C_{n}e^{-\frac {n^{2}\pi ^{2}}{L^{2}}t}\right ) \cos \left ( \frac {n\pi }{L}x\right ) \end {align*}

But \begin {align*} r_{\tau } & =\frac {d}{dt}\left ( A\left ( \tau \right ) x+\left ( \frac {B\left ( \tau \right ) -A\left ( \tau \right ) }{2L}\right ) x^{2}\right ) \\ & =\frac {2LA^{\prime }\left ( \tau \right ) x+\left ( B^{\prime }\left ( \tau \right ) -A^{\prime }\left ( \tau \right ) \right ) x^{2}}{2L} \end {align*}

Hence

\begin {gather*} u\left ( x,t\right ) =C_{0}+A\left ( t\right ) x+\left ( \frac {B\left ( t\right ) -A\left ( t\right ) }{2L}\right ) x^{2}\\ +\frac {1}{2L^{2}}\int _{0}^{t}\left ( \int _{0}^{L}2LQ\left ( x,\tau \right ) +2LA^{\prime }\left ( \tau \right ) x+\left ( B^{\prime }\left ( \tau \right ) -A^{\prime }\left ( \tau \right ) \right ) x^{2}-2k\left ( B\left ( \tau \right ) -A\left ( \tau \right ) \right ) dx\right ) dt+\\ \sum _{n=1}^{\infty }\cos \frac {n\pi }{L}x\left ( e^{-\frac {n^{2}\pi ^{2}}{L^{2}}t}\int _{0}^{t}\left ( \frac {e^{\frac {n^{2}\pi ^{2}}{L^{2}}\tau }}{L^{2}}\int _{0}^{L}\left ( 2LQ\left ( x,\tau \right ) +2LA^{\prime }\left ( \tau \right ) x+\left ( B^{\prime }\left ( \tau \right ) -A^{\prime }\left ( \tau \right ) \right ) x^{2}-2k\left ( B\left ( \tau \right ) -A\left ( \tau \right ) \right ) \right ) \cos \left ( \frac {n\pi }{L}x\right ) dx\right ) dt+C_{n}e^{-\frac {n^{2}\pi ^{2}}{L^{2}}t}\right ) \end {gather*}

The constants \(C_{0},C_{n}\) are found from initial conditions \(u\left ( x,0\right ) =f\left ( x\right ) \).

____________________________________________________________________________________

4.1.5.19 [234] Articolo 8.4.3

problem number 234

Added December 20, 2018.

Example 8.4.3 from Partial differential equations and boundary value problems with Maple by George A. Articolo, 2nd ed.

Solve the heat equation for \(u(x,t)\)

\[ u_t = k u_{xx} + t \]

For \(0<x<1\) and \(t>0\). The boundary conditions are \begin {align*} u(0,t)&=5 \\ u(1,t)+ \frac {\partial u}{\partial x}(1,t) &= 10\\ \end {align*}

Initial condition is \(u(x,0)=\frac {- 40 x^2}{3}+ \frac {45 x}{2}+5\) and \(k=\frac {1}{20}\)

Mathematica

ClearAll["Global`*"]; 
k = 1/20; 
pde =  D[u[x, t], t] == k*D[u[x, t], {x, 2}] + t; 
bc  = {u[0, t] == 5, u[1, t] + Derivative[1, 0][u][1, t] == 10}; 
ic  = u[x, 0] == (-40*x^2)/3 + (45*x)/2 + 5; 
sol =  AbsoluteTiming[TimeConstrained[DSolve[{pde, ic, bc}, u[x, t], x, t], 60*10]];
 

\[\left \{\left \{u(x,t)\to \begin {array}{cc} \{ & \begin {array}{cc} \frac {5 x}{2}+\sum _{K[1]=1}^\infty -\frac {\sqrt {2} \left (\frac {40 e^{-\frac {1}{20} t K[2,K[1]]} \left (\cos \left (\sqrt {K[2,K[1]]}\right )-1\right ) \left (e^{\frac {1}{20} t K[2,K[1]]} (t K[2,K[1]]-20)+20\right )}{\sqrt {\cos \left (2 \sqrt {K[2,K[1]]}\right )+3} K[2,K[1]]^{5/2}}+\frac {40 e^{-\frac {1}{20} t K[2,K[1]]} \left (\cos \left (\sqrt {K[2,K[1]]}\right ) (K[2,K[1]]+4)+\sqrt {K[2,K[1]]} \sin \left (\sqrt {K[2,K[1]]}\right )-4\right )}{3 \sqrt {\cos \left (2 \sqrt {K[2,K[1]]}\right )+3} K[2,K[1]]^{3/2}}\right ) \sin \left (x \sqrt {K[2,K[1]]}\right )}{\sqrt {\cos ^2\left (\sqrt {K[2,K[1]]}\right )+1}}+5 & \tan \left (\sqrt {K[2,K[1]]}\right )+\sqrt {K[2,K[1]]}=0\land K[1]\in \mathbb {Z}\land K[1]\geq 1\land K[2,K[1]]>0 \\ \text {Indeterminate} & \text {True} \\\end {array} \\\end {array}\right \}\right \}\]

Maple

restart; 
pde := diff(u(x, t), t) = (1/20)*(diff(u(x, t), x$2))+t; 
bc  := u(0, t) = 5, (u(1, t)+ eval( diff(u(x,t),x),x=1)) = 10; 
ic  := u(x, 0) = -40*x^2/3+45*x/2+5; 
cpu_time := timelimit(60*10,CodeTools[Usage](assign('sol', pdsolve([pde, bc,ic], u(x, t))),output='realtime'));
 

\[u \left (x , t\right ) = \frac {5 x}{2}+\int _{0}^{t}\left (\sum _{\mathit {n1} =0}^\infty \left \{\begin {array}{cc} 0 & \lambda _{n}=0 \\ \frac {4 \left (\cos \left (\lambda _{n}\right )-1\right ) \tau \,{\mathrm e}^{-\frac {\left (t -\tau \right ) \lambda _{n}^{2}}{20}} \sin \left (x \lambda _{n}\right )}{-2 \lambda _{n}+\sin \left (2 \lambda _{n}\right )} & \mathit {otherwise} \end {array}\right .\right )d \tau +\left (\sum _{n=0}^\infty \frac {80 \left (\lambda _{n}^{2} \cos \left (\lambda _{n}\right )+\lambda _{n} \sin \left (\lambda _{n}\right )+4 \cos \left (\lambda _{n}\right )-4\right ) {\mathrm e}^{-\frac {t \lambda _{n}^{2}}{20}} \sin \left (x \lambda _{n}\right )}{3 \left (-2 \lambda _{n}+\sin \left (2 \lambda _{n}\right )\right ) \lambda _{n}^{2}}\right )+5\boldsymbol {\mathrm {where}}\left \{\lambda _{n}+\tan \left (\lambda _{n}\right )=0\wedge 0<\lambda _{n}\right \}\]

____________________________________________________________________________________