%%%%		-*- Mode: LaTeX -*-
%%%% Author:    J. Robert Buchanan
%%%% Address:   Department of Mathematics
%%%%		Millersville University
%%%%            P.O. Box 1002
%%%%            Millersville, PA 17551-0302
%%%% Phone:     717-871-7305
%%%% FAX:	717-871-7948
%%%%
%%%% Email:     Robert.Buchanan@millersville.edu
%%%%
%%%% Date:      04/04/2025
%%%%
%%%% Purpose:   Wave Equation
%%%%

\documentclass[10pt]{beamer}

\mode<presentation>
{
  %\usetheme{Warsaw}
  \usetheme{default}
  %\usetheme{CambridgeUS}
  % or ...

  %\setbeamercovered{transparent}
  % or whatever (possibly just delete it)
}


\usepackage[english]{babel}
% or whatever

\usepackage[latin1]{inputenc}
% or whatever

\usepackage{times}
\usepackage[T1]{fontenc}
% Or whatever. Note that the encoding and the font should match. If T1
% does not look nice, try deleting the line with the fontenc.


\title{Wave Equation}
\subtitle{\textit{Partial Differential Equations}} % (optional)


\author % (optional, use only with lots of authors)
{J~Robert~Buchanan}
% - Use the \inst{?} command only if the authors have different
%   affiliation.

\institute[Millersville University of Pennsylvania]
% (optional, but mostly needed)
{
  Department of Mathematics
}
% - Use the \inst command only if there are several affiliations.
% - Keep it simple, no one is interested in your street address.

\date{ % (optional)
Fall
%Spring
%Summer
\the\year}

\subject{Talks}
% This is only inserted into the PDF information catalog. Can be left
% out. 



% If you have a file called "university-logo-filename.xxx", where xxx
% is a graphic format that can be processed by latex or pdflatex,
% resp., then you can add a logo as follows:

% \pgfdeclareimage[height=0.5cm]{university-logo}{university-logo-filename}
% \logo{\pgfuseimage{university-logo}}



% Delete this, if you do not want the table of contents to pop up at
% the beginning of each subsection:
\AtBeginSubsection[]
{
  \begin{frame}<beamer>
    \frametitle{Outline}
    \tableofcontents[currentsection,currentsubsection]
  \end{frame}
}


% If you wish to uncover everything in a step-wise fashion, uncomment
% the following command: 

%\beamerdefaultoverlayspecification{<+->}


\begin{document}

\begin{frame}
  \titlepage
\end{frame}

%\begin{frame}
%  \frametitle{Outline}
%  \tableofcontents
  % You might wish to add the option [pausesections]
%\end{frame}


% Since this a solution template for a generic talk, very little can
% be said about how it should be structured. However, the talk length
% of between 15min and 45min and the theme suggest that you stick to
% the following rules:  

% - Exactly two or three sections (other than the summary).
% - At *most* three subsections per section.
% - Talk about 30s to 2min per frame. So there should be between about
%   15 and 30 frames, all told.

%\section{Introduction}

\begin{frame}\frametitle{Objectives}

In this lesson we will:
\begin{itemize}
\item develop explicit methods for numerically approximating the
  solution to the wave equation, and
\item develop implicit methods for numerically approximating the
  solution to the wave equation.
\end{itemize}

\end{frame}
%%

\begin{frame}\frametitle{Wave Equation}

Consider the initial value problem for the wave equation,
\begin{align*}
u_{tt}
	&= u_{xx}
\mbox{ for $0 < x < 1$ and $t > 0$}	\\
u(x, 0)
	&= f(x)
\mbox{ for $0 < x < 1$}	\\
u_{t}(x, 0)
	&= g(x)
\mbox{ for $0 < x < 1$.}
\end{align*}
The differential equation may be
approximated as
\[
\frac{u_{i}^{j+1} - 2 u_{i}^{j} + u_{i}^{j-1}}{k^{2}}
	= \frac{u_{i+1}^{j} - 2 u_{i}^{j} + u_{i-1}^{j}}{h^{2}}	.
\]
The truncation error of this approximation is $O(k^{2}) + O(h^{2})$.
The time step size is $\Delta t = k$ and the spatial step size is
$\Delta x = h = 1/N$.
Let $r = k/h$ and solve for
$u_{i}^{j+1}$.
\[
%\label{eq:findiff:explicitwave}
u_{i}^{j+1}
	= r^{2} u_{i+1}^{j} + 2 (1 - r^{2}) u_{i}^{j} + r^{2} u_{i-1}^{j} - u_{i}^{j-1}	.
\]

\end{frame}
%%

\begin{frame}\frametitle{Stencil}

\begin{center}
\resizebox{1.00\textwidth}{!}{\includegraphics{explicitwave}}
\end{center}

\end{frame}
%%

\begin{frame}\frametitle{Initial Conditions}

If the initial conditions for the equation are $u(x, 0) = f(x)$ and
$u_{t}(x, 0) = g(x)$ for $0 < x < 1$ then
\[
%\label{eq:findiff:explicitwaveic0}
u_{i}^{0}
	= f(i \, h)
\mbox{ for $i = 1, 2, \ldots, N-1$.}
\]
Using the centered difference formula for the first derivative with
respect to $t$ yields
\[
%\label{eq:findiff:waveghost}
\frac{u_{i}^{1} - u_{i}^{-1}}{2 k}
	= g(i \, h)
\iff
u_{i}^{-1}
	= u_{i}^{1} - 2 k g(i \, h)
\]
for $i = 1, 2, \ldots, N-1$.
Set $j = 0$ and use the
expression just derived for $u_{i}^{-1}$.
\[
%\label{eq:findiff:explicitwaveic}
u_{i}^{1}
	= \frac{r^{2}}{2} f((i+1) h) + (1-r^{2}) f(i \, h) +
\frac{r^{2}}{2} f((i-1) h) + k g(i \, h)
\]
for $i = 1, 2, \ldots, N-1$.

\end{frame}
%%

\begin{frame}\frametitle{Example}

%\label{xmp:findiff:explicitwave}
Use the explicit finite difference formulas to approximate the
solution to the initial boundary value problem
\begin{align*}
u_{tt}
	&= u_{xx}
\mbox{ for $0 < x < 1$ and $t > 0$}	\\
u(0, t)
	= u(1, t)
	&= 0
\mbox{ for $t > 0$}	\\
u_{t}(x, 0)
	&= 0
\mbox{ for $0 < x < 1$}	\\
u(x, 0)
	&= \left\{ \begin{array}{rl}
0 & \mbox{if $0 \le  x \le 1/4$,}	\\
x-1/4 & \mbox{if $1/4 \le  x \le 3/8$,}	\\
1/2-x & \mbox{if $3/8 \le  x \le 1/2$,}	\\
0 & \mbox{if $1/2 \le  x \le 1$.}
\end{array} \right.
\end{align*}
Use $h = 1/20$ and $k = 1/20$.
Compare the finite difference approximation to the infinite series
solution at $t = 0, \, 1/5, \, 2/5, \, 3/5, \, 4/5, \, 1$.

\end{frame}
%%

\begin{frame}\frametitle{Solution}

\begin{center}
\resizebox{0.85\textwidth}{!}{\includegraphics{explicitwavexmp}}
\end{center}

\end{frame}
%%

\begin{frame}\frametitle{Implicit Scheme}

For a twice continuously differentiable function $f$,
\[
f(x)
	= \frac{f(x+h) + f(x-h)}{2} + O(h^{2})
\]
which is equivalent to the following equation,
\[
f(x)
	= \frac{f(x+h) + 2 f(x) + f(x-h)}{4} + O(h^{2})	.
\]
If $f = u_{xx}(x, t)$ then
\begin{align*}
u_{xx}(x, t)
	= {} & \frac{u_{xx}(x, t-k) + 2 u_{xx}(x, t) + u_{xx}(x, t+k)}{4}	\\
	= {} & \frac{u(x+h, t-k) - 2 u(x, t-k) + u(x-h, t-k)}{4 h^{2}}	\\
	&+ \frac{u(x+h, t) - 2 u(x, t) + u(x-h, t)}{2 h^{2}}	\\
	&+ \frac{u(x+h, t+k) - 2 u(x, t+k) + u(x-h, t+k)}{4 h^{2}}	\\
	&+ O(h^{2}) + O(k^{2})	.
\end{align*}

\end{frame}
%%

\begin{frame}\frametitle{Implicit Scheme}

Therefore the wave equation can be approximated by the differencing scheme,
\begin{align*}
\frac{u_{i}^{j+1} - 2 u_{i}^{j} + u_{i}^{j-1}}{k^{2}}
	= {} & \frac{u_{i+1}^{j+1} - 2 u_{i}^{j+1} + u_{i-1}^{j+1}}{4 h^{2}}
	+ \frac{u_{i+1}^{j} - 2 u_{i}^{j} + u_{i-1}^{j}}{2 h^{2}}	\\
	&+ \frac{u_{i+1}^{j-1} - 2 u_{i}^{j-1} + u_{i-1}^{j-1}}{4 h^{2}}	.
\end{align*}
The truncation error in this finite difference approximation is
$O(k^{2}) + O(h^{2})$.

\vspace*{0.10in}

The approximation can be written as
%\label{eq:findiff:boxwave}
\begin{align*}
-r^{2} u_{i+1}^{j+1} + 2 (2 + r^{2}) u_{i}^{j+1} - r^{2} u_{i-1}^{j+1}
	= {} & 2 r^{2} u_{i+1}^{j} + 4 (2 - r^{2}) u_{i}^{j} + 2 r^{2} u_{i-1}^{j}	\\
	&+ r^{2} u_{i+1}^{j-1} - 2 (2 + r^{2}) u_{i}^{j-1} + r^{2} u_{i-1}^{j-1}
\end{align*}
for $i = 1, 2, \ldots, N-1$ where $r = k/h$.

\end{frame}
%%

\begin{frame}\frametitle{Stencil}

\begin{center}
\resizebox{1.00\textwidth}{!}{\includegraphics{boxwave}}
\end{center}

\end{frame}
%%

\begin{frame}\frametitle{Matrix/Vector Form}

Suppose the boundary conditions are of the homogeneous Dirichlet type.
Define $A(z)$ as an $(N-1) \times (N-1)$ matrix:
\[
A(z)
	= \left[ \begin{array}{ccccccc}
2(2+z) & -z & 0 & \cdots & 0 & 0 & 0	\\
-z & 2(2+z) & -z & \cdots & 0 & 0 & 0	\\
\vdots & \vdots & \vdots & {} & \vdots & \vdots & \vdots	\\
0 & 0 & 0 & \cdots & -z & 2 (2+z) & -z	\\
0 & 0 & 0 & \cdots & 0 & -z & 2 (2+z)
\end{array} \right]	.
\]
The implicit finite difference
scheme can be written in matrix/vector form as
\[
%\label{eq:findiff:boxwavematrix}
A(r^{2}) \mathbf{u}^{j+1}
	= 2 A(-r^{2}) \mathbf{u}^{j} - A(r^{2}) \mathbf{u}^{j-1}
\]
When $j = 0$
\[
A(r^{2}) \mathbf{u}^{1}
	= 2 A(-r^{2}) \mathbf{u}^{0} - A(r^{2}) \mathbf{u}^{-1}
	= A(-r^{2}) \mathbf{u}^{0} + k A(r^{2}) \left[ \begin{array}{c}
u_{t}(h, 0)	\\
u_{t}(2 h, 0)	\\
\vdots	\\
u_{t}((N-1) h, 0)
\end{array} \right]	.
\]

\end{frame}
%%

\begin{frame}\frametitle{Example}

Use the implicit finite difference scheme
to approximate the solution to the following
initial boundary value problem.
\begin{align*}
u_{tt}
	&= u_{xx}
\mbox{ for $0 < x < 1$ and $t > 0$}	\\
u(0, t)
	&= u(1, t) = 0
\mbox{ for $t > 0$}	\\
u(x, 0)
	&= x (1-x)
\mbox{ for $0 < x < 1$}	\\
u_{t}(x, 0)
	&= \sin (5 \pi x)
\mbox{ for $0 < x < 1$}
\end{align*}
Use $N = 10$, $h = 1/10$, and $k = 1/20$ and iterate the solution
until $t = 1/2$.

\end{frame}
%%

\begin{frame}\frametitle{Solution (1 of 3)}

Given the values of $h$ and $k$ the parameter $r = 1/2$ and thus
\[
A(\frac{1}{4})
	= \left[ \begin{array}{rrrcrrr}
\frac{9}{2} & -\frac{1}{4} & 0 & \cdots & 0 & 0 & 0	\\
-\frac{1}{4} & \frac{9}{2} & -\frac{1}{4} & \cdots & 0 & 0 & 0	\\
\vdots & \vdots & \vdots & {} & \vdots & \vdots & \vdots	\\
0 & 0 & 0 & \cdots & -\frac{1}{4} & \frac{9}{2} & -\frac{1}{4}	\\
0 & 0 & 0 & \cdots & 0 & -\frac{1}{4} & \frac{9}{2}
\end{array} \right]
\]
and
\[
2 A(-\frac{1}{4})
	= \left[ \begin{array}{ccccccc}
7 & \frac{1}{2} & 0 & \cdots & 0 & 0 & 0	\\
\frac{1}{2} & 7 & \frac{1}{2} & \cdots & 0 & 0 & 0	\\
\vdots & \vdots & \vdots & {} & \vdots & \vdots & \vdots	\\
0 & 0 & 0 & \cdots & \frac{1}{2} & 7 & \frac{1}{2}	\\
0 & 0 & 0 & \cdots & 0 & \frac{1}{2} & 7
\end{array} \right]
\]
For the sake of brevity denote $A(1/4)$ as simply $A$ and $A(-1/4)$ as
simply $B$.

\end{frame}
%%

\begin{frame}\frametitle{Solution (2 of 3)}

Setting $u_{i}^{0} = (i \, h) (1 - i \, h)$ for $i = 1, 2, \ldots,
N-1$ and solving the tridiagonal system:
\[
A \left[ \begin{array}{c}
u_{1}^{1} \\ u_{2}^{1} \\ \vdots \\ u_{N-1}^{1}
\end{array} \right]
	= B \left[ \begin{array}{c}
h (1 - h) \\ 2h (1-2h) \\ \vdots \\ (N-1) h (1- (N-1) h)
\end{array} \right]
	+ k A \left[ \begin{array}{c}
\sin (5 \pi h) \\ \sin(10 \pi h) \\ \vdots \\ \sin(5(N-1) \pi h)
\end{array} \right]
\]
produce $\mathbf{u}^{1}$.
Iterate to move forward in $t$.

\end{frame}
%%

\begin{frame}\frametitle{Solution (3 of 3)}

\begin{center}
\resizebox{0.85\textwidth}{!}{\includegraphics{exampleboxwave}}
\end{center}

\end{frame}
%%

%\begin{frame}\frametitle{Homework}

%\begin{itemize}
%\item Read Section $x.y$
%\item Exercises: 
%\end{itemize}

%\end{frame}
%%

%%%
\end{document}

%%%%
%%%% EOF
%%%%
