Homework 4 Due 11/9/17 in class.¶
Reading: RungeKutta methods and error estimation are described in section 5.7 of Leveque. Stability is discussed in Chapter 7.

This problem is based on examples 7.17.3 in Leveque (in the book $k = \Delta t$). I suggest reading them before coding it up. For $\Delta t = 10^{3}$ and $\lambda=10$, solve equation (7.2) using each of Euler's Method and Trapezoidal Rule on the interval $\left[0,T\right]$, with $T=2$.
 First, write out the Trapezoidal rule discretization scheme in the form $u^{n+1} = \phi(u^{n},t_{n},t_{n+1})$, for some function $\phi$, giving an explicit formula for $u^{n+1}$ in terms of the known values.
 Implement Euler's method and, using the formula you derived, Trapezoidal rule to solve the ODE. Calculate the error between the numerical solution and the true solution, $u(t) = \cos(t)$, at the final time, $T=2$, and the maximum error over all times. Which method is more accurate for this problem? Explain why this makes sense. On the same graph plot the exact solution, the EM solution, and the TR method solution. (It's ok if the graphs are indistinguishable.)

Now rerun your codes for $\lambda = 2100$ and recalculate the errors at the final time, the maximum errors over all times, and replot the solutions by each method (you will probably want to put the EM solution on a separate graph). About how small do you need to take $\Delta t$ for EM to become stable?

In class we said that the Trapezoidal rule was unconditionally stable if the following inequality holds (where $z = \lambda \Delta t$):
\begin{align}
\left \frac{1 + \displaystyle\frac{z}{2}}{1  \displaystyle\frac{z}{2}} \right \leq 1
\end{align}
Prove that this inequality holds if and only if $Re(z) \leq 0$, confirming the unconditional stability of Trapezoidal rule.

In class we looked at error control by using a second order RungeKutta method (with numerical solution, $y^n$), and a thirdorder RungeKutta method (with numerical solution, $\tilde{y}^n$). After taking a time step with size $\Delta t$, we showed we could estimate the size of a step $\Delta t_{new}$ that would have been needed to ensure the local error $e_l(\Delta t_{new})$ is less than $\varepsilon$. That is, to ensure
\begin{align*}
e_l(\Delta t_{new}) \approx \lefty^n  \tilde{y}^n\right \approx C (\Delta t_{new})^3 \leq \varepsilon
\end{align*}
we found that $\Delta t_{new}$ should satisfy
\begin{align*}
\Delta t_{new} \leq \left( \frac{\varepsilon}{C} \right)^{1/3} \approx \left( \frac{\varepsilon (\Delta t)^3}{\lefty^n  \tilde{y}^n\right} \right)^{1/3}
\end{align*}
How would $C$ and this last inequality change if we had instead used fourth and fifth order RungeKutta methods to estimate $y^n$ and $\tilde{y}^n$? Show your work.

Write out the RungeKutta method with tableau given by
0 
0 
0 
$\alpha$ 
$\alpha$ 
0 

$\left(1\tfrac{1}{2\alpha}\right)$ 
$\frac{1}{2\alpha}$ 
Then show the method is secord order accurate. You may assume $\alpha > \tfrac{1}{2}$.