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 \underset {n=1}{\overset {\infty }{\sum }}\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 {1}{L} \left ( \sum _{n=1}^{\infty } \left ( -2\,{\frac {1}{{L}^{2}}\sin \left ( {\frac {n\pi \,x}{L}} \right ) {{\rm e}^{-{\frac {k{\pi }^{2}{n}^{2}t}{{L}^{2}}}}}\int _{0}^{L}\! \left ( -f \left ( x \right ) L+ \left ( L-x \right ) A+xB \right ) \sin \left ( {\frac {n\pi \,x}{L}} \right ) \,{\rm d}x} \right ) L+AL- \left ( A-B \right ) x \right ) }\]
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 3.1.1.1 on page 397 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*}
____________________________________________________________________________________
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 \underset {n=1}{\overset {\infty }{\sum }}\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 ) =20+30\,x+\sum _{n=1}^{\infty }{\frac { \left ( 100\, \left ( -1 \right ) ^{n}-40 \right ) \sin \left ( n\pi \,x \right ) {{\rm e}^{-{\pi }^{2}{n}^{2}t}}}{n\pi }}\]
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 3.1.5.1 on page 690 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*}
____________________________________________________________________________________
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 \underset {n=1}{\overset {\infty }{\sum }}-\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+10\,x+\sum _{n=1}^{\infty }-200\,{\frac { \left ( -1+ \left ( -1 \right ) ^{n} \right ) \sin \left ( n\pi \,x \right ) {{\rm e}^{-1/20\,{\pi }^{2}{n}^{2}t}}}{{n}^{3}{\pi }^{3}}}\]
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 3.1.5.1 on page 690 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*}
____________________________________________________________________________________
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 \underset {K[1]=1}{\overset {\infty }{\sum }}\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 {1}{Lk} \left ( \sum _{n=1}^{\infty } \left ( -2\,{\frac {1}{k{L}^{2}}\sin \left ( {\frac {n\pi \,x}{L}} \right ) {{\rm e}^{-{\frac {k{\pi }^{2}{n}^{2}t}{{L}^{2}}}}}\int _{0}^{L}\!- \left ( -{\it \_a}\,\int _{0}^{L}\!\int _{0}^{{\it \_z1}}\!Q \left ( {\it \_z1} \right ) \,{\rm d}{\it \_z1}\,{\rm d}{\it \_z1}+\int _{0}^{{\it \_a}}\!\int _{0}^{{\it \_z1}}\!Q \left ( {\it \_z1} \right ) \,{\rm d}{\it \_z1}\,{\rm d}{\it \_z1}L+k \left ( f \left ( {\it \_a} \right ) L-AL+{\it \_a}\, \left ( A-B \right ) \right ) \right ) \sin \left ( {\frac {n\pi \,{\it \_a}}{L}} \right ) \,{\rm d}{\it \_a}} \right ) Lk+x\int _{0}^{L}\!\int _{0}^{{\it \_a}}\!Q \left ( {\it \_a} \right ) \,{\rm d}{\it \_a}\,{\rm d}{\it \_a}-\int _{0}^{x}\!\int _{0}^{{\it \_a}}\!Q \left ( {\it \_a} \right ) \,{\rm d}{\it \_a}\,{\rm d}{\it \_a}L+ \left ( AL- \left ( A-B \right ) x \right ) k \right ) }\]
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 3.1.1.11 on page 445 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*}
____________________________________________________________________________________
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 \underset {K[1]=1}{\overset {\infty }{\sum }}-\frac {20 e^{-\frac {\pi ^2 t K[1]^2}{9000}} \left (-\left (4+5 (-1)^{K[1]}\right ) \pi ^2 K[1]^2-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 ) =20-{\frac {{x}^{3}}{6}}+151\,x+\sum _{n=1}^{\infty }100\,{\frac { \left ( \left ( -1 \right ) ^{n}{\pi }^{2}{n}^{2}+4/5\,{\pi }^{2}{n}^{2}+540\, \left ( -1 \right ) ^{n} \right ) \sin \left ( 1/30\,n\pi \,x \right ) }{{n}^{3}{\pi }^{3}}{{\rm e}^{-{\frac {{\pi }^{2}{n}^{2}t}{9000}}}}}\]
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 3.1.5.4 on page 700 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
____________________________________________________________________________________
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 \underset {K[1]=1}{\overset {\infty }{\sum }}\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 {1}{L} \left ( \sum _{n=1}^{\infty } \left ( 2\,{\frac {1}{L}\sin \left ( {\frac {n\pi \,x}{L}} \right ) {{\rm e}^{-{\frac {k{\pi }^{2}{n}^{2}t}{{L}^{2}}}}}\int _{0}^{L}\!{\frac {f \left ( x \right ) L-AL+ \left ( A-B \right ) x}{L}\sin \left ( {\frac {n\pi \,x}{L}} \right ) }\,{\rm d}x} \right ) L+\int _{0}^{t}\!\sum _{n=1}^{\infty } \left ( 2\,{\frac {1}{L}\sin \left ( {\frac {n\pi \,x}{L}} \right ) {{\rm e}^{-{\frac {k{\pi }^{2}{n}^{2} \left ( t-\tau \right ) }{{L}^{2}}}}}\int _{0}^{L}\!Q \left ( x,\tau \right ) \sin \left ( {\frac {n\pi \,x}{L}} \right ) \,{\rm d}x} \right ) \,{\rm d}\tauL +AL- \left ( A-B \right ) x \right ) }\]
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 3.1.6.4 on page 798 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*}
____________________________________________________________________________________
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 \underset {K[1]=1}{\overset {\infty }{\sum }}\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}} k \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 {1}{L} \left ( \sum _{n=1}^{\infty } \left ( 2\,{\frac {1}{L}\sin \left ( {\frac {n\pi \,x}{L}} \right ) {{\rm e}^{-{\frac {k{\pi }^{2}{n}^{2}t}{{L}^{2}}}}}\int _{0}^{L}\!{\frac {A \left ( 0 \right ) \left ( x-L \right ) -xB \left ( 0 \right ) +f \left ( x \right ) L}{L}\sin \left ( {\frac {n\pi \,x}{L}} \right ) }\,{\rm d}x} \right ) L+\int _{0}^{t}\!\sum _{n=1}^{\infty }-2\,{\frac {- \left ( -1 \right ) ^{n}{\frac {\rm d}{{\rm d}\tau }}B \left ( \tau \right ) +{\frac {\rm d}{{\rm d}\tau }}A \left ( \tau \right ) }{n\pi }\sin \left ( {\frac {n\pi \,x}{L}} \right ) {{\rm e}^{-{\frac {k{\pi }^{2}{n}^{2} \left ( t-\tau \right ) }{{L}^{2}}}}}}\,{\rm d}\tauL + \left ( -x+L \right ) A \left ( t \right ) +xB \left ( t \right ) \right ) }\]
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 3.1.6.4 on page 798. 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*}
____________________________________________________________________________________
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 \underset {K[1]=1}{\overset {\infty }{\sum }}\frac {8 \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 ) =\sum _{n=1}^{\infty }-80\,{\frac {\sin \left ( 1/2\,n\pi \,x \right ) \left ( \left ( -{\pi }^{2}{n}^{2}+80\, \left ( -1 \right ) ^{n} \right ) {{\rm e}^{-1/40\,{\pi }^{2}{n}^{2}t}}+ \left ( 2\,{\pi }^{2}{n}^{2}\sin \left ( t \right ) -80\,\cos \left ( t \right ) \right ) \left ( -1 \right ) ^{n}+{\pi }^{2}\cos \left ( t \right ) {n}^{2}+40\,\sin \left ( t \right ) \right ) }{\pi \,n \left ( {\pi }^{4}{n}^{4}+1600 \right ) }}+ \left ( \cos \left ( t \right ) -{\frac {\sin \left ( t \right ) }{2}} \right ) x+\sin \left ( t \right ) \]
Hand solution
The basic solution for this type of PDE was already given in problem 3.1.5.7 on page 718 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
____________________________________________________________________________________
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 \underset {K[1]=1}{\overset {\infty }{\sum }}\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 {2-{\frac {{\pi }^{2}}{6}}}{\pi }}+\sum _{n=2}^{\infty }-2\,{\frac {\cos \left ( nx \right ) {{\rm e}^{-{n}^{2}t}} \left ( \left ( -1 \right ) ^{n}+1 \right ) }{{n}^{2} \left ( {n}^{2}-1 \right ) \pi }}-2\,{\frac {t}{\pi }}-{\frac {{x}^{2}}{\pi }}+x\]
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*}
____________________________________________________________________________________
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 \underset {K[1]=1}{\overset {\infty }{\sum }}\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 ) =\sum _{n=0}^{\infty } \left ( -2\,{\frac {1}{L}\sin \left ( 1/2\,{\frac { \left ( 1+2\,n \right ) \pi \,x}{L}} \right ) {{\rm e}^{-1/4\,{\frac {k{\pi }^{2} \left ( 1+2\,n \right ) ^{2}t}{{L}^{2}}}}}\int _{0}^{L}\! \left ( xB+A-f \left ( x \right ) \right ) \sin \left ( 1/2\,{\frac { \left ( 1+2\,n \right ) \pi \,x}{L}} \right ) \,{\rm d}x} \right ) +xB+A\]
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}\]
____________________________________________________________________________________
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 \underset {K[1]=1}{\overset {\infty }{\sum }}-\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}}+{\frac { \left ( {L}^{2}-2\,A+2\,B \right ) x}{2\,L}}+A+\sum _{n=1}^{\infty } \left ( -{\frac {1}{{L}^{2}}\sin \left ( {\frac {n\pi \,x}{L}} \right ) {{\rm e}^{-{\frac {k{\pi }^{2}{n}^{2}t}{{L}^{2}}}}}\int _{0}^{L}\!2\,\sin \left ( {\frac {n\pi \,x}{L}} \right ) \left ( -f \left ( x \right ) L+1/2\,{L}^{2}x+ \left ( -1/2\,{x}^{2}+A \right ) L- \left ( A-B \right ) x \right ) \,{\rm d}x} \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} 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*}
____________________________________________________________________________________
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 \underset {K[1]=1}{\overset {\infty }{\sum }}\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 3.1.1.11 on page 445 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*}
____________________________________________________________________________________
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 \underset {K[1]=1}{\overset {\infty }{\sum }}\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 ) =\sum _{n=1}^{\infty }-2\,{\frac {\sin \left ( 1/2\,n\pi \,x \right ) \left ( \left ( \left ( {\pi }^{6}{n}^{6}-80\,{\pi }^{4}{n}^{4}+3200\,{\pi }^{2}{n}^{2}-128000 \right ) \left ( -1 \right ) ^{n}-40\,{\pi }^{4}{n}^{4} \right ) {{\rm e}^{-1/40\,{\pi }^{2}{n}^{2}t}}+40\,{\pi }^{2} \left ( \left ( {\pi }^{2}{n}^{2}\sin \left ( t \right ) -40\,\cos \left ( t \right ) \right ) \left ( -1 \right ) ^{n}+{\pi }^{2}\cos \left ( t \right ) {n}^{2}+40\,\sin \left ( t \right ) \right ) {n}^{2} \right ) }{{\pi }^{3}{n}^{3} \left ( {\pi }^{4}{n}^{4}+1600 \right ) }}-{\frac {5\,{x}^{3}}{3}}-{\frac { \left ( -3\,\cos \left ( t \right ) -40+3\,\sin \left ( t \right ) \right ) x}{6}}+\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 3.1.5.12 on page 743 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
____________________________________________________________________________________
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 \underset {K[1]=1}{\overset {\infty }{\sum }}\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 {1}{L} \left ( \int _{0}^{t}\!\sum _{n=1}^{\infty } \left ( 2\,{\frac {1}{L}\sin \left ( {\frac {n\pi \,x}{L}} \right ) {{\rm e}^{-{\frac {k{\pi }^{2}{n}^{2} \left ( t-\tau \right ) }{{L}^{2}}}}}\int _{0}^{L}\! \left ( - \left ( 1-{\frac {x}{L}} \right ) {\frac {\rm d}{{\rm d}\tau }}A \left ( \tau \right ) -{\frac {x{\frac {\rm d}{{\rm d}\tau }}B \left ( \tau \right ) }{L}}+Q \left ( x,\tau \right ) \right ) \sin \left ( {\frac {n\pi \,x}{L}} \right ) \,{\rm d}x} \right ) \,{\rm d}\tauL +\sum _{n=1}^{\infty } \left ( 2\,{\frac {1}{L}\sin \left ( {\frac {n\pi \,x}{L}} \right ) {{\rm e}^{-{\frac {k{\pi }^{2}{n}^{2}t}{{L}^{2}}}}}\int _{0}^{L}\!{\frac { \left ( x-L \right ) A \left ( 0 \right ) -xB \left ( 0 \right ) +f \left ( x \right ) L}{L}\sin \left ( {\frac {n\pi \,x}{L}} \right ) }\,{\rm d}x} \right ) L+ \left ( L-x \right ) A \left ( t \right ) +xB \left ( t \right ) \right ) }\]
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 3.1.6.4 on page 798 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*}
____________________________________________________________________________________
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 \underset {K[1]=1}{\overset {\infty }{\sum }}\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 ) =\sum _{n=1}^{\infty }-2\,{\frac { \left ( \left ( \left ( {\pi }^{12}{n}^{12}-160\,{\pi }^{10}{n}^{10}+19200\,{\pi }^{8}{n}^{8}-1280000\,{\pi }^{6}{n}^{6}+56320000\,{n}^{4}{\pi }^{4}-2048000000\,{\pi }^{2}{n}^{2}+32768000000 \right ) \left ( -1 \right ) ^{n}-40\,{\pi }^{2}{n}^{2} \left ( {n}^{4}{\pi }^{4}-80\,{\pi }^{2}{n}^{2}+3200 \right ) ^{2} \right ) {{\rm e}^{-1/40\,{\pi }^{2}{n}^{2}t}}+80\, \left ( \left ( t{\pi }^{6}{n}^{6}-120\,{\pi }^{4} \left ( t+1/3 \right ) {n}^{4}+6400\,{\pi }^{2} \left ( t+1/2 \right ) {n}^{2}-128000\,t \right ) \cos \left ( t \right ) +40\, \left ( t{\pi }^{4}{n}^{4}-80\,{\pi }^{2} \left ( t+1 \right ) {n}^{2}+3200\,t+3200 \right ) \sin \left ( t \right ) \right ) \left ( {n}^{4}{\pi }^{4}+1600 \right ) \left ( -1 \right ) ^{n}{{\rm e}^{-t}}+40\, \left ( {n}^{4}{\pi }^{4}-80\,{\pi }^{2}{n}^{2}+3200 \right ) ^{2} \left ( \left ( {\pi }^{2}\sin \left ( t \right ) {n}^{2}-40\,\cos \left ( t \right ) \right ) \left ( -1 \right ) ^{n}+{\pi }^{2}\cos \left ( t \right ) {n}^{2}+40\,\sin \left ( t \right ) \right ) \right ) \sin \left ( 1/2\,n\pi \,x \right ) }{\pi \,n \left ( {n}^{4}{\pi }^{4}+1600 \right ) \left ( {n}^{4}{\pi }^{4}-80\,{\pi }^{2}{n}^{2}+3200 \right ) ^{2}}}+{\frac {\cos \left ( t \right ) x}{2}}-{\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 3.1.5.14 on page 756 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
____________________________________________________________________________________
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 ) =1+\cos \left ( 2\,\pi \,x \right ) {{\rm e}^{-4\,t{\pi }^{2}}}+t+\sin \left ( t \right ) x\]
____________________________________________________________________________________
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 \underset {K[1]=1}{\overset {\infty }{\sum }}\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 {1}{10\,\pi } \left ( 10\,\sum _{n=1}^{\infty }4\,{\frac {\sin \left ( nx \right ) }{\pi \,{n}^{3} \left ( {n}^{4}+1 \right ) ^{2}} \left ( \left ( \left ( \left ( \pi -30 \right ) {n}^{10}+ \left ( \pi /2-1/20 \right ) {n}^{8}+ \left ( 2\,\pi -60 \right ) {n}^{6}+ \left ( \pi +1/20 \right ) {n}^{4}+ \left ( \pi -30 \right ) {n}^{2}+\pi /2 \right ) \left ( -1 \right ) ^{n}+30\,{n}^{2}+{\frac {299\,{n}^{6}}{5}}+30\,{n}^{10} \right ) {{\rm e}^{-{n}^{2}t}}+ \left ( 1/20\,{n}^{2} \left ( {n}^{6}+{n}^{4}t-{n}^{2}+t \right ) \cos \left ( t \right ) -1/20\,{n}^{4} \left ( {n}^{4}t-2\,{n}^{2}+t \right ) \sin \left ( t \right ) -1/2\,\pi \, \left ( {n}^{4}+1 \right ) ^{2} \right ) \left ( -1 \right ) ^{n}-1/10\, \left ( {n}^{2} \left ( {n}^{4}t-2\,{n}^{2}+t \right ) \cos \left ( t \right ) +\sin \left ( t \right ) \left ( {n}^{6}+{n}^{4}t-{n}^{2}+t \right ) \right ) {n}^{2} \right ) }\pi +t \left ( \left ( -2\,x+2\,\pi \right ) \sin \left ( t \right ) +\cos \left ( t \right ) x \right ) \right ) }\]
____________________________________________________________________________________
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 \underset {K[1]=1}{\overset {\infty }{\sum }}\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 {1}{L}\int _{0}^{L}\!{\frac { \left ( -2\,Lx+{x}^{2} \right ) A \left ( 0 \right ) -{x}^{2}B \left ( 0 \right ) +2\,f \left ( x \right ) L}{2\,L}}\,{\rm d}x}+\sum _{n=1}^{\infty } \left ( 2\,{\frac {1}{L}\int _{0}^{L}\!1/2\,{\frac { \left ( -2\,Lx+{x}^{2} \right ) A \left ( 0 \right ) -{x}^{2}B \left ( 0 \right ) +2\,f \left ( x \right ) L}{L}\cos \left ( {\frac {n\pi \,x}{L}} \right ) }\,{\rm d}x\cos \left ( {\frac {n\pi \,x}{L}} \right ) {{\rm e}^{{\frac {k{\pi }^{2}{n}^{2}t}{{L}^{2}}}}}} \right ) +\int _{0}^{t}\!{\frac {1}{L}\int _{0}^{L}\!{\frac { \left ( -2\,Lx+{x}^{2} \right ) {\frac {\rm d}{{\rm d}\tau }}A \left ( \tau \right ) -{x}^{2}{\frac {\rm d}{{\rm d}\tau }}B \left ( \tau \right ) -2\,Q \left ( x,\tau \right ) L+2\, \left ( A \left ( \tau \right ) -B \left ( \tau \right ) \right ) k}{2\,L}}\,{\rm d}x}+\sum _{n=1}^{\infty } \left ( 2\,{\frac {1}{L}\int _{0}^{L}\!-{\frac {x \left ( L-x/2 \right ) {\frac {\rm d}{{\rm d}\tau }}A \left ( \tau \right ) +1/2\,{x}^{2}{\frac {\rm d}{{\rm d}\tau }}B \left ( \tau \right ) +Q \left ( x,\tau \right ) L- \left ( A \left ( \tau \right ) -B \left ( \tau \right ) \right ) k}{L}\cos \left ( {\frac {n\pi \,x}{L}} \right ) }\,{\rm d}x\cos \left ( {\frac {n\pi \,x}{L}} \right ) {{\rm e}^{{\frac {k{\pi }^{2}{n}^{2} \left ( t-\tau \right ) }{{L}^{2}}}}}} \right ) \,{\rm d}\tau + \left ( -{\frac {{x}^{2}}{2\,L}}+x \right ) A \left ( t \right ) +{\frac {{x}^{2}B \left ( t \right ) }{2\,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 ) \).
____________________________________________________________________________________
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}+\underset {K[1]=1}{\overset {\infty }{\sum }}-\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 ) = \left ( \sum _{n=0}^{\infty }\begin {cases}0 & \lambda _{{n}}=0\\{\frac {80\,\sin \left ( \lambda _{{n}}x \right ) \left ( {\lambda _{{n}}}^{2}\cos \left ( \lambda _{{n}} \right ) +\lambda _{{n}}\sin \left ( \lambda _{{n}} \right ) +4\,\cos \left ( \lambda _{{n}} \right ) -4 \right ) }{3\,{\lambda _{{n}}}^{2} \left ( -2\,\lambda _{{n}}+\sin \left ( 2\,\lambda _{{n}} \right ) \right ) }{{\rm e}^{-{\frac {t{\lambda _{{n}}}^{2}}{20}}}}} & \text {otherwise}\end {cases}+\int _{0}^{t}\!\sum _{{\it n1}=0}^{\infty }\begin {cases}0 & \lambda _{{n}}=0\\4\,{\frac {{{\rm e}^{-1/20\, \left ( t-\tau \right ) {\lambda _{{n}}}^{2}}}\sin \left ( \lambda _{{n}}x \right ) \tau \, \left ( \cos \left ( \lambda _{{n}} \right ) -1 \right ) }{-2\,\lambda _{{n}}+\sin \left ( 2\,\lambda _{{n}} \right ) }} & \text {otherwise}\end {cases}\,{\rm d}\tau +{\frac {5\,x}{2}}+5, \left \{ \left ( \tan \left ( \lambda _{{n}} \right ) +\lambda _{{n}}=0 \land 0<\lambda _{{n}}\right ) \right \} \right ) \]
____________________________________________________________________________________