\documentclass{article}
%\pagestyle{empty}
\usepackage{graphicx, amssymb,amsmath,amsfonts, psfrag}
\usepackage{amsmath}
\usepackage[usenames,dvipsnames]{xcolor}
\setlength{\textheight}{9in}
\setlength{\topmargin}{0in}
\setlength{\textwidth}{6in}
\setlength{\oddsidemargin}{+0.5in}
\newcommand{\dis}{\displaystyle}
\newcommand{\bd}{\partial}

\newcommand{\green}[1]{\textcolor{ForestGreen}{#1}}
\newcommand{\red}[1]{\textcolor{red}{#1}}
\newcommand{\blue}[1]{\textcolor{blue}{#1}}

\begin{document}


\begin{center}{\bf The Heat Equation}\end{center}

\vspace{0.5in}


We consider a metal rod of length $L$. Suppose that initially the temperature 
at each point $x \in [0,L]$ along the rod is given by $f(x)$. We wish to know 
how the temperature will evolve over time. Let 
\[
u(x,t)
\]
be the temperature at location $x$ and time $t$. 
Thus, $u(x,0) = f(x)$. The evolution of the temperature along to rod 
is modeled by the {\bf heat equation}, which is 
\[
\alpha^2 \frac{\bd^2 u}{\bd x^2} = \frac{\bd u}{\bd t},
\]
or $\alpha^2 u_{xx} = u_t$. See Appendix in textbook. 

We will make an additional assumption that temperature of the ends of 
the metal rod are held at fixed temperatures. This gives the
{\bf boundary conditions}
\[
u(0,t) = T_1 \hspace{.5in} \& \hspace{.5in} u(L,t) = T_2.
\]
Later we will consider other types of boundary conditions. 

We will solve the present problem in two steps. First, we assume
$T_1=T_2=0$. Then we will show how to jazz this up to the more general
case.

\vfill
\pagebreak


\begin{center}{\bf Solving Homogeneous Case} \end{center}
\vspace{0.5in}

Step 1 is to solve the following model. 

\vspace{0.3in}

\begin{center}
\fbox{\parbox{3in}{
\[
\alpha^2 u_{xx} = u_{t}
\]

\[
u(0,t) = u(L,t) = 0
\]

\[
u(x,0) = f(x)
\]
where $f(x)$ will be given.}}
\end{center}

\vspace{0.3in}




{\bf Solution.} Suppose $u(x,t) = X(x) T(t)$. Then $u_{xx}(x,t) = X''(x)T(t)$ and $u_t(x,t) = X(x)T'(t)$. Therefore,
\[
\alpha^2 X''T = XT'  \hspace{0.5in} \implies  \hspace{0.5in} \frac{X''}{X} = \frac{1}{\alpha^2}\frac{T'}{T}.
\]
This implies that each side of the second equation above must be constant. We call the constant $-\sigma$.
This yields two ordinary differential equations.
\[
X'' + \sigma X = 0 \hspace{0.5in} \&  \hspace{0.5in} T' + \sigma \alpha^2 T = 0.
\]
The boundary conditions $u(0,t) = u(L,t) = 0$ implies $X(0) = X(L) = 0$. Then for the equation in $X$ the 
analysis we did for the wave equation goes through in exactly the same way. We conclude that
non trivial solution exist only when $\sqrt{\sigma} = \dfrac{n\pi}{L}$ where $n$ is an integer, and that
\[
X(x) = C \sin \left( \frac{n\pi x}{L} \right)
\]
gives a solution for any real number $C$ and integer $n$. Let 
\[
X_n(x) =  \sin \left( \frac{n\pi x}{L} \right), \:\:\mbox{ for }\:\: n\geq 1.
\]
Note: $n=0$ gives a trivial solution and negative values for $n$ are redundant.

Now, consider the ordinary differential equation in $T$. Its general solution  is just
\[
T(t) = C e^{-\sigma\alpha^2t} =  C e^{-\frac{n^2\pi^2\alpha^2}{L^2}t}.
\]
We let
\[
T_n(t) = e^{-\frac{n^2\pi^2\alpha^2}{L^2}t}  \hspace{0.5in} \&  \hspace{0.5in} u_n(x,t) = X_n(x)T_n(t) \:\:\: \mbox{ for }\:\: n\geq 1.
\]



\vfill
\pagebreak
\begin{center}{\bf Putting It All Together} \end{center}
\vspace{0.25in}



From last page we have
\[
u_n(x,t) = X_n(x)T_n(t) = \sin\left(\frac{n\pi x}{L}\right) e^{-\frac{n^2\pi^2\alpha^2}{L^2}t}  \:\:\: \mbox{ for } n\geq 1 .
\]
Each $u_n$ satisfies the heat equation and the boundary conditions. So would any linear combination of $u_n$. 
It is shown in Math 407 that if $\{ c_n \}_{n=1}^\infty$ are such that
\[
u(x,t) = \sum_{n=1}^\infty c_n u_n(x,t)
\]
converges, then $u(x,t)$  satisfies the heat equation (almost everywhere) and the boundary conditions. 

\vspace{.3in}

Therefore, if we can find values for the $c_n$'s such that 
\[
u(x,0) =  \sum_{n=1}^\infty\sin\left(\frac{n\pi x}{L}\right) = f(x)
\]
where $f(x)$ is the initial temperature distribution, then $u(x,t)$ will satisfy all our requirements.

\vspace{.3in}

{\bf Example.} Suppose $f(x) = 10$, $L=1$ and $\alpha=1$. At the instant $t=0$ the end points of the rod put 
into contact with degree zero heat sinks. We will model what happens next. 


\begin{center} 
\psfrag{a}{$0^o$}
\psfrag{b}{$0^o$}
\psfrag{10}{$10^o$}
\includegraphics[height=1.0in]{Figs/hotrod.eps}
\end{center}


The odd periodic extension of $f(x)$ is a square wave. Let $L=1$. We compute the $c_n$'s. 
\[
c_n = \frac{1}{1} \int_{-1}^1 \sin(n\pi x) f(x) \, dx = 20 \int_0^1 \sin(n\pi x) \, dx = -\frac{20}{n\pi} \big[ \cos(n\pi)- \cos(0)\big] =
\left\{\begin{array}{ccc}\dfrac{40}{n\pi} & \mbox{ for } & n \mbox{ odd},\\
 &&\\
                         0        & \mbox{ for } & n \mbox{ even}.
\end{array}\right.
\]
Thus,
\[
u(x,t) = \sum_{k=1}^\infty \frac{40}{(2k-1)\pi} \sin( (2k-1)\pi x) e^{-(2k-1)^2\pi^2 t}.
\]


An animation is on the web page. On the next page are some snapshots.  



\vfill
\pagebreak


\begin{center}{\bf Some Plots for the Last Example} \end{center}
\vspace{0.5in}


\begin{center}

\includegraphics[height=1.8in]{Heat2plot2.eps}
\includegraphics[height=1.8in]{Heat2plot3.eps}
\includegraphics[height=1.8in]{Heat2plot4.eps}

\vspace{0.5in}


\includegraphics[height=1.8in]{Heat2plot5.eps}
\includegraphics[height=1.8in]{Heat2plot6.eps}
\includegraphics[height=1.8in]{Heat2plot7.eps}

\vspace{0.5in}

\includegraphics[height=1.8in]{Heat2plot8.eps}
\includegraphics[height=1.8in]{Heat2plot9.eps}

\end{center}


\vfill
\pagebreak
\begin{center}
{\bf A Crazy Example }
\end{center}

Suppose $L=1$, $\alpha=1$ and the initial temperature distribution is given by 
\[
f(x) = \left\{\begin{array}{lll}
0 & \mbox{ for } & 0\leq x < 0.2 \\
-500(x-0.2)(x-0.4) & \mbox{ for } & 0.2\leq x < 0.4 \\
0 & \mbox{ for } & 0.4\leq x < 0.6 \\
4 & \mbox{ for } & 0.6\leq x < 0.8 \\
0 & \mbox{ for } & 0.8\leq x < 1.0 
\end{array}
  \right.
\]
Below is a graph.


\begin{center}
\includegraphics[height=1.5in]{Heat2plot10.eps}
\end{center}

Here are the Maple comands that created it.

\vspace{.2in}
{\tt
\noindent \red{> f := x -> piecewise(x<.2, 0, x>=.2 and x<=.4 , -500*(x-0.2)*(x-0.4), \\x>0.4 and x<0.6, 0, x>=0.6 and x<=0.8, 4, x>0.8, 0);
}

\vspace{.1in}
\noindent\red{> plot(f(x),x=0..1);}
}

\vspace{.2in}
The coefficients are given by $c_n = 2 \dis\int_0^1 \sin(n\pi x) f(x) \, dx$. I did not bother trying to find a formula for the $c_n$, I just used the integral. Thus the solution is
\[
u(x,t) = \sum_{n=1}^\infty c_n \sin(n\pi x) e^{-n^2\pi^2t}. 
\]
I created an animation using the commands below. I took the sum out to $n=50$, but this is likely overkill. It is on the webpage.

\vspace{.2in}
{\tt  
\noindent\red{> c := n -> 2*int(sin(n*Pi*x)*f(x) ,x=0..1);}

\vspace{.1in}
\noindent\red{> animate(sum( c(n)*sin((n)*Pi*x)*exp(-(n\^{}2*Pi\^{}2*t)) ,n=1..50), \\x=0..1,t=0..0.2,numpoints=1000,frames=100);}
}


\vspace{0.3in}

Snapshots of the animation are on the next page. 


\vfill
\pagebreak

\begin{center}{\bf Some Plots for the Last Example} \end{center}
\vspace{0.5in}

\begin{center}


\includegraphics[height=1.8in]{Heat2plot13.eps}
\includegraphics[height=1.8in]{Heat2plot14.eps}
\includegraphics[height=1.8in]{Heat2plot15.eps}

\includegraphics[height=1.8in]{Heat2plot16.eps}
\includegraphics[height=1.8in]{Heat2plot17.eps}
\includegraphics[height=1.8in]{Heat2plot18.eps}

\includegraphics[height=1.8in]{Heat2plot19.eps}
\includegraphics[height=1.8in]{Heat2plot20.eps}
\includegraphics[height=1.8in]{Heat2plot21.eps}
%\includegraphics[height=1.8in]{Heat2plot22.eps}

\end{center}


\vfill
\pagebreak
\begin{center}{\bf Heat Equation with \\Nonhomogeneous Boundary Conditions}\end{center}
\vspace{0.5in}

Now we are working with the model
\begin{center}
\fbox{\parbox{3in}{
\[
\alpha^2 u_{xx} = u_{t}
\]

\[
u(0,t) = T_1 \hspace{0.5in} \& \hspace{0.5in} u(L,t) = T_2
\]

\[
u(x,0) = f(x)
\]
where $f(x)$ will be given.}}
\end{center}

{\bf Key Idea.} As $t\to\infty$ we think that $u(x,t) \to \dfrac{T_2-T_1}{L} x + T_1$. So, we let
\[
v(x) = \dfrac{T_2-T_1}{L} x + T_1 \hspace{0.5in} \mbox{and} \hspace{0.5in} w(x,t) = u(x,t) - v(x).
\]
Notice that $w_{xx} = u_{xx}$ and $w_t = u_t$. Therefore, $w$ satisfies the heat equation
\[
\alpha^2 w_{xx} = w_t.
\]
Further, $w(0,t) = u(0,t) - v(0) = T_1 - T_1 = 0$ and likewise $w(L,t) = 0$. However,
\[
w(x,0) = u(x,0) - v(x) = f(x) - v(x).
\]
Let $g(x) = f(x)- v(x)$. Then $w(x,t)$ satisfies the model below.
\begin{center}
\fbox{\parbox{3in}{
\[
\alpha^2 w_{xx} = w_{t}
\]

\[
w(0,t) = w(L,t) = 0
\]

\[
w(x,0) = g(x).
\]
}}
\end{center}

Our plan is to solve this model for $w(x,t)$ and then add $v(x)$ to get $u(x,t)$.
We do this in the next example.



\vfill
\pagebreak
\begin{center} {\bf Example} \end{center}
\vspace{0.5in}

Let $L=1$, $T_1 = 10^o$ and $T_2=20^o$. We suppose the bar starts with uniform temperature $10^o$ and at time $t=0$
the ends are set to a heat bath of $T_1$ or the right and $T_2$ on the left. 

\begin{center} 
\psfrag{a}{$10^o$}
\psfrag{b}{$20^o$}
\psfrag{10}{$10^o$}
\includegraphics[height=1.0in]{Figs/hotrod.eps}
\end{center}

Thus, $v(x) = 10x + 10$ and $g(x)=-10$. Next we compute the Fourier series coefficients for the odd periodic 
extension of $g(x)$. The graph of the odd periodic extension of $g(x)$ is below along with the command that created it. Note: {\tt frac} is a Maple command that gives the fractional part of a number.

\vspace{.2in}
{\tt > plot(piecewise(x>=-1,-20*frac((x+1)/2)+10,x<-1,-20*frac((x+1)/2)-10), \\x=-5..5,discont=true, color=plum, thickness=2);}

\begin{center} 
\includegraphics[height=1.8in]{Heat3plot1.eps}
\end{center}

\[
c_n = \frac{1}{1} \int_{-1}^1 \sin(n\pi x) g(x) \, dx = -20 \int_{0}^1 x \sin(n\pi x) \, dx = \frac{20}{n\pi}\cos(n\pi) = \frac{20}{n\pi}(-1)^n.
\]
Thus,
\[
w(x,t) =\frac{20}{n\pi} \sum_{n=1}^\infty (-1)^n \sin(n\pi x) e^{-n^2\pi^2t}.
\]
Then,
\[
u(x,t) = g(x) + w(x,t) = 10 + 10x + \frac{20}{n\pi} \sum_{n=1}^\infty (-1)^n \sin(n\pi x) e^{-n^2\pi^2t}.
\]

Some plots are on the next page.
Animation coming soon to a website near you! 

\vfill
\pagebreak

\begin{center} {\bf Plots for Last Example} \end{center}
\vspace{0.5in}
\begin{center}

\includegraphics[height=2in]{Heat3plot3.eps}
\includegraphics[height=2in]{Heat3plot4.eps}

\vspace{0.5in}

\includegraphics[height=2in]{Heat3plot5.eps}
\includegraphics[height=2in]{Heat3plot6.eps}

\vspace{0.5in}

\includegraphics[height=2in]{Heat3plot7.eps}


\end{center}


\vfill
\pagebreak

\begin{center}{\bf Heat Equation with Insulated Ends} \end{center}
\vspace{0.5in}


Now we consider a metal rod where heat cannot flow out through the ends. The end are 
insulated. The model now becomes the following.

\begin{center}
\fbox{\parbox{2.5in}{
\[
\alpha^2 u_{xx} = u_{t}
\]

\[
u_x(0,t) = u_x(L,t) = 0
\]

\[
u(x,0) = f(x),
\]
where $f(x)$ is given.}}
\end{center}

We go through the same steps are before. Suppose $u(x,t)=X(x)T(t)$. Then the heat equation becomes
\[
\alpha^2 X''(x)T(t) = X(x)T'(t),
\]
and just as before we have
\[
\frac{X''}{X} = \frac{1}{\alpha^2} \frac{T'}{T} = \mbox{ a constant } = -\sigma.
\]
Thus, we get two ODE's 
\[
X'' + \sigma X = 0 \hspace{.3in} \& \hspace{.3in} T' + \sigma\alpha^2 T = 0.
\]

We work with the $X$ equation first. We consider the same three cases $\sigma <0$, $\sigma = 0$ and $\sigma >0$. 
The boundary condition translates to 
\[
X'(0) = X'(L) = 0.
\]

{\bf Suppose $\mathbf\sigma \mathbf < \mathbf 0$.} It will turn out there are no nontrivial solutions. The general solution is 
\[
X(x) = C_1 e^{\sqrt{-\sigma}x} + C_2 e^{-\sqrt{-\sigma}x} 
\]
Then
\[
X'(x) = C_1 \sqrt{-\sigma}e^{\sqrt{-\sigma}x} - C_2 \sqrt{-\sigma}e^{-\sqrt{-\sigma}x} 
\]
At the boundary points $x=0$ and $x=L$ we have
\[
X'(0) = C_1\sqrt{-\sigma} - C_2\sqrt{-\sigma} = 0 \:\:\: \implies \:\:\: C_1 = C_2 
\]
and
\[
X'(L) = C_1\sqrt{-\sigma}e^{\sqrt{-\sigma}L} - C_2\sqrt{-\sigma}e^{-\sqrt{-\sigma}L}  \:\:\: \implies \:\:\: C_1 = C_2 e^{-2\sqrt{-\sigma}L}
\]
These only have a solution besides $C_1=C_2=0$ if $L=0$, which we do not allow.


\vfill
\pagebreak

\begin{center}{\bf Heat Equation with Insulated Ends\\Continued} \end{center}
\vspace{0.5in}

{\bf Suppose $\mathbf\sigma \mathbf = \mathbf 0$.} The general solution is $X(x) = C_1x + C_2$. Since $X'(x) = C_1$ it must be that $C_1=0$. 
Any $X(x) = C_2$ will be a solution. 

\vspace{.2in}

{\bf Finally, suppose $\mathbf\sigma \mathbf > \mathbf 0$.} The general solution is $X(x) = C_1 \sin \sqrt{\sigma}x + C_2 \cos \sqrt{\sigma}x$. Thus,
\[
X'(x) = C_1  \sqrt{\sigma}\cos \sqrt{\sigma}x - C_2  \sqrt{\sigma}\sin \sqrt{\sigma}x.
\]
Thus,
\[
X'(0) =  C_1  \sqrt{\sigma} = 0 \:\:\: \implies C_1=0.
\]
Then
\[
X'(L) = - C_2  \sqrt{\sigma}\sin \sqrt{\sigma}L. = 0 \:\:\: \implies \:\:\: \sigma = \frac{n^2\pi^2}{L^2} \mbox{ or } C_2=0.
\]
Thus, if we want nontrivial solutions we require $\sigma = \frac{n^2\pi^2}{L^2}$. Then there are no restrictions on $C_2$. We let
\[
X_n(x) = \cos \left(\frac{n\pi x}{L}\right) \:\:\: \mbox{ for } n = 0, 1, 2, 3, ...
\]
Notice $n=0$ gives us a constant.


Recall the equation for $T(t)$ was $T' + \sigma\alpha^2 T = 0$. It is general solution is 
\[
T(t) = C e^{-\sigma\alpha^2t}.
\]
We let
\[
T_n(t) = e^{-\frac{n^2 \pi^2 \alpha^2}{L^2}t} \:\:\: \mbox{ for } n = 0, 1, 2, 3, ...
\]
Let
\[
u_n(x,t) = X_n(x)T_n(t)\ :\:\: \mbox{ for } n = 0, 1, 2, 3, ...
\]
Each $u_n(x,t)$ satisfies the heat equation and the boundary conditions on $u_x$. So too does any linear combination
of them. In is shown in Math 407 that if $c_0, c_1, c_2,c_3, \dots$ are such that
\[
u(x,t) = c_0 + \sum_{n=1}^\infty c_n X_n T_n
\]
converges, then $u(x,t)$ satisfies the heat equation and the boundary conditions on $u_x$. All that is left to do 
is find $c_n$'s such that $u(x,0) = f(x)$, the initial condition. But this is just the Fourier series of the {\bf even}
periodic extension of $f(x)$. Thus, $c_0$ is the average value of $f(x)$ and for $n=1, 2, 3,...$
\[
c_n = \frac{1}{L}\int_{-L}^L \cos \left( \frac{n \pi x}{L}\right) f_e(x) \, dx =  \frac{2}{L} \int_0^L  \cos \left( \frac{n \pi x}{L}\right) f(x) \, dx.
\]


\vfill
\pagebreak



\begin{center}{\bf Example} \end{center}
\vspace{0.5in}

Suppose $L=\pi$, $\alpha=1$ and $u(x,0) = f(x) = \sin(x)$. The even periodic extension of $f(x)$ is $|\sin (x)|$. 
%
\begin{center}
\includegraphics[height=1.5in]{Heat4plot1.eps}
\end{center}
%
But, using symmetry our integrals are only over $[0,\pi]$.
Then
\[
c_0 = \frac{1}{\pi} \int_0^\pi \sin x \, dx = \frac{2}{\pi}
\]
and for $n=1,2,3, ...$ we have
\[
c_n = \frac{2}{\pi} \int_0^\pi \cos \left( \frac{n \pi x}{\pi} \right) \sin (x) = \frac{1+\cos (n\pi)}{1-n^2} =\left\{\begin{array}{lll}
\frac{4/\pi}{1-n^2} & \mbox{ for } & n \mbox{ even},\\
&&\\
0 &  \mbox{ for } & n \mbox{ odd}.
\end{array}
\right.
\]
Note, the $n=1$ case should done separately to avoid division by zero, but it comes out zero.
Therefore,
\[
u(x,t) = \frac{2}{\pi} + \frac{4}{\pi} \sum_{k=1}^\infty \frac{1}{1-4k^2} \cos (2kx) e^{-4k^2t}.  
\]
On the next page are plots for various vaues of $t$ with the sum going to $k=30$.
The green lines mark $2/\pi$. An animation is on the course website. 



\vfill
\pagebreak

\begin{center}{\bf Plots for Last Example} \end{center}
\vspace{0.5in}



\begin{center}
\includegraphics[width=1.8in]{Heat4plot2.eps}
\includegraphics[width=1.8in]{Heat4plot3.eps}
\includegraphics[width=1.8in]{Heat4plot4.eps}

\vspace{0.5in}

\includegraphics[width=1.8in]{Heat4plot5.eps}
\includegraphics[width=1.8in]{Heat4plot6.eps}
\includegraphics[width=1.8in]{Heat4plot7.eps}

\vspace{0.5in}

\includegraphics[width=1.8in]{Heat4plot8.eps}
\includegraphics[width=1.8in]{Heat4plot9.eps}
\includegraphics[width=1.8in]{Heat4plot10.eps}

\end{center}

\vfill
\pagebreak

\begin{center}{\bf Summary} \end{center}
\vspace{0.25in}

{\bf End points held at 0 degrees (homgeneous case).}

\vspace{0.25in}
\noindent Model: $\alpha^2u_{xx} = u_t$, $u(0,t)=u(L,t)=0$, $u(x,0)=f(x)$.

\vspace{0.25in}
\noindent Solution: 
\[
u(x,t) = \sum_{n=1}^\infty c_n \sin \left( \frac{n\pi x}{L}\right) e^{-\frac{n^2\pi^2\alpha^2t}{L^2}} 
\]
where
\[
c_n = \frac{2}{L} \int_0^L \sin \left( \frac{n\pi x}{L}\right) f(x)\, dx.
\]
\vspace{0.25in}
\hrule
\vspace{0.25in}

{\bf End points held at fixed temeratures (nonhomgeneous case).}

\vspace{0.25in}
\noindent Model: $\alpha^2u_{xx} = u_t$, $u(0,t)=T_1$, $u(L,t)=T_2$, $u(x,0)=f(x)$.

\vspace{0.25in}
\noindent Solution: Let $v(x) = \dfrac{T_2-T_1}{L}x + T_1$. Then
\[
u(x,t) = v(x) + \sum_{n=1}^\infty c_n \sin \left( \frac{n\pi x}{L}\right)  e^{-\frac{n^2\pi^2\alpha^2t}{L^2}}, 
\]
where
\[
c_n = \frac{2}{L} \int_0^L \sin \left( \frac{n\pi x}{L}\right)[f(x)-v(x)]\, dx.
\]
\vspace{0.25in}
\hrule
\vspace{0.25in}

{\bf Insulated end points.}

\vspace{0.25in}
\noindent Model: $\alpha^2u_{xx} = u_t$, $u_x(0,t)=0$, $u_x(L,t)=0$, $u(x,0)=f(x)$.

\vspace{0.25in}
\noindent Solution:
\[
u(x,t) = c_0 + \sum_{n=1}^\infty c_n \cos \left( \frac{n\pi x}{L}\right) e^{-\frac{n^2\pi^2\alpha^2t}{L^2}}
\]
where
\[
c_0 = \mbox{ the average value of $f(x)$ } = \frac{1}{L} \int_0^L f(x) \, dx
\]
and for $n= 1, 2, 3, ...$
\[
c_n = \frac{2}{L} \int_0^L \cos \left( \frac{n\pi x}{L}\right) f(x) \, dx.
\]

\vfill
\pagebreak

\begin{center}{\bf Extra Credit!} \end{center}
\vspace{0.5in}


Consider a metal ring. For a given initial temperature distribution $f(\theta)$ for $\theta \in [0,2\pi]$
set up a model with the heat equation and show how to solve it. Then work through an example and display the plots 
for several times. If you like, create an animation.




\vfill
\end{document}
