Solve an Initial Value Problem for the Heat Equation
Specify the heat equation.
In[1]:=
![Click for copyable input](assets.en/solve-an-initial-value-problem-for-the-heat-equati/In_11.png)
heqn = D[u[x, t], t] == D[u[x, t], {x, 2}];
Prescribe an initial condition for the equation.
In[2]:=
![Click for copyable input](assets.en/solve-an-initial-value-problem-for-the-heat-equati/In_12.png)
ic = u[x, 0] == E^(-x^2);
Solve the initial value problem.
In[3]:=
![Click for copyable input](assets.en/solve-an-initial-value-problem-for-the-heat-equati/In_13.png)
sol = DSolveValue[{heqn, ic }, u[x, t], {x, t}]
Out[3]=
![](assets.en/solve-an-initial-value-problem-for-the-heat-equati/O_7.png)
Visualize the diffusion of heat with the passage of time.
In[4]:=
![Click for copyable input](assets.en/solve-an-initial-value-problem-for-the-heat-equati/In_14.png)
Plot[Evaluate[Table[sol, {t, 0, 4}]], {x, -5, 5}, PlotRange -> All,
Filling -> Axis]
Out[4]=
![](assets.en/solve-an-initial-value-problem-for-the-heat-equati/O_8.png)
Initial value problem for the heat equation with piecewise initial data.
In[5]:=
![Click for copyable input](assets.en/solve-an-initial-value-problem-for-the-heat-equati/In_15.png)
ic = u[x, 0] == UnitBox[x];
In[6]:=
![Click for copyable input](assets.en/solve-an-initial-value-problem-for-the-heat-equati/In_16.png)
sol = DSolveValue[{heqn, ic }, u[x, t], {x, t}]
Out[6]=
![](assets.en/solve-an-initial-value-problem-for-the-heat-equati/O_9.png)
Discontinuities in the initial data are smoothed instantly.
In[7]:=
![Click for copyable input](assets.en/solve-an-initial-value-problem-for-the-heat-equati/In_17.png)
Plot3D[sol, {x, -2, 2}, {t, 0, 1}, PlotRange -> All,
PlotPoints -> 250, Mesh -> None]
Out[7]=
![](assets.en/solve-an-initial-value-problem-for-the-heat-equati/O_10.png)