Wolfram Language

Partial Differential Equations

Solve an Initial Value Problem for the Heat Equation

Specify the heat equation.

In[1]:=
Click for copyable input
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
ic = u[x, 0] == E^(-x^2);

Solve the initial value problem.

In[3]:=
Click for copyable input
sol = DSolveValue[{heqn, ic }, u[x, t], {x, t}]
Out[3]=

Visualize the diffusion of heat with the passage of time.

In[4]:=
Click for copyable input
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]:=
Click for copyable input
ic = u[x, 0] == UnitBox[x];
In[6]:=
Click for copyable input
sol = DSolveValue[{heqn, ic }, u[x, t], {x, t}]
Out[6]=

Discontinuities in the initial data are smoothed instantly.

In[7]:=
Click for copyable input
Plot3D[sol, {x, -2, 2}, {t, 0, 1}, PlotRange -> All, PlotPoints -> 250, Mesh -> None]
Out[7]=

Related Examples

de es fr ja ko pt-br ru zh