% This is a sample file for the Undergraduate Faculty Program at
% PCMI, containing one lecture 
%
%   What is a Partial Differential Equation?
%
%  from the Park City Lectures of Andrew J. Bernoff.
%
% The sample file illustrates the use of epsf.tex to include postscript 
% graphics, as well as various "AmS-LaTeX" constructions from the amsmath
% package (which is automatically loaded by the pcms-l document class).
% To run this file you need the files 
%
%        pcms-l.cls and pcmslmod.tex
%


\documentclass[lecture,12pt,]{pcms-l}
\input pcmslmod.tex  % v.1.2
%\input epsf.tex

%\usepackage{amssymb} % this command would have loaded all the extra symbols,



% authors should not define these, they will be defined by the volume editors
%\def\currentvolume{3}
%\def\currentyear{1993}


% EQUATION NUMBERING AND THEOREM SETUP

\numberwithin{section}{chapter}
\numberwithin{equation}{chapter}

\theoremstyle{plain}
\newtheorem{theorem}[equation]{Theorem}
\newtheorem{lemma}[equation]{Lemma}

\theoremstyle{definition}
\newtheorem{definition}[equation]{Definition}

\newtheorem{problem}{Problem}
\newtheorem*{exercise}{Exercise}
\newtheorem*{remark}{Remark}

% Set enumerate to use letters, not numbers for problem parts.

\renewcommand{\theenumi}{\alph{enumi}}
\renewcommand{\labelenumi}{(\theenumi)}

% AUTHOR-DEFINED MACROS:

\newcommand{\cA}{\mathcal{A}}
\newcommand{\cB}{\mathcal{B}}
\newcommand{\C}{\mathbb{C}}
\newcommand{\cC}{\mathcal{C}}
\newcommand{\cD}{\mathcal{D}}
\newcommand{\cE}{\mathcal{E}}
\newcommand{\bU}{{\bar U}}

\begin{document}

\mainmatter
\setcounter{page}{1}

%\LogoOn

\lectureseries[An Introduction to PDE]{An Introduction to Partial Differential Equations}

\auth[Janine Wittwer]{Janine Wittwer} 
% the following hack starts the lecture numbering at 2
\setcounter{lecture}{4}
\lecture{The Diffusion Equation and Fourier Series}


\section{Outline of Lecture}
\begin{itemize}
\item Separation of variables for the Dirichlet problem
\item The separation constant and corresponding solutions
\item Incorporating the homogeneous boundary conditions
\item Solving the general initial condition problem
\end{itemize}

\section{Solving  the Diffusion Equation- Dirichlet problem by Separation of Variables}


In lecture 2, we derived the homogeneous Dirichlet problem for the diffusion equation. This equation, also called the {\bf Heat Equation}, governs the heat distribution in a finite metal bar of length $\pi$, where we keep the endpoints at a fixed temperature, in our case $0$. The initial temperature at time $t=0$ is given by $f(x)$. 
We derived the following conditions:

\vspace{.1 in}

{\sc The Dirichlet Problem for the Diffusion Equation\\
(Homogeneous Boundary Conditions)}
\begin{eqnarray*}
u_t=\kappa u_{xx} \quad & 0<x < \pi, t>0 \quad  & {\bf \rm DE} \\
 u(0,t) =0 \quad u(\pi,t) =0 \quad & t>0 & {\bf \rm BC} \\
u(x,0) = f(x) & 0 < x < \pi , &  {\bf \rm IC} \\
\end{eqnarray*}


In lecture 2, we saw a few solutions to this system, but we didn't have a systematic way of solving the problem given a particular $f(x)$. In this lecture, we will discuss a method to solve the equation for  (essentially) any initial $f(x)$.


\subsection{A Solution to the Homogeneous Dirichlet Problem}  

In 1807 Jean Baptiste Joseph Fourier caused a big stir when he managed to solve a problem of heat dispersion using what are now called Fourier series. We will use the  method he developed to solve our homogeneous Dirichlet problem.

When solving a differential equation, it is frequently advantageous to first look for special solutions that might be easier to find then the general case.
Fourier's first step was to look for solutions in the special form

\begin{equation}
u(x,t)=X(x)T(t).
\end{equation}

\noindent Plugging this form into the differential equation $u_t=\kappa u_{xx}$, we get

\begin{equation}
X(x)T'(t) = \kappa X''(x)T(t)
\end{equation}
and dividing by $\kappa X(x)T(t)$ we find
\begin{equation}
\frac {T'(t)}{\kappa T(t)} = \frac {X''(x)}{X(x)}.
\end{equation}

Notice that the left hand side is a function of $t$ alone, while the right is a function of $x$ only. This implies that both sides must indeed be constant!

Call this constant
$-\lambda$. It is known as the {\bf separation constant}. The reason for the negative sign in front of the $\lambda$ will be apparent shortly. 

Thus we have \begin{equation}
\frac {T'(t)}{\kappa T(t)} = \frac {X''(x)}{X(x)} =-\lambda.
\end{equation}


We can separate this equation into two equations, one  involving only $x$, one  involving only $t$:
$$ \frac {T'(t)}{\kappa T(t)}=-\lambda,$$ and $$\frac {X''(x)}{X(x)} =-\lambda.$$

 Each  of these  equations is now an ordinary differential equation, and thus we can draw on the theory of ordinary differential equations to solve them. The first equation,
 $$T'(t) = -\lambda \kappa T(t)$$ has the solution $$T(t) = Ce^{-\lambda  \kappa t}.$$ Note that we expect the temperature to remain finite as time goes to infinity, and thus the exponent to be negative. Thus $\lambda$ should be non-negative. (Hence the choice of $-\lambda$ earlier.)
 
 The ordinary differential equation in $x$, $$X''(x) =-\lambda X(x), \,\ \lambda \geq 0,$$ has the solution $$X(x) = A\cos( \sqrt{\lambda}x) + B \sin( \sqrt{\lambda}x)$$  for $\lambda >0$, and $$X(x) = Ax+B$$ for $\lambda = 0$. 
 
Putting these back together, we find that 
\begin{equation}\label{general} \begin{array}{ll} u(x,t) = Ce^{-\lambda  \kappa t}\left(A\cos( \sqrt{\lambda}x) + B \sin( \sqrt{\lambda}x)\right) & \lambda \geq 0 \\ u(x,t) = C(Ax+B) & \lambda = 0 \end{array} \end{equation}
 solve the diffusion equation, though they do not in general satisfy the boundary or initial conditions.



 \section { Incorporating the homogeneous boundary conditions}

 
We wish $u(x,t)$ to satisfy the homogeneous boundary conditions $u(0,t) = u(\pi,t) =0 $.
In the case where $u(x,t) = C(Ax+B)$, this forces $u(x,t) = 0$. This is the trivial solution, and we will thus ignore it from now on.

In the case where $$u(x,t) = Ce^{-\lambda  \kappa t}\left(A\cos( \sqrt{\lambda}x) + B \sin( \sqrt{\lambda}x)\right), $$ $$u(0,t) = Ce^{-\lambda  \kappa t}A.$$ Thus to have $u(0,t) = 0$ we must have  $A=0$. Thus $$u(x,t) = Ce^{-\lambda  \kappa t}B\sin( \sqrt{\lambda}x).$$
To satisfy $u(\pi,t) =0, $ we must choose $\lambda$  such that $\sin( \sqrt{\lambda}\pi)=0$. As $\sin(x) = 0$ exactly when $x = n\pi, \,\  n = 0,1,2,3,...$, this means that 
 
 \begin{equation}
\boxed{\lambda = n^2}\,\ n = 0,1,2,3,...
\end{equation}

To summarize, we now have a whole family of functions which satisfies both the differential equation, and the boundary values, namely
$$
\boxed{u(x,t) = De^{-n^2 \kappa t}\sin(n x )} \hspace{.1 in} n=1,2,3,...$$

\noindent where I've combined the constants $B$ and $C$ into one constant called $D$.

\noindent These functions have initial value 
$$u(x,0) =D \sin(n  x).$$ Thus we now know how to solve the Dirichlet problem for the homogeneous diffusion equation whenever  the initial condition is $$f(x) =D \sin(n x).$$ 


\section{ The solution for general $f(x)$}

Sums of solutions to the homogeneous problem will again be solutions. Thus, for example,  the solution to 
\begin{eqnarray*}
u_t=\kappa u_{xx} \quad & 0<x < \pi, t>0 \quad  & {\bf \rm DE} \\
 u(0,t) =0 \quad u(\pi,t) =0 \quad & t>0 & {\bf \rm BC} \\
u(x,0) = 5\sin{3x} + 2.7 \sin{100x} & 0 < x < \pi , &  {\bf \rm IC} \\
\end{eqnarray*}
is given by 
 $$u(x,t)=5e^{-3^2 \kappa t}\sin(3x )+ 2.7e^{-100^2 \kappa t}\sin(100x ).$$


 What about all the other  possible initial conditions?

\vspace{.1 in}

\noindent {\bf Fourier's discovery : Any reasonable function on $[0, \pi]$ can be written as a sum of $\sin(nx)$'s!!}

\vspace{.1 in}

We will not prove this claim here, but we will just assume that it is true for now i.e. we will assume that for a given initial value $f(x)$ we can write

$$f(x) = \sum_{n =1}^{\infty} a_n \sin(nx).$$
This is called a {\bf Fourier Series}. The numbers $a_n$ are called the {\bf Fourier Coefficients } of $f$.

Thus,  the solution to the general system

\begin{eqnarray*}
u_t=\kappa u_{xx} \quad & 0<x < \pi, t>0 \quad  & {\bf \rm DE} \\
 u(0,t) =0 \quad u(\pi,t) =0 \quad & t>0 & {\bf \rm BC} \\
u(x,0) = f(x) & 0 < x < \pi , &  {\bf \rm IC} \\
\end{eqnarray*}

is given by $$ \boxed{ u(x,t) = \sum_{n =1}^{\infty} a_n e^{-n^2  \kappa t }\sin(nx ).}$$

\begin{remark}
 Strictly speaking, we need to formally prove that this series converges, and indeed has the initial value $f(x)$. This proof is non-trivial, and we will not do it here.
\end{remark}

\subsection{ How to calculate the Fourier Coefficients}


We will make use of the following fact, the proof  of  which is left as an exercise:

{\bf The orthogonality condition}
$$
\boxed{ \int_0^{ \pi} \sin(nx) \sin(mx) dx = \left\{ \begin{array}{ll}  0 & n \neq m \\ \frac{\pi}{2} & n=m \end{array} \right. } $$
To calculate the Fourier coefficients, start with 
$$f(x) = \sum_{n =1}^{\infty} a_n \sin(nx).$$
Multiply both sides by $\sin(mx)$ and integrate. We get

$$\int_0^{ \pi} f(x) \sin(mx) dx = \int_0^{\pi} \sum_{n =1}^{\infty} a_n \sin(nx) \sin(mx) dx =\sum_{n =1}^{\infty} a_n\int_0^{\pi} \sin(nx) \sin(mx) dx. $$
Because of the orthogonality condition, all the terms in the sum are $0$ except when $n=m$, in which case we get $\frac{\pi}{2}$ .
Thus $$\sum_{n =1}^{\infty} a_n\int_0^{\pi} \sin(nx) \sin(mx) dx= a_m \frac{\pi}{2} \,\ ! $$


Thus the formula to calculate the Fourier Coefficients is 
$$\boxed{a_m = \frac{2}{\pi} \int_0^{\pi} f(x) \sin(mx) dx} \,\ m=1,2,3,...\,\ .$$

\pagebreak

\section{Challenge Problems for Lecture 5}

\begin{problem}
Use Maple to graph the solution to the homogeneous Dirichlet problem for the diffusion equation with initial condition $f(x) = \left(\sin(x)\right)^2$ on $[0,\pi]$.
\end{problem}

\begin{problem}
Rework the solution to  the homogeneous Dirichlet problem for a bar of length $L$ instead of length $\pi$. 
That is, solve 
\begin{eqnarray*}
U_t=\kappa U_{xx} \quad & 0<x < L, t>0 \quad  & {\bf \rm DE} \\
 U(0,t) =0 \quad U(L,t) =0 \quad & t>0 & {\bf \rm BC} \\
U(x,0) = f(x) & 0 < x < L . &  {\bf \rm IC} \\
\end{eqnarray*}
\end{problem}

\begin{problem} In the above, we considered homogeneous Dirichlet boundary conditions, i.e. 
$$u(0,t) =0 \quad u(\pi,t) =0 \quad \,\ t>0.$$

We can also consider Neumann boundary conditions, 
$$ u_x(0,t) =0 \quad u_x(\pi,t) =0 \quad  t>0.$$

These correspond to a metal rod where the ends are insulated, so there is no heat flowing out of (or into) the bar.
The complete system of equations for the Neumann problem  reads:



\begin{eqnarray*}
u_t=\kappa u_{xx} \quad & 0<x < \pi, t>0 \quad  & {\bf \rm DE} \\
 u_x(0,t) =0 \quad u_x(\pi,t) =0 \quad & t>0 & {\bf \rm BC} \\
u(x,0) = f(x) & 0 < x < \pi , &  {\bf \rm IC} \\
\end{eqnarray*}
\noindent Solve this system  for $f(x) = 2+ 3\cos(2x)$ using separation of variables.
Plot the solution in Maple. What happens as $t \to \infty$?
\end{problem}
\begin{problem}
Solve the Dirichlet problem when the boundary conditions are not homogeneous. That is, solve it for
\begin{eqnarray*}
U_t=\kappa U_{xx} \quad & 0<x < L, t>0 \quad  & {\bf \rm DE} \\
 U(0,t) =a \quad U(L,t) =b \quad & t>0 & {\bf \rm BC} \\
U(x,0) = f(x) & 0 < x < L . &  {\bf \rm IC} \\
\end{eqnarray*} 
\noindent Hint: First find a simple solution $g(x)$ which satisfies the DE and the BC.   
\end{problem}
\end{document}
