Solve an Initial Value Problem for the Heat Equation
Specify the heat equation.
In[1]:=
heqn = D[u[x, t], t] == D[u[x, t], {x, 2}];
Prescribe an initial condition for the equation.
In[2]:=
ic = u[x, 0] == E^(-x^2);
Solve the initial value problem.
In[3]:=
sol = DSolveValue[{heqn, ic }, u[x, t], {x, t}]
Out[3]=
Visualize the diffusion of heat with the passage of time.
In[4]:=
Plot[Evaluate[Table[sol, {t, 0, 4}]], {x, -5, 5}, PlotRange -> All,
Filling -> Axis]
Out[4]=
Initial value problem for the heat equation with piecewise initial data.
In[5]:=
ic = u[x, 0] == UnitBox[x];
In[6]:=
sol = DSolveValue[{heqn, ic }, u[x, t], {x, t}]
Out[6]=
Discontinuities in the initial data are smoothed instantly.
In[7]:=
Plot3D[sol, {x, -2, 2}, {t, 0, 1}, PlotRange -> All,
PlotPoints -> 250, Mesh -> None]
Out[7]=