\documentclass{article}
%\pagestyle{empty}
\usepackage{graphicx, amsmath, psfrag}
\setlength{\textheight}{9in}
\setlength{\topmargin}{0.0in}
\setlength{\textwidth}{6in}
\setlength{\oddsidemargin}{+0.0in}
\newcommand{\dis}{\displaystyle}
\newcommand{\x}{\times}
\begin{document}

\begin{center}{\bf Lecture Notes for Ch 10\\Fourier Series and Partial Differential Equations}\end{center}

{\bf Part II.}

Outline
\begin{itemize}

\item [Page 2.]  Periodic Extensions

\item [Pages 3-4.] An Example

\item [Page 5.] An Example Done Entirely on Maple

\item [Page 7.] An Example that Requires No Computer Skills 

\item [Pages 8-11.] An ODE with Square Wave Forcing Example

\end{itemize}


\vfill
\pagebreak

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{center}
{\bf Periodic Extensions}
\end{center}

We will be interested in functions on a closed bounded interval. For 
example the temperature along a finite metal bar. To apply Fourier series, we create a periodic extension. There are {\bf three} standard 
ways to do this. We will illustrate with an example. Let $f(x)$ have domain $[0,2]$ and be given by

\vspace{0.4in}
$\dis 
 f(x) = \left\{ \begin{array}{lll}
1-x & \mbox{ for } & x \in [0,1],\\
0 &  \mbox{ for } & x \in (1,2].\end{array}\right.
$

\vspace{-0.9in}
\begin{flushright}
\psfrag{1}{1}\psfrag{0}{0}\psfrag{f}{$f(x)$}
\includegraphics[height=1in]{Figs/fgiven.eps}
\end{flushright}

Then the {\bf periodic extension} of $f(x)$ is the function shown below. It is given by $\tilde{f}(x) = f(x \mod 2)$ except for $x=2n$ where jump discontinuities form. Here we define it to be the average 
of the two point end values.


\begin{center}
\psfrag{0}{0}
\psfrag{1}{1}
\psfrag{2}{2}
\psfrag{3}{3}
\psfrag{4}{4}
\psfrag{5}{5}
\psfrag{6}{6}
\psfrag{-4}{$-4$}
\psfrag{-1}{$-1$}
\psfrag{-2}{$-2$}
\psfrag{-3}{$-3$}
%\hspace*{-1in}
\includegraphics[height=1.0in]{Figs/fperext.eps}
\end{center}

Next we form the {\bf even periodic extension} of $f(x)$. We first 
define a function on $[-2,2]$ by letting $f_e(x) = f(|x|)$, and then
forming it periodic extension, $\tilde{f_e}(x) = f_e(x \mod 4)$. 
In this case there are no discontinuities. If there were we would 
define the extension at such points as before. See below. Notice, the period is 4. 

\begin{center}
\psfrag{1}{1}
\psfrag{2}{2}
\psfrag{3}{3}
\psfrag{4}{4}
\psfrag{0}{0}\psfrag{5}{5}\psfrag{6}{6}
\psfrag{-1}{$-1$}
\psfrag{-2}{$-2$}
\psfrag{-3}{$-3$}
\psfrag{-4}{$-4$}
%\hspace*{-1in}
\includegraphics[height=1in]{Figs/fevenext.eps}
\end{center}

The {\bf odd periodic extension} is similar. Let $f_o(x) = \mbox{sign}(x)f(|x|)$ for $x\in [0,4]$, then extend to a function on the real line with period 4. See below.

\begin{center}
\psfrag{1}{1}
\psfrag{2}{2}
\psfrag{3}{3}
\psfrag{4}{4}
\psfrag{0}{0}\psfrag{5}{5}\psfrag{6}{6}
\psfrag{-1}{$-1$}
\psfrag{-2}{$-2$}
\psfrag{-3}{$-3$}
\psfrag{-4}{$-4$}
%\hspace*{-1in}
\includegraphics[height=1.7in]{Figs/foddext.eps}
\end{center}


\vfill
\pagebreak
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{center}
{\bf Example of Fourier Series}
\end{center}

Problem: Find a Fourier series that will converge to 
$\dis 
 f(x) = \left\{ \begin{array}{lll}
1-x & \mbox{ for } & x \in [0,1],\\
0 &  \mbox{ for } & x \in (1,2]\end{array}\right.
$
for $x\in[0,2]$.

\vspace{.2in}

Solution: We will find the Fourier series of its even periodic extension. Clearly, the $b_n$'s are all zero. Let $L=2$

\[
a_0 = \frac{1}{L} \int_{-L}^L f_e(x) \, dx = \frac{1}{2} \int_{-2}^2 f_e(x) \, dx = \frac{1}{2} \x \mbox{area under the function} = \frac{1}{2}\x 1 = \frac{1}{2}.
\]

Next,
\begin{eqnarray*}
a_n &=& \frac{1}{2} \int_{-2}^2 \cos \left( \frac{n\pi x}{2} \right) f_e(x)\, dx\\
&&\\
& =& \frac{2}{2} \int_0^2 \cos \left( \frac{n\pi x}{2} \right) f_e(x)\, dx \\
&&\\
&=& \int_0^1 \cos \left( \frac{n\pi x}{2} \right) (1-x) \, dx  + 0\\
&&\\
&=&  \int_0^1 \cos \left( \frac{n\pi x}{2} \right)\, dx -  \int_0^1 x \cos \left( \frac{n\pi x}{2} \right)\, dx\\
&&\\
&=& \frac{2}{n\pi} \sin\left( \frac{n\pi x}{2} \right) \bigg|_0^1 -
\frac{4}{n^2\pi^2}\left[\cos  \left( \frac{n\pi x}{2} \right) + \frac{n\pi x}{2} \sin  \left( \frac{n\pi x}{2} \right)\right]\bigg|_0^1\\
&&\\
&=&\frac{2}{n\pi} \sin\left( \frac{n\pi}{2} \right) - \frac{4}{n^2\pi^2} \left[ \cos  \left( \frac{n\pi}{2} \right) +  
\frac{n\pi}{2}\sin \left( \frac{n\pi}{2} \right) -1 \right]\\
&&\\
&=& \frac{-4}{n^2\pi^2}\left[ \cos\left( \frac{n\pi}{2} \right) -1 \right].
\end{eqnarray*}

If you plug in some values of $n$ you will see that
\[
 \cos\left( \frac{n\pi}{2} \right) -1 = \left\{\begin{array}{ccl}
-1 & \mbox{ for } & n = 1\!\!\! \mod 4    \\
-2 & \mbox{ for } & n = 2\!\!\! \mod 4    \\
-1 & \mbox{ for } & n = 3\!\!\! \mod 4    \\
0 & \mbox{ for } & n = 0\!\!\! \mod 4    
\end{array}\right.
\]

We give the first few values of $a_n$, $n>0$, in the table below.

\begin{center}\renewcommand{\arraystretch}{2.5}
\begin{tabular}{|c||c|c|c|c|c|c|c|c|}
\hline
$n$ & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 \\
\hline
$a_n$ & $\dis\frac{4}{\pi^2}$ & $\dis\frac{8}{4\pi^2}$ & $\dis\frac{4}{9\pi^2}$ & 0 & $\dis\frac{4}{25\pi^2}$ & $\dis\frac{8}{36\pi^2}$ & $\dis\frac{4}{49\pi^2}$  & 0 \\
\hline
\end{tabular}
\end{center}

Therefore,
\[
f(x) = \frac{1}{4} + \frac{4}{\pi^2}\cos \left(\frac{\pi x}{2}\right) + \frac{8}{4\pi^2}\cos \left(\frac{2\pi x}{2}\right) + \frac{4}{9\pi^2}\cos \left(\frac{3\pi x}{2}\right) + 0 + \frac{4}{25\pi^2}\cos \left(\frac{5\pi x}{2}\right)  + \frac{8}{36\pi^2}\cos \left(\frac{6\pi x}{2}\right) + \cdots
\]

Plots of some partial sums are on the next page.

\vfill
\pagebreak



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{center}
{\bf Plots of some Partial Sums }
\end{center}



\begin{center}

\psfrag{N=1}{$N=1$}
\hspace*{-1in}\includegraphics[width=8in]{Figs/FSexampleplot1.eps}


\vspace{.5in}

\psfrag{N=2}{$N=2$}
\hspace*{-1in}\includegraphics[width=8in]{Figs/FSexampleplot2.eps}



\vspace{.5in}

\psfrag{N=5}{$N=5$}
\hspace*{-1in}\includegraphics[width=8in]{Figs/FSexampleplot3.eps}

\vspace{.5in}

\psfrag{N=20}{$N=20$}
\hspace*{-1in}\includegraphics[width=8in]{Figs/FSexampleplot4.eps}

\end{center}


\vfill
\pagebreak



\begin{center}
{\bf An example Done Entirely on Maple}
\end{center}

\vspace{.2in}

{\bf Problem.} Find the Fourier series that will converge to $f(x) = 4 -x^2$ for $x \in [-2,2]$.

\vspace{.1in}
\begin{center}
\includegraphics[height=1.5in]{Figs/ParaFplot1.eps}
\end{center}
\vspace{.2in}


{\bf Solution.} Since $f(x)$ is even $b_n=0$. Next we compute $a_0$.

\vspace{.2in}
{\tt  1/2*int( 4-x\^{}2, x=-2..2);}
\vspace{.2in}

\[
 \frac{16}{3}
\]

Then we find $a_n$.

\vspace{.2in}
{\tt>  1/2*int( (4-x\^{}2)*cos(n*Pi*x/2), x=-2..2); }
\vspace{.2in}
 
\[ 
 - \frac{16(n \pi \cos(n\pi) - \sin(n\pi))}{n^3\pi^3}
\]

Then we plot a partial sum of the first 11 terms. Note that I simplified the expression for $a_n$.

\vspace{.2in}
{\tt>  plot(8/3 - 16/Pi\^{}2*sum((-1)\^{}n/n\^{}2*cos(n*Pi*x/2),n=1..30),x=-10..10,thickness=2); }
\vspace{.2in}
 
\begin{center}
\includegraphics[height=1.5in]{Figs/ParaFplot2.eps}
\end{center}

\vfill
\pagebreak


\begin{center}
{\bf Extra Credit!}
\end{center}

\vspace{.2in}

Looking at the graph from the last example, we notice it never quite 
gets to zero. We begin think, could there be a better way? The periodic 
extension of the parabola has very sharp corners. These make convergence 
``difficult''. To get around this, use the periodic extension of a 
modified graph shown below. 


\begin{center}
\includegraphics[height=2in]{Figs/paraflipplot1.eps}
\end{center}

The function is based on the original curve $y=4-x^2$ for  $x\in[-2,2]$, 
but for $x\in[-4,2]$ and for $x\in[2,4]$ we have taken half of original 
curve flipped it twice and moved it into place. 

\vspace{.2in}
Find the equations for these pieces of the new function. Take its 
periodic extension, find its Fourier series and compare the convergence
with the Fourier series used in the last example. 

\vspace{.2in}
This will be worth one homework assignment. 



\vfill
\pagebreak

\begin{center}
{\bf An Example that Requires no Computer Skills}
\end{center}

\vspace{.2in}
{\bf Problem.} Find the Fourier series for $f(x) = \sin^3 x$.

\begin{center}
\includegraphics[height=2in]{Figs/sin3plot1.eps}
\end{center}

{\bf Solution.} You did this for homework already! Remember when you showed that
\[
\sin^3 x = \frac{3}{4} \sin x - \frac{1}{4} \sin 3x.
\]
That is its Fourier series. It is odd, so all the $a_n$'s are zero. 
Then $b_1 = 3/4$, $b_3 = -1/4$ and all the other $b_n$'s are zero.



\vfill
\pagebreak


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{center}
{\bf An ODE Example}
\end{center}


Let $f(x)$ be the square wave we studied earlier, shown again below.

\begin{center}\psfrag{Square}{Square Wave}\psfrag{Wave}{}
\includegraphics[width=6in]{Figs/sqplot1.eps}
\end{center}

Problem: Solve the initial value problem $u'' + \frac{1}{4} u = f(x)$, $u(0)=u'(0)=0$. 

\vspace{.2in}

Solution: The solution to the corresponding homogeneous problem is $u_h = C_1 \sin (x/2) + C_2 \cos (x/2)$.

To get a particular solution we recall the Fourier series we found for $f(x)$:

\[
\sum_{n=1}^\infty b_n \sin (nx), \hspace{0.5in}\mbox{where  }\, b_n = \left\{ \begin{array}{ll}0 & \mbox{for $n$ even,}\\
\frac{4}{n\pi} & \mbox{for $n$ odd.}\end{array}\right.
\]
This converges to $f(x)$ except at the jump discontinuities.

The idea is, we can consider each term separately. That is for $n=1,2,3,\dots$ we have
\[
u'' + \frac{u}{4} = \sin nx.
\]
For each $n$ we shall find a particular solution $u_n$. Let
\[
u_n = A \sin nx + B \cos nx.
\]
Then 
\[
u''_n = -An^2 \sin nx - B n^2 \cos nx.
\]
Thus, $-An^2 + A/4 =1$ and $-Bn^2 + B/4 = 0$. Thus, $B=0$ and $A = \dis\frac{1}{\frac{1}{4} - n^2}$. Hence,
\[
u_n = \frac{1}{\frac{1}{4} - n^2} \sin nx, \hspace{0.5in} \mbox{ for } n = 1, 2, 3, \dots . 
\]
Now we let
\[
u_p = \sum_{n=1}^\infty \frac{b_n}{\frac{1}{4} - n^2} \sin nx.
\]
It follows by linearity that $u''_p +\frac{1}{4} u_p = $ the Fourier series of $f(x)$ which equals $f(x)$, almost everywhere.
We can rewrite $u_p$ as
\[
u_p = \sum_{k=1}^\infty \frac{\frac{4}{(2k-1)\pi} \sin((2k-1)x)}{\frac{1}{4} - (2k-1)^2} = 
\frac{16}{\pi} \sum_{k=1}^\infty \frac{\sin((2k-1)x)}{(2k-1)(1-4(2k-1)^2)}.
\]
Now, we have that the general solution is
\[
u = u_h + u_p = C_1 \sin (x/2) + C_2 \cos (x/2) + u_p.
\]

\vfill
\pagebreak
We still need to find $C_1$ and $C_2$ such that $u(0) = u'(0) = 0$.
\[
u(0) = 0 + C_2 + \frac{16}{\pi}\sum_{k=1}^\infty 0 = C_2.
\]
Thus $C_2 = 0$.

Now,
\[
u'(x) = \frac{C_1}{2} \cos (x/2) + \frac{16}{\pi}\sum_{k=1}^\infty \frac{(2k-1)\cos((2k-1)x)}{(2k-1)(1-4(2k-1)^2)}. 
\]
Thus,
\[
u'(0) = \frac{C_1}{2} + \frac{16}{\pi}\sum_{k=1}^\infty \frac{1}{1-4(2k-1)^2}.
\]
It turns out $\dis  \sum_{k=1}^\infty \frac{1}{1-4(2k-1)^2} = -\pi/8$. (I'll show how to do this in a bit.) Then, since $u'(0) = 0$ we have
\[
C_1 = \frac{32}{\pi} \cdot \frac{\pi}{8} = 4.
\]
Our final solution is
\[
u(x) = 4 \sin(x/2) +  \frac{16}{\pi} \sum_{k=1}^\infty \frac{\sin((2k-1)x)}{(2k-1)(1-4(2k-1)^2)}.
\]
On the next page we will plot some partial sums. 

\vfill
\pagebreak


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{center}
{\bf Graphs for ODE Example }
\end{center}

\begin{center}\psfrag{sin(x/2)}{$4\sin x/2$}
\includegraphics[height=1.5in]{Figs/ODEexampleplot1.eps}
\end{center}

\begin{center}\psfrag{N=1}{$N=1$}
\includegraphics[height=1.5in]{Figs/ODEexampleplot2.eps}
\end{center}

\begin{center}\psfrag{N=2}{$N=2$}
\includegraphics[height=1.5in]{Figs/ODEexampleplot3.eps}
\end{center}

\begin{center}\psfrag{N=3}{$N=3$}
\includegraphics[height=1.5in]{Figs/ODEexampleplot4.eps}
\end{center}

\begin{center}\psfrag{N=10}{$N=10$}
\includegraphics[height=1.5in]{Figs/ODEexampleplot5.eps}
\end{center}

\vfill
\pagebreak


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{center}
{\bf Back to computing that series...}
\end{center}

Back to why $\dis  \sum_{k=1}^\infty \frac{1}{1-4(2k-1)^2} = -\pi/8$.

\vspace{.5in}

{\bf Method one.} Use a computer. Here is the command in Maple:
\[
\tt sum(1/(4*(2*k-1)^2-1), k=1..infinity);
\]
It returns $\pi/8$. (I switched the terms in the denominator to make it 
positive.) I could not find a way to do this is Maxima; it can only do 
numerical approximations. 

\vspace{.5in}

{\bf Method two.} Recall that you took a course called {\em Calculus II}.
Look up the Taylor series for $\arctan x$, then plug in $x=1$. This shows 
that
\[
1 -\frac{1}{3} + \frac{1}{5} - \frac{1}{7} + \frac{1}{9} - \cdots  = \arctan (1) = \frac{\pi}{4}.
\]
We will apply this fact to our sum. But, first we notice that
\begin{eqnarray*}
 \frac{1}{4(2k-1)^2 - 1} &=& \frac{1}{16k^2 -16k + 3} \\
&&\\
&=& \frac{1}{(4k-3)(4k-1)} \\
&&\\
&=& \frac{\frac{1}{2}}{4k-3} - \frac{\frac{1}{2}}{4k-1}. 
\end{eqnarray*}

Therefore,
\begin{eqnarray*}
\sum_{k=1}^\infty \frac{1}{4(2k-1)^2 - 1}  &=& \frac{1}{2}\sum_{k=1}^\infty \left(\frac{1}{4k-3} - \frac{1}{4k-1}\right) \\
&&\\
&=&  \frac{1}{2}\left(1 -\frac{1}{3} + \frac{1}{5} - \frac{1}{7} + \frac{1}{9} - \cdots \right) \\
&&\\
&=&  \frac{1}{2}\frac{\pi}{4} = \frac{\pi}{8}.
\end{eqnarray*}




\vfill
\pagebreak

\end{document}
