︠eaec9b65-76fa-46fb-bcce-6b13ad79d0b3i︠ %html

Solving the Heat Equation

Joel H. Shapiro

Portland State University

www.mth.pdx.edu/~shapiroj

1. Introduction

For a metal rod of unit length, placed (for mathematical convenience) on the real interval $[0,\pi]$, let $u(x,t)$ denote the temperature of the rod at the cross-section $x$ units from the origin at time $t$ (we assume the temperature to be constant on each cross-section of the rod. Then the function $u$ is known to obey the Heat Equation: $u_t = ku_{xx}$, where $k$ is a positive constant that is a property of the material used to form the rod.

Suppose, for simplicity, that $k=1$, and we have these initial-boundary conditions:

    (1) the ends of the rod are held at constant temperature zero for all time: $u(0,t)=u(1,t)=0$ for all $t \ge 0$, and

    (2) the initial temperature of the rest of the rod is 1, i.e., $u(x,0) \equiv 1$ on $(0,\pi)$.

Then the solution to our our initial-boundary problem, consisting of the heat equation $u_t = u_{xx}$, along with boundary condition (1) and initial condition (2), is given by the series below: $$ (*)~~~~~ {\displaystyle u(x,t) = \sum_{k=0}^\infty e^{-(2k+1)^2 t}~\frac{\sin((2k+1)x)}{2k+1}} $$

To see that this series really does solve our initial-boundary problem for the heat equation, note that formal term-by-term differentiation (justified by the exponential decay of the time-dependent terms) shows that $u$ satisfies the heat equation, while the substitution $x=0$ and $x=\pi$ show that (1) is satisfied. As for (2): the series for $t=0$ is the Fourier sine series for the function $f\equiv 1$ over the interval $[0,\pi]$. See [1, Sec. 1.8.3-1.8.4, pp. 63--70], [2, Sec. 18.10, especially pp. 999--1004], or [3] for more details, and to learn how to discover this formula for $u(x,t)$.

 

2. Plotting the solution

We'll define here a function u(x,t,n) that returns the sum of the first $n$ terms of the series (*), and another one, P(t,n) that plots this sum as a function of $x$, using the time $t$ as a parameter.

SAGE commands featured here: def, sum(), plot(), Graphics(), srange(), show().

︡a5467467-b43b-45e8-b492-b1eb53d2b254︡{"html": "\r\n\r\n \r\n \r\n\r\n\r\n\r\n\r\n\r\n

Solving the Heat Equation

\r\nJoel H. Shapiro\r\n

Portland State University

\r\n \r\n\r\nwww.mth.pdx.edu/~shapiroj \r\n\r\n\r\n\r\n

1. Introduction

\r\n

For a metal rod of unit length, placed (for mathematical convenience) on the real interval $[0,\\pi]$, let $u(x,t)$ denote the temperature of the rod at the cross-section $x$ units from the origin at time $t$ (we assume the temperature to be constant on each cross-section of the rod. Then the function $u$ is known to obey the Heat Equation: $u_t = ku_{xx}$, where $k$ is a positive constant that is a property of the material used to form the rod.\r\n

\r\n

Suppose, for simplicity, that $k=1$, and we have these initial-boundary conditions:

\r\n

   \r\n (1) the ends of the rod are held at constant temperature zero for all time: $u(0,t)=u(1,t)=0$ for all $t \\ge 0$, and

\r\n

   \r\n (2) the initial temperature of the rest of the rod is 1, i.e., $u(x,0) \\equiv 1$ on $(0,\\pi)$.

\r\n

Then the solution to our our initial-boundary problem, consisting of the heat equation $u_t = u_{xx}$, along with boundary condition (1) and initial condition (2), is given by the series below: \r\n$$ (*)~~~~~ {\\displaystyle u(x,t) = \\sum_{k=0}^\\infty e^{-(2k+1)^2 t}~\\frac{\\sin((2k+1)x)}{2k+1}} $$\r\n

\r\n

\r\nTo see that this series really does solve our initial-boundary problem for the heat equation, note that formal term-by-term differentiation (justified by the exponential decay of the time-dependent terms) shows that $u$ satisfies the heat equation, while the substitution $x=0$ and $x=\\pi$ show that (1) is satisfied. As for (2): the series for $t=0$ is the Fourier sine series for the function $f\\equiv 1$ over the interval $[0,\\pi]$. See [1, Sec. 1.8.3-1.8.4, pp. 63--70], [2, Sec. 18.10, especially pp. 999--1004], or [3] for more details, and to learn how to discover this formula for $u(x,t)$. \r\n

\r\n\r\n

 

\r\n

2. Plotting the solution

\r\n

We'll define here a function u(x,t,n) that returns the sum of the first $n$ terms of the series (*), and another one, P(t,n) that plots this sum as a function of $x$, using the time $t$ as a parameter.

\r\n

SAGE commands featured here: def, sum(), plot(), Graphics(), srange(), show().

"}︡ ︠1ed163f0-d1eb-4039-bb60-769eb923d320︠ def u(x,t,n): return (4/pi)*sum([exp(-(2*k+1)^2*t)*sin((2*k+1)*x)/(2*k+1) for k in range(n)]) ︡6bd92681-2531-4761-8e83-090fc291ab47︡︡ ︠3ece0775-1006-47d7-986a-323ea7ccbc40i︠ %html

Here is the sum of the first five terms of the series (*)

︡895b8714-60a0-4bdd-b5de-c79d8c5ea022︡{"html": "

\r\nHere is the sum of the first five terms of the series (*)\r\n

"}︡ ︠976ecec3-cec4-4d71-96b0-a7141d4fee19︠ var('t') u(x,t,5).show() #Sum of first five terms. ︡5958fc04-bc64-46df-8b7b-512040ac36eb︡{"html": "
\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\frac{4 \\, {\\left(35 \\, e^{\\left(-81 \\, t\\right)} \\sin\\left(9 \\, x\\right) + 45 \\, e^{\\left(-49 \\, t\\right)} \\sin\\left(7 \\, x\\right) + 63 \\, e^{\\left(-25 \\, t\\right)} \\sin\\left(5 \\, x\\right) + 105 \\, e^{\\left(-9 \\, t\\right)} \\sin\\left(3 \\, x\\right) + 315 \\, e^{\\left(-t\\right)} \\sin\\left(x\\right)\\right)}}{315 \\, \\pi}
"}︡ ︠a850e757-7b37-4d3f-b8cb-7c61068ea4e8i︠ %html

For $t = 0$ the infinite series (*) is the Fourier sine series of the function identically 1 on the interval $(0,\pi)$. We superimpose the graph of this function (in red) on a plot of the sum of the first 25 terms of that sine series.

︡477524e8-56cd-4cde-85c3-824100099460︡{"html": "

For $t = 0$ the infinite series (*) is the Fourier sine series of the function identically 1 on the interval $(0,\\pi)$. We superimpose the graph of this function (in red) on a plot of the sum of the first 25 terms of that sine series.\r\n

"}︡ ︠49fb32d5-0105-4d5a-9f49-1c1a90480b03︠ fs = u(x,0,25) #Plot of fs approx. to initial function init_temp = x^0 #The init. temp distn u(x,0) = 1 Pfs = fs.plot((0,pi+.1)) #Plot fs partial sum in blue one = init_temp.plot((0,pi),rgbcolor=[1,0,0]) #Plot init temp in red (Pfs+one).show(xmin=-.1, xmax=pi+.1, ymin=0,figsize=[3,3]) #Show both plots on same set of axes ︡75bf3dee-64ca-4de7-8410-a029f60c394b︡{"html": ""}︡ ︠008989e8-dfe3-4ed0-9bac-22537ea2fd4fi︠ %html

Now we define a function $P$ that maps the $n$-th partial sum of (*) to a graphics object having $t$ as parameter (i.e., $P:[0,\infty)\times\{{\rm Natural~numbers}\}\rightarrow \{\rm Graphics~objects\}$). The type() command tests what we've done.

︡6d2563b3-bb90-4df3-bc62-f48f9c5353b5︡{"html": "

\r\nNow we define a function $P$ that maps the $n$-th partial sum of (*) to a graphics object having $t$ as parameter (i.e., $P:[0,\\infty)\\times\\{{\\rm Natural~numbers}\\}\\rightarrow \\{\\rm Graphics~objects\\}$). The type() command tests what we've done.\r\n

"}︡ ︠ba77ae7d-d75f-4ae5-b0ba-88f9cca286ab︠ def P(t,n): fs = u(x,t,n) return fs.plot((-.1,pi+.1),rgbcolor=[sin(t),cos(t),exp(-t)]); #colors change with t ︡236ec1a1-6476-4a14-a831-f5c13ee146a2︡︡ ︠f3e9153d-23e7-4255-bea0-d8771cdd69e7i︠ %html

Next we plot, for t=.01, .5, 1,2,and 3, the 25th partial sum of series for $u(x,t)$. Compare the plot for $t=.01$ with the one above for $t=0$, noting how effectively the exponential "multiplier" smooths out the partial sum.

︡0e138e19-3423-4f99-bfa9-eb205fa4e9cb︡{"html": "

\r\nNext we plot, for t=.01, .5, 1,2,and 3, the 25th partial sum of series for $u(x,t)$. Compare the plot for $t=.01$ with the one above for $t=0$, noting how effectively the exponential \"multiplier\" smooths out the partial sum.\r\n

"}︡ ︠c8155695-240d-4895-902b-6d8d0bf95733︠ show(P(.01,25)+P(.5,25)+P(1,25)+P(2,25)+P(3,25),ymin=0,ymax=1) ︡2ac77580-c1fc-4749-bc4f-41e11bb1b32a︡{"html": ""}︡ ︠589d38da-9346-462d-a360-b93f541938cci︠ %html

3. Visualizing the solution with @interact

︡ee4b0385-799f-40b1-8aa8-49f789aedb6f︡{"html": "

3. Visualizing the solution with @interact

"}︡ ︠1b774fc5-a4fc-466a-9c8b-360d424a16eb︠ #"continuous" parameter t set automatically for 50 equally spaced values in [0,5] @interact def _(t=(0,5)): show(P(t,25), ymax=1) ︡47c3fb3a-7b0d-40cd-97ae-820cc0f622da︡︡ ︠c274b24e-78b0-4336-ba70-4887668319c9i︠ %html

4. Animating the solution via @interact

Here's an animation inspired by a Maple program written by Paul Bourdon. We represent the rod by 100 large dots on the $x$-axis, and the temperature $u(x,t)$ of (the center of) each dot by a color, ranging from red (hot) to white(cold). The distribution of colors at time t represents $u(x,t)$. The animation shows the temperature at each point cooling from the initial temperature 1 toward zero as $t\rightarrow\infty$.

The first step is to define the function cool(t,n) that colors the 100 consecutive points on the $x$-axis according to the value $u(x,t)$.

︡eee6ecf6-9da9-4bdb-9ec2-6e7e821e2306︡{"html": "

4. Animating the solution via @interact

\r\n\r\n

Here's an animation inspired by a Maple program written by Paul Bourdon. We represent the rod by 100 large dots on the $x$-axis, and the temperature $u(x,t)$ of (the center of) each dot by a color, ranging from red (hot) to white(cold). The distribution of colors at time t represents $u(x,t)$. The animation shows the temperature at each point cooling from the initial temperature 1 toward zero as $t\\rightarrow\\infty$. \r\n

\r\n\r\n

\r\nThe first step is to define the function cool(t,n) that colors the 100 consecutive points on the $x$-axis according to the value $u(x,t)$.\r\n

"}︡ ︠acbc293a-84ae-4e8c-97a6-68263f826b0d︠ def cool(t,n): g = Graphics() for k in range(100): v = u(pi*k/100,t,n) g += point((pi*k/100,0),pointsize=100, rgbcolor=[1,1-sqrt(v),1-sqrt(v)]) return g ︡37bdc392-c2a7-4bdc-a5f1-dc362855d9dc︡︡ ︠496b9a8f-e0c5-4672-9fba-346c16c27791︠ cool(.05,10).show(axes=false) #Testing our definition ︡9519ba5a-3c4c-4313-a03b-7bf9fc684ff0︡{"html": ""}︡ ︠8fbbf9e6-1ded-4f52-819e-6598f74741d1i︠ %html

︡8947b66b-641e-4586-aeb2-e26c042ba6c7︡{"html": "

"}︡ ︠73e74360-277a-47b0-bb7b-2acae54104d6︠ #"continuous" parameter t set automatically for 50 equally spaced values in interval [.02,5] @interact def _(t=(0.02,5)): show(cool(t,25), axes=false) ︡2a75c079-78ce-442e-9cff-8ecf91e41667︡︡ ︠543b92f2-d43e-40da-a1f2-6718d37e90d4i︠ %html

References

[1] H. Dym and H.P. McKean, Fourier Series and Integrals, Academic Press 1972.

[2] A. Jeffrey, Advanced Engineering Mathematics, Harcourt/Academic Press 2002.

[3] Weisstein, Eric W. Heat Conduction Equation. From MathWorld--A Wolfram Web Resource. http://mathworld.wolfram.com/HeatConductionEquation.html

︡b3b18c9a-67d5-44ee-aa9c-b1b3b69f7cfd︡{"html": "

References

\r\n

\r\n[1] H. Dym and H.P. McKean, Fourier Series and Integrals, Academic Press 1972.\r\n

\r\n

\r\n[2] A. Jeffrey, Advanced Engineering Mathematics, Harcourt/Academic Press 2002.\r\n

\r\n

\r\n[3] Weisstein, Eric W. Heat Conduction Equation. From MathWorld--A Wolfram Web Resource. \r\n\r\nhttp://mathworld.wolfram.com/HeatConductionEquation.html \r\n

"}︡