____________________________________________________________________________________
From Mathematica DSolve help pages. Solve the heat equation for \(u(x,t)\) on real line with \(t>0\) \[ u_t= u_{xx} \] With initial condition \[ u(x,0)= e^{-x^2} \]
Mathematica ✓
ClearAll[u, x, t]; pde = D[u[x, t], t] == D[u[x, t], {x, 2}]; ic = u[x, 0] == E^(-x^2); sol = AbsoluteTiming[TimeConstrained[DSolve[{pde, ic}, u[x, t], {x, t}], 60*10]];
\[ \left \{\left \{u(x,t)\to \frac {e^{-\frac {x^2}{4 t+1}}}{\sqrt {4 t+1}}\right \}\right \} \]
Maple ✓
x:='x'; u:='u'; t:='t'; pde := diff(u(x, t), t)=diff(u(x, t), x$2); ic:=u(x,0)=exp(-x^2); cpu_time := timelimit(60*10,CodeTools[Usage](assign('sol', pdsolve([pde,ic],u(x,t)) assuming t>0),output='realtime'));
\[ u \left ( x,t \right ) ={\frac {1}{\sqrt {1+4\,t}}{{\rm e}^{-{\frac {{x}^{2}}{1+4\,t}}}}} \]
Hand solution
Solve\[ \frac {\partial u}{\partial t}=\frac {\partial ^{2}u}{\partial x^{2}}\] On \(-\infty <x<\infty ,t>0\) with \(u\left ( x,0\right ) =f\left ( x\right ) =e^{-x^{2}}\). The first step is to find Green function for the above PDE. Taking Fourier transform of both sides w.r.t. \(x\), using \(\hat {u}\left ( k,t\right ) \) as the Fourier transform of \(u\left ( x,t\right ) \) gives\begin {align*} \frac {d}{dt}\hat {u}\left ( k,t\right ) & =\left ( ik\right ) ^{2}\hat {u}\left ( k,t\right ) \\ & =-k^{2}\hat {u}\left ( k,t\right ) \\ \frac {d}{dt}\hat {u}\left ( k,t\right ) +k^{2}\hat {u}\left ( k,t\right ) & =0 \end {align*}
The solution to the above is \begin {equation} \hat {u}\left ( k,t\right ) =Ce^{-k^{2}t}\tag {1} \end {equation} At \(t=0,\)\[ \hat {u}\left ( k,0\right ) =\mathcal {F}\left ( h\left ( x\right ) \right ) \] Therefore\[ C=\mathcal {F}\left ( h\left ( x\right ) \right ) \] And (1) becomes\[ \hat {u}\left ( k,t\right ) =\mathcal {F}\left ( h\left ( x\right ) \right ) e^{-k^{2}t}\] To find Green function, we replace \(h\left ( x\right ) \) by \(\delta \left ( x-\xi \right ) \) where \(\xi \) is the location of the pulse. But \(\mathcal {F}\left ( \delta \left ( x-\xi \right ) ;k\right ) =\frac {1}{\sqrt {2\pi }}\int _{-\infty }^{\infty }\delta \left ( x-\xi \right ) e^{-ikx}dx=\frac {1}{\sqrt {2\pi }}e^{-i\xi k}\). Therefore the above becomes\[ \hat {G}\left ( k,t\right ) =\frac {1}{\sqrt {2\pi }}e^{-i\xi k}e^{-k^{2}t}\] The above is the Fourier transform of the Green function. Now we invert it\begin {align} G\left ( x,t\right ) & =\frac {1}{\sqrt {2\pi }}\int _{-\infty }^{\infty }\left ( \frac {1}{\sqrt {2\pi }}e^{-i\xi k}e^{-k^{2}t}\right ) e^{ikx}dk\nonumber \\ & =\frac {1}{2\pi }\int _{-\infty }^{\infty }e^{-i\xi k-k^{2}t+ikx}dk\tag {2} \end {align}
We would like to use Gaussian as the integrand, hence we want to change \(-i\xi k-k^{2}t+ikx\) to \(-\left ( k\sqrt {t}-A\right ) ^{2}\). We do this by completing the square.\begin {align*} -i\xi k-k^{2}t+ikx & =-\left ( k\sqrt {t}-A\right ) ^{2}\\ & =-\left ( k^{2}t+A^{2}-2Ak\sqrt {t}\right ) \\ & =-k^{2}t-A^{2}+2Ak\sqrt {t} \end {align*}
Comparing sides then \(2Ak\sqrt {t}=k\left ( -i\xi +ix\right ) \) or \(A=\frac {-i\xi +ix}{2\sqrt {t}}\). Therefore\begin {align*} -i\xi k-k^{2}t+ikx & =-\left ( k\sqrt {t}-\frac {-i\xi +ix}{2\sqrt {t}}\right ) ^{2}+A^{2}\\ & =-\left ( k\sqrt {t}-\frac {-i\xi +ix}{2\sqrt {t}}\right ) ^{2}+\left ( \frac {-i\xi +ix}{2\sqrt {t}}\right ) ^{2} \end {align*}
Hence \begin {align*} e^{-i\xi k-k^{2}t+ikx} & =e^{-\left ( k\sqrt {t}-\frac {-i\xi +ix}{2\sqrt {t}}\right ) ^{2}+\left ( \frac {-i\xi +ix}{2\sqrt {t}}\right ) ^{2}}\\ & =e^{-\left ( k\sqrt {t}-\frac {-i\xi +ix}{2\sqrt {t}}\right ) ^{2}}e^{\left ( \frac {-i\xi +ix}{2\sqrt {t}}\right ) ^{2}} \end {align*}
Substituting the above into (2) gives\begin {align*} G\left ( x,t\right ) & =\frac {1}{2\pi }\int _{-\infty }^{\infty }e^{-\left ( k\sqrt {t}-\frac {-i\xi +ix}{2\sqrt {t}}\right ) ^{2}}e^{\left ( \frac {-i\xi +ix}{2\sqrt {t}}\right ) ^{2}}dk\\ & =\frac {1}{2\pi }e^{\left ( \frac {-i\xi +ix}{2\sqrt {t}}\right ) ^{2}}\int _{-\infty }^{\infty }e^{-\left ( k\sqrt {t}-\frac {-i\xi +ix}{2\sqrt {t}}\right ) ^{2}}dk \end {align*}
To evaluate \(\int _{-\infty }^{\infty }e^{-\left ( k\sqrt {t}-\frac {-i\xi +ix}{2\sqrt {t}}\right ) ^{2}}dk\), let \(u=k\sqrt {t}\), then \(du=\sqrt {t}dk\). The above becomes\begin {align*} G\left ( x,t\right ) & =\frac {1}{2\pi }e^{\left ( \frac {-i\xi +ix}{2\sqrt {t}}\right ) ^{2}}\int _{-\infty }^{\infty }e^{-\left ( u-\frac {-i\xi +ix}{2\sqrt {t}}\right ) ^{2}}\frac {du}{\sqrt {t}}\\ & =\frac {1}{2\pi \sqrt {t}}e^{\left ( \frac {-i\xi +ix}{2\sqrt {t}}\right ) ^{2}}\int _{-\infty }^{\infty }e^{-\left ( u-\frac {-i\xi +ix}{2\sqrt {t}}\right ) ^{2}}du \end {align*}
Now the integral is Gaussian. \(\int _{-\infty }^{\infty }e^{-\left ( u-\frac {-i\xi +ix}{2\sqrt {t}}\right ) ^{2}}du=\sqrt {\pi }\) and the above becomes\begin {align*} G\left ( x,t\right ) & =\frac {\sqrt {\pi }}{2\pi \sqrt {t}}e^{\left ( \frac {-i\xi +ix}{2\sqrt {t}}\right ) ^{2}}\\ & =\frac {1}{2\sqrt {\pi t}}e^{\left ( i\left ( \frac {-\xi +x}{2\sqrt {t}}\right ) \right ) ^{2}}\\ & =\frac {1}{2\sqrt {\pi t}}e^{-\frac {\left ( x-\xi \right ) ^{2}}{4t}} \end {align*}
Now that we found the Green function for the PDE, we can find the solution as\begin {align*} u\left ( x,t\right ) & =\int _{-\infty }^{\infty }G\left ( \xi ,t\right ) h\left ( \xi \right ) d\xi \\ & =\int _{-\infty }^{\infty }\frac {1}{2\sqrt {\pi t}}e^{-\frac {\left ( x-\xi \right ) ^{2}}{4t}}h\left ( \xi \right ) d\xi \\ & =\frac {1}{\sqrt {4\pi t}}\int _{-\infty }^{\infty }e^{-\frac {\left ( x-\xi \right ) ^{2}}{4t}}e^{-\xi ^{2}}d\xi \end {align*}
But \(\int _{-\infty }^{\infty }e^{-\frac {\left ( x-\xi \right ) ^{2}}{4t}}e^{-\xi ^{2}}d\xi =\frac {2e^{-\frac {x^{2}}{1+4t}\sqrt {\pi }}}{\sqrt {\frac {1+4t}{t}}}\), hence the above becomes\begin {align*} u\left ( x,t\right ) & =\frac {1}{\sqrt {4\pi t}}\frac {2e^{-\frac {x^{2}}{1+4t}\sqrt {\pi }}}{\sqrt {\frac {1+4t}{t}}}\\ & =\frac {e^{-\frac {x^{2}}{1+4t}}}{\sqrt {1+4t}} \end {align*}
____________________________________________________________________________________
From Mathematica DSolve help pages. Solve the heat equation for \(u(x,t)\) on real line with \(t>0\) \[ u_t = 12 u_{xx} + u_x \sin t \] With initial condition \[ u(x,0)= x \]
Mathematica ✓
ClearAll[u, x, t]; pde = D[u[x, t], t] == 12*D[u[x, t], {x, 2}] + Sin[t]*D[u[x, t], x]; ic = u[x, 0] == x; sol = AbsoluteTiming[TimeConstrained[DSolve[{pde, ic}, u[x, t], {x, t}], 60*10]];
\[ \{\{u(x,t)\to -\cos (t)+x+1\}\} \]
Maple ✓
x:='x'; u:='u'; t:='t'; pde:=diff(u(x,t),t)= 12* diff(u(x,t),x$2)+sin(t)*diff(u(x,t),x); ic:=u(x,0)=x; cpu_time := timelimit(60*10,CodeTools[Usage](assign('sol', pdsolve([pde,ic],u(x,t))),output='realtime'));
\[ u \left ( x,t \right ) =-\cos \left ( t \right ) +x+1 \]
____________________________________________________________________________________
From Mathematica DSolve help pages. Solve the heat equation for \(u(x,t)\) on real line with \(t>0\) \[ u_t= u_{xx} \] With initial condition \[ u(x,0)= \text {UnitBox[x]} \] Where UnitBox is equal to 1 if \(|x| \leq \frac {1}{2}\) and zero otherwise.
Mathematica ✓
ClearAll[u, x, t]; pde = D[u[x, t], t] == D[u[x, t], {x, 2}]; ic = u[x, 0] == UnitBox[x]; sol = AbsoluteTiming[TimeConstrained[DSolve[{pde, ic}, u[x, t], {x, t}], 60*10]];
\[ \left \{\left \{u(x,t)\to \frac {1}{2} \left (\text {Erf}\left (\frac {1-2 x}{4 \sqrt {t}}\right )+\text {Erf}\left (\frac {2 x+1}{4 \sqrt {t}}\right )\right )\right \}\right \} \]
Maple ✓
x:='x'; u:='u'; t:='t'; pde := diff(u(x, t), t)=diff(u(x, t), x$2); ic:= u(x,0)=piecewise( x< -1/2 or x>1/2,0, 1); cpu_time := timelimit(60*10,CodeTools[Usage](assign('sol', pdsolve([pde,ic],u(x,t)) assuming t>0),output='realtime'));
\[ u \left ( x,t \right ) =1/2\,\erf \left ( 1/4\,{\frac {2\,x+1}{\sqrt {t}}} \right ) -1/2\,\erf \left ( 1/4\,{\frac {2\,x-1}{\sqrt {t}}} \right ) \]
____________________________________________________________________________________
Solve the heat equation \[ u_t = k u_{xx} \] For \(-\infty <x<\infty \) and \(t>0\), and initial condition is \(u(x,0)=f(x)\)
Mathematica ✓
ClearAll[u, t, x, m, k, f]; pde = D[u[x, t], t] == k*D[u[x, t], {x, 2}]; ic = u[x, 0] == f[x]; sol = AbsoluteTiming[TimeConstrained[DSolve[{pde, ic}, u[x, t], {x, t}, Assumptions -> {t > 0, k > 0}], 60*10]]; sol[[2]] = sol[[2]] /. K[1] -> s;
\[ \left \{\left \{u(x,t)\to \int _{-\infty }^{\infty } \frac {f(s) e^{-\frac {(x-s)^2}{4 k t}}}{2 \sqrt {\pi } \sqrt {k t}} \, ds\right \}\right \} \]
Maple ✓
L:='L'; u:='u'; t:='t'; x:='x';m:='m'; interface(showassumed=0); pde:=diff(u(x,t),t)=k*diff(u(x,t),x$2); ic:=u(x,0)=f(x); cpu_time := timelimit(60*10,CodeTools[Usage](assign('sol',pdsolve([pde,ic],u(x,t)) assuming t>0,k>0),output='realtime'));
\[ u \left ( x,t \right ) =1/4\,{\frac {1}{{\pi }^{2}}\int _{-\infty }^{\infty }\!2\,{\frac {{\pi }^{3/2}f \left ( -\zeta \right ) }{\sqrt {k}\sqrt {t}}{{\rm e}^{-1/4\,{\frac { \left ( x+\zeta \right ) ^{2}}{k\,t}}}}}\,{\rm d}\zeta } \]
____________________________________________________________________________________
Solve the heat equation \[ u_t = k u_{xx} + m \] For \(-\infty <x<\infty \) and \(t>0\). Initial condition is \(u(x,0)=\sin (x)\)
Mathematica ✓
ClearAll[u, t, x, m, k]; pde = D[u[x, t], t] == k*D[u[x, t], {x, 2}] + m; ic = u[x, 0] == Sin[x]; sol = AbsoluteTiming[TimeConstrained[DSolve[{pde, ic}, u[x, t], {x, t}], 60*10]];
\[ \left \{\left \{u(x,t)\to e^{-k t} \sin (x)+m t\right \}\right \} \]
Maple ✓
L:='L'; u:='u'; t:='t'; x:='x';m:='m'; interface(showassumed=0); pde:=diff(u(x,t),t)=k*diff(u(x,t),x$2)+m; ic:=u(x,0)=sin(x); cpu_time := timelimit(60*10,CodeTools[Usage](assign('sol',pdsolve([pde,ic],u(x,t))),output='realtime'));
\[ u \left ( x,t \right ) =\sin \left ( x \right ) {{\rm e}^{-k\,t}}+mt \]
____________________________________________________________________________________
Solve the heat equation for \(u(x,t)\) \[ u_t= u_xx \]
Mathematica ✗
ClearAll[x, y, t]; pde = D[u[x, t], t] == D[u[x, t], {x, 2}]; sol = AbsoluteTiming[TimeConstrained[DSolve[pde, u[x, t], {x, t}], 60*10]];
\[ \text {Failed} \]
Maple ✓
x:='x'; u:='u'; t:='t'; pde := diff(u(x, t), t)=diff(u(x, t), x$2); cpu_time := timelimit(60*10,CodeTools[Usage](assign('sol',pdsolve(pde,u(x,t),'build') assuming t>0),output='realtime'));
\[ u \left ( x,t \right ) ={\it \_C3}\,{{\rm e}^{{\it \_c}_{{1}}t}}{\it \_C1}\,{{\rm e}^{\sqrt {{\it \_c}_{{1}}}x}}+{\frac {{\it \_C3}\,{{\rm e}^{{\it \_c}_{{1}}t}}{\it \_C2}}{{{\rm e}^{\sqrt {{\it \_c}_{{1}}}x}}}} \]
Hand solution
Solve\[ \frac {\partial u}{\partial t}=\frac {\partial ^{2}u}{\partial x^{2}}\] for \(t>0,-\infty <x<\infty \). Let \(u=X\left ( x\right ) T\left ( t\right ) \) then we obtain\[ T^{\prime }X=X^{\prime \prime }T \] Dividing by \(XT\neq 0\)\[ \frac {T^{\prime }}{T}=\frac {X^{\prime \prime }}{X}=-\lambda \] (Only positive eigenvalues are possible). The two ODE’s are\begin {align} T^{\prime }+\lambda T & =0\tag {1}\\ X^{\prime \prime }+\lambda X & =0\tag {2} \end {align}
Solution for (2) is \(X\left ( x\right ) =C_{1}e^{\sqrt {\lambda }x}+C_{2}e^{-\sqrt {\lambda }x}\) and solution for (1) is \(T\left ( t\right ) =C_{3}e^{-\lambda t}\). Hence\begin {align*} u\left ( x,t\right ) & =C_{3}e^{-\lambda t}\left ( C_{1}e^{\sqrt {\lambda }x}+C_{2}e^{-\sqrt {\lambda }x}\right ) \\ & =C_{3}e^{-\lambda t}C_{1}e^{\sqrt {\lambda }x}+C_{3}e^{-\lambda t}C_{2}e^{-\sqrt {\lambda }x}\\ & =C_{3}e^{-\lambda t}C_{1}e^{\sqrt {\lambda }x}+\frac {C_{3}e^{-\lambda t}C_{2}}{e^{\sqrt {\lambda }x}} \end {align*}
____________________________________________________________________________________
Added December 20, 2018.
Solve the heat equation for \(u(x,t)\) on real line with \(t>0\) \[ u_t = \mu u_{xx} - 1 \] With initial condition \[ u(x,1)= \begin {cases} 0 & x \geq 0 \\ 1 & x < 0 \end {cases} \]
Mathematica ✗
ClearAll[u, x, t, mu]; pde = D[u[x, t], t] + 1 == mu*D[u[x, t], {x, 2}]; ic = u[x, 1] == Piecewise[{{1, x <= 0}, {0, x > 0}}]; sol = AbsoluteTiming[TimeConstrained[DSolve[{pde, ic}, u[x, t], x, t, Assumptions -> mu > 0], 60*10]];
\[ \text {Failed} \] due to i.c. not at zero
Maple ✓
x:='x';t:='t';u:='u';mu:='mu'; pde := diff(u(x, t), t)+1 = mu* diff(u(x, t), x$2); ic := u(x, 1) = piecewise(0 <= x, 0, x < 0, 1); cpu_time := timelimit(60*10,CodeTools[Usage](assign('sol',pdsolve([pde, ic],u(x,t)) assuming mu>0, t>0),output='realtime'));
\[ u \left ( x,t \right ) =3/2-1/2\,\erf \left ( 1/2\,{\frac {x}{\sqrt {\mu }\sqrt {t-1}}} \right ) -t \]
Hand solution
Solve\[ u_{t}=\mu u_{xx}-1 \] for \(t>0,-\infty <x<\infty \) with initial conditions \(u\left ( x,0\right ) =f\left ( x\right ) =\left \{ \begin {array} [c]{cc}0 & x\geq 0\\ 1 & x<0 \end {array} \right . \)
Let \(v=u+t\). Hence \(u=v-t\) and \(u_{t}=v_{t}-1\) and \(u_{x}=v_{x}\) and \(u_{xx}=v_{xx}\). The above PDE becomes\begin {align} v_{t}-1 & =\mu v_{xx}-1\nonumber \\ v_{t} & =\mu v_{xx}\tag {1} \end {align}
Initial conditions do not change. They are \(v\left ( x,0\right ) =u\left ( x,0\right ) =\left \{ \begin {array} [c]{cc}0 & x\geq 0\\ 1 & x<0 \end {array} \right . \). Using Green function for 1D heat PDE on the real line, (also called heat Kernel) \[ G\left ( x,t\right ) =\frac {1}{\sqrt {4\pi \mu t}}e^{\frac {-x^{2}}{4\mu t}}\] Then the solution to (1) is \begin {align*} v\left ( x,t\right ) & =\int _{-\infty }^{\infty }f\left ( x^{\prime }\right ) G\left ( x-x^{\prime },t\right ) dx^{\prime }\\ & =\int _{-\infty }^{0}\frac {1}{\sqrt {4\pi \mu t}}e^{\frac {-\left ( x-x^{\prime }\right ) ^{2}}{4\mu t}}dx^{\prime }\\ v\left ( x,t\right ) & =\frac {-1}{\sqrt {4\pi \mu t}}\int _{0}^{\infty }e^{\frac {-\left ( x-x^{\prime }\right ) ^{2}}{4\mu t}}dx^{\prime } \end {align*}
But \(\int _{0}^{\infty }e^{\frac {-\left ( x-x^{\prime }\right ) ^{2}}{4\mu t}}dx^{\prime }=\sqrt {\pi \mu t}\left ( 1+\operatorname {erf}\left ( \frac {x}{2\sqrt {\mu t}}\right ) \right ) \), hence
\[ v\left ( x,t\right ) =\frac {-1}{2}\left ( 1+\operatorname {erf}\left ( \frac {x}{2\sqrt {\mu t}}\right ) \right ) \]
Since \(u=v-t\) then\begin {align*} u\left ( x,t\right ) & =\frac {-1}{2}\left ( 1+\operatorname {erf}\left ( \frac {x}{2\sqrt {\mu t}}\right ) \right ) -t\\ & =-\frac {1}{2}-\frac {1}{2}\operatorname {erf}\left ( \frac {x}{2\sqrt {\mu t}}\right ) -t \end {align*}