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["Global`*"]; 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 \fbox {$\frac {e^{-\frac {x^2}{4 t+1}}}{\sqrt {4+\frac {1}{t}} \sqrt {t}}\text { if }\Re \left (\frac {1}{t}\right )\geq -4$}\right \}\right \}\]
Maple ✓
restart; 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 {{\mathrm e}^{-\frac {x^{2}}{4 t +1}}}{\sqrt {4 t +1}}\]
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["Global`*"]; 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 t \sin (t)+x\}\}\]
Maple ✓
restart; 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 ) = x -\cos \left (t \right )+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["Global`*"]; 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 {2 x+1}{4 \sqrt {t}}\right )-\text {erf}\left (\frac {2 x-1}{4 \sqrt {t}}\right )\right )\right \}\right \}\]
Maple ✓
restart; 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 ) = -\frac {\erf \left (\frac {2 x -1}{4 \sqrt {t}}\right )}{2}+\frac {\erf \left (\frac {2 x +1}{4 \sqrt {t}}\right )}{2}\]
____________________________________________________________________________________
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["Global`*"]; 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 \frac {\int _{-\infty }^{\infty }e^{s (i x-k s t)} \int _{-\infty }^{\infty }e^{-i s x} f(x)dxds}{2 \pi }\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); 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 ) = \frac {\int _{-\infty }^{\infty }\frac {2 \pi ^{\frac {3}{2}} {\mathrm e}^{-\frac {\left (x +\zeta \right )^{2}}{4 k t}} f \left (-\zeta \right )}{\sqrt {k}\, \sqrt {t}}d \zeta }{4 \pi ^{2}}\]
____________________________________________________________________________________
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["Global`*"]; 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 ✓
restart; 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 ) = m t +{\mathrm e}^{-k t} \sin \left (x \right )\]
____________________________________________________________________________________
Solve the heat equation for \(u(x,t)\) \[ u_t= u_xx \]
Mathematica ✓
ClearAll["Global`*"]; pde = D[u[x, t], t] == D[u[x, t], {x, 2}]; sol = AbsoluteTiming[TimeConstrained[DSolve[pde, u[x, t], {x, t}], 60*10]];
\[\{\{u(x,t)\to \cosh (c_2 (x+c_2 t)+c_1)+\sinh (c_2 (x+c_2 t)+c_1)+1\}\}\]
Maple ✓
restart; 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 ) = c_{3} \left (c_{1} {\mathrm e}^{2 x \sqrt {\textit {\_c}_{1}}}+c_{2}\right ) {\mathrm e}^{t \textit {\_c}_{1}} {\mathrm e}^{-x \sqrt {\textit {\_c}_{1}}}\]
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["Global`*"]; 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]];
\[\left \{\left \{u(x,t)\to \frac {\int _{-\infty }^{\infty }\frac {i e^{K[1] (i x-\mu (t-1) K[1])}}{K[1]}dK[1]}{2 \pi }\right \}\right \}\] due to i.c. not at zero
Maple ✓
restart; 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 ) = -t -\frac {\erf \left (\frac {x}{2 \sqrt {t -1}\, \sqrt {\mu }}\right )}{2}+\frac {3}{2}\]
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*}
____________________________________________________________________________________
Added May 23, 2019.
From Math 5587 midterm I, Fall 2016, practice exam, problem 14.
Solve for \(u(x,t)\) with IC \(u(x,0)=x\) for \(-\infty <x<\infty ,t>0\) \begin {align*} u_{t} = u_{xx} \end {align*}
Mathematica ✓
ClearAll["Global`*"]; pde = D[u[x, t], t] == D[u[x,t],{x,2}]; ic = u[x,0]==x; sol = AbsoluteTiming[TimeConstrained[DSolve[{pde,ic}, u[x, t], {x, t}], 60*10]];
\[\{\{u(x,t)\to \fbox {$x\text { if }\Re (t)\geq 0$}\}\}\]