\documentclass{article}

\newenvironment{problem}[1]{\begin{framed}\noindent{\bf\LARGE #1}\\*[1em]}{\end{framed}}
\newenvironment{subproblem}[1]{\begin{framed}\noindent{\bf(#1)} }{\end{framed}}
\newenvironment{solution}{}{}
\newcommand{\firstsub}[1][a]{${}$\\\noindent{\bf(#1)} }

\usepackage{fullpage}
\usepackage{framed}
\usepackage{amsmath}
\usepackage{color}
\usepackage{epsfig}
\usepackage{pstricks}
\usepackage{pst-plot}
\usepackage{pst-coil}
\usepackage{multido}
\newcommand{\gp}[1]{{\left({#1}\right)}}
\newcommand{\px}[2]{\frac{\partial #1}{\partial #2}}
\newcommand{\dx}{\Delta x}
\newcommand{\dt}{\Delta t}

\begin{document}

\title{Math 142-1, Project 2}
\author{Your name here}
\date{}
\maketitle

\begin{problem}{Programming}
  In this project, you will implement the Lax-Friedrichs numerical scheme
  \begin{align*}
    z_i^{n+1} &= \frac{1}{2} (z_{i+1}^n + z_{i-1}^n) - \frac{\dt}{2\dx} (f(z_{i+1}^n) - f(z_{i-1}^n))
  \end{align*}
  for numerically solving the PDE
  \begin{align*}
    \px{z}{t} + \px{}{x} (f(z)) &= 0 \\
    f(z(x_l)) &= F_l \\
    f(z(x_r)) &= F_r
  \end{align*}
  for $x \in [x_l,x_r]$ and for $t \in [0,T]$.  This will be quite helpful to
  you later on in the course, when you will be able to use this numerical method
  to check your answers on homework problems.  Using this tool to get some
  intuition for how the PDEs we discuss in this course evolve may also be
  helpful to you on homework and exams.

  Your numerical scheme will require careful treatment of the boundaries.  If
  you have valid data for $z_m^n$ for $1 \le m \le M-1$, then the numerical
  scheme above will require $z_0^n$ and $z_M^n$ to compute $z_m^{n+1}$.  Note
  that flux boundary conditions enter into the numerical method through
  $f(z_0^n) = F_l$ and $(z_M^n) = F_r$.  But this scheme still requires $z_0^n$
  and $z_M^n$.  For this, we want to use the approximations $z_0^n = z_1^n$ and
  $z_M^n = z_{M-1}^n$.
\end{problem}

\begin{problem}{Problem 1}
  Show that the scheme above can be written as
  \begin{align*}
    \frac{z_i^{n+1} - \frac{1}{2} (z_{i+1}^n + z_{i-1}^n)}{\dt} + \frac{f(z_{i+1}^n) - f(z_{i-1}^n)}{2\dx} &= 0
  \end{align*}
\end{problem}

\begin{solution}
  \textbf{\textcolor{red}{Your solution goes here}}
\end{solution}

\begin{problem}{Problem 2}
  Show that, if $z$ is smooth, then the PDE we are solving can be written in the
  form
  \begin{align*}
    \px{}{t} \int_a^b z \,dx + f(z(b,t)) - f(z(a,t)) &= 0.
  \end{align*}
  This integral form of the PDE is called the \textit{weak form} because its
  requirements on $z$ are weaker; no spatial derivatives of $z$ are required, so
  $z$ need not be differentiable in space.  In fact, $z$ need not even be
  continuous.  You will need to use this form to show that non-smooth solutions
  satisfy the PDE.  Such non-smooth solutions are called \textit{weak solutions}
  (solutions to the original differential form of the PDE are called
  \textit{strong solutions}).  Weak solutions must satisfy the above equation
  for any choices $a$ and $b$.
\end{problem}

\begin{solution}
  \textbf{\textcolor{red}{Your solution goes here}}
\end{solution}

\begin{problem}{Problem 3}
  Consider the PDE
  \begin{align*}
    \px{z}{t} + c \px{z}{x} &= 0 \qquad z(x,0) = z_0(x)
  \end{align*}
  where $c$ is a constant and $x \in (-\infty,\infty)$.  Show that $z(x,t) =
  z_0(x-c t)$ is a \textit{weak} solution to this PDE, even if $z_0$ (and thus
  $z$) is not differentiable.
\end{problem}

\begin{solution}
  \textbf{\textcolor{red}{Your solution goes here}}
\end{solution}

\begin{problem}{Problem 4}
  In the PDE from the previous problem, let $c \in \{1, 2, 3, -1\}$.  Use the
  domain $x \in [-1,1]$ and $t \in [0,\frac{1}{4}]$, choosing boundary
  conditions ($F_l$ and $F_r$) so that $z(x,t) = |x-c t|$ is the analytic
  solution.  Take time steps $\dt = k \dx$, for $\dx \in
  \{2^{-6},2^{-8},2^{-10}\}$ while fixing $k$.  What happens numerically when
  $k|c|>1$?  What happens numerically when $k|c|<1$?  For each $c$, plot the
  analytic solution along with the solution for each choice of $\dx$ using $k =
  0.9/|c|$.  Repeat the process with $k = 1.1/|c|$.
\end{problem}

\begin{solution}
  \textbf{\textcolor{red}{Your solution goes here}}
\end{solution}

\begin{problem}{Problem 5}
  The numerical scheme above does not work for all choices of $\dt$ and $\dx$.  The following restriction must be enforced
  \begin{align*}
    \dt &< \frac{\dx}{\max\limits_x |f'(z(x,t))|}
  \end{align*}

  For each of the PDEs (defined by the flux function $f(z)$) and analytic
  solutions in the table below plot the numerical solution that you obtain
  superimposed with the analytic solution.  If your numerical scheme is
  implemented correctly and $\dx$ is large enough, the two should be very close.
  In each case, $x \in [-1,1]$ and $t \in [0,\frac{1}{2}]$.

  \begin{tabular}{|c|cc|}
    \hline
    $\#$ & $f(z)$ & $z(x,t)$ \\
    \hline
    1 & $z$ & $|x-t|$ \\
    2 & $-z$ & $|x+t|$ \\
    3 & $2z$ & $|x-2t|$ \\
    4 & $\frac{1}{2}z^2$ & $1$ \\
    5 & $\frac{1}{2}z^2$ & $\frac{x}{t+1}$ \\
    6 & $\frac{1}{2}z^2$ & $\frac{x}{t-2}$ \\
    7 & $\frac{1}{2}z^2$ & $\begin{cases} 1 & x < 0 \\ -1 & x > 0 \end{cases}$ \\
    8 & $\frac{1}{2}z^2$ & $\begin{cases} -1 & x < -t \\ \frac{x}{t} & -t < x < t \\ 1 & x \ge t \end{cases}$ \\
    9 & $\frac{1}{2}z^2$ & $\begin{cases} 2 & x < t \\ 0 & x > t \end{cases}$ \\
    \hline
  \end{tabular}
\end{problem}

\begin{solution}
  \textbf{\textcolor{red}{Your solution goes here}}
\end{solution}

\begin{problem}{Problem 6}
  Show that $z(x,t) = \begin{cases} 2 & x < 0 \\ 0 & x > 0 \end{cases}$ is
  \textit{not} a weak solution to the PDE $z_t + z z_x = 0$.
\end{problem}

\begin{solution}
  \textbf{\textcolor{red}{Your solution goes here}}
\end{solution}

\begin{problem}{Problem 7}
  Show that $z(x,t) = \begin{cases} -1 & x < 0 \\ 1 & x > 0 \end{cases}$ is a
  weak solution to the PDE $z_t + z z_x = 0$.  Your numerical implementation
  does not produce this solution; the solution that the numerical method will
  produce is in the table above.  Since there are at least two solutions, this
  PDE need not have unique weak solutions.
\end{problem}

\begin{solution}
  \textbf{\textcolor{red}{Your solution goes here}}
\end{solution}

\begin{problem}{Final Notes}
  At this point, you should have a working numerical method for these sorts of
  PDEs, which you will be using for the third project.  You may also use it to
  verify homework problems and generally understand how the solution to PDEs
  will behave.
\end{problem}

\end{document}
