Example Resource

Solve the 2D Heat Equation

Source Notebook

Solve the 2D Heat Equation

 

Examples

The heat equation describes how heat flows in a material. In this example we look at a 2D region over which we solve initial value problems to describe heat flow. We obtain both symbolic and numerical results for our solutions.

Define the heat equation: tu=2u in 2D:

In[1]:=
heat = D[u[x, y, t], t] == Laplacian[u[x, y, t], {x, y}]
Out[1]=

Choose a region to solve the heat equation on:

In[2]:=
Graphics[\[CapitalOmega] = Rectangle[{0, 0}, {2, 1}]]
Out[2]=

Select an initial condition for the heat of the region as an arbitrary function:

In[3]:=
ic = Sin[2 \[Pi] x] Cos[\[Pi] y]; DensityPlot[ic, {x, y} \[Element] \[CapitalOmega], AspectRatio -> Automatic, PlotLegends -> Automatic, FrameLabel -> {x, y}]
Out[3]=

Solve the heat equation on this region for the above initial conditions:

In[4]:=
sol[x_, y_, t_] = DSolveValue[{heat, u[x, y, 0] == ic}, u[x, y, t], {x, y, t}]
Out[4]=

We see that the solution is just the same as the initial condition, but with a decaying exponential out front. This is because the initial condition could be separated into functions of each variable u[x,y,0]=f[x]g[y] with f[x]=Sin[2π x] and g[y]=Cos[π y]. What about an initial condition where this isn't true?

In[5]:=
ic = Sin[\[Pi] x Cos[2 \[Pi] y]]; DensityPlot[ic, {x, y} \[Element] \[CapitalOmega], AspectRatio -> Automatic, PlotLegends -> Automatic, FrameLabel -> {x, y}]
Out[5]=

Let's add a periodic boundary condition since our initial condition is periodic in y:

In[6]:=
BC = PeriodicBoundaryCondition[u[x, y, t], y == 0, TranslationTransform[{0, 1}]];

Solve the heat equation on Ω with this more complicated initial condition. This time use NDSolveValue to get a numerical result:

In[7]:=
sol[x_, y_, t_] = NDSolveValue[{heat, u[x, y, 0] == ic, BC}, u[x, y, t], {t, 0, 3}, {x, y} \[Element] \[CapitalOmega]]
Out[7]=

After just t=0.1, the higher frequency wiggles dissipated away and only the longer frequency wiggles survive:

In[8]:=
DensityPlot[sol[x, y, 0.1], {x, y} \[Element] \[CapitalOmega], AspectRatio -> Automatic, FrameLabel -> Automatic]
Out[8]=

Source Metadata

Publisher Information