## Exercise 1

Compute and plot a few solution to the time-dependent ODE:

$$\dot{x} = \cos(2t) x$$

## Exercise 2

Consider the system given corresponding to the idealized pendulum:

\begin{align} \dot{x} &= y \\ \dot{y} &= \cos(x) \end{align}

Draw a streamplot of this field in the region $[-2\pi,2\pi] \times [-\pi,\pi]$. Does this look familiar?

## Exercise 3

In the special case that we have a time-independent, linear system of ODEs, we may try a different approach to understanding the behavior. Recall that the solution to the system:

$$\dot{x} = Ax$$

is given by the matrix exponential $x(t) = e^{At}x(0)$. In an eigenbasis, recall that this seperates into a bunch of one-dimensional solutions in the direction of the eigenvectors. Now, suppose that we have the matrix ODE given by:

$$A = \begin{bmatrix} 3 & -4 \\ 4 & -7 \end{bmatrix}$$

Compute the eigenvalues and eigenvectors or $A$ using eig in scipy.linalg and use it to make a sketch of the solutions to the ODE (by hand). See if you can verify your sketch with a streamplot.

## Exercise 4

We'll try implementing the time stepping method we discussed for the advection equation. To do this, we'll discretize our domain into $n$ uniformly spaced set of points which I'll call $x_i$. Next, we want to discretize the derivatives that appear in the equation.

The trickiest part is figuring our what to do at the boundary points... In order to get around this problem, we'll simplify things by using a periodic boundary. That is, when we go off the right hand side, we end up back on the left and vice-versa.

This may sound tricky to implement but Numpy has a very useful function for this kind of thing! To do this, we'll use the np.roll function. Here's an example of what it does:

In [9]:
import numpy as np

u = np.arange(5)

print u
print

print np.roll(u, -1)  # rolls backward by one step.
print

print np.roll(u, 1)   # rolls forward by one step.
print

[0 1 2 3 4]

[1 2 3 4 0]

[4 0 1 2 3]



The crux of implementing this is to use the roll function to implement the finite difference approximations to the spatial derivative either in the upwind method

$$u_x(t_n,x_i) \approx \frac{u_{n,i} - u_{n,i-1}}{\Delta x}$$

or in the downwind method

$$u_x(t_n, x_i) \approx \frac{u_{n,i+1} - u_{n,i}}{\Delta x}$$

Finally, we want to put all this together into a time-stepping method. To do this, I'll do a time discretization:

$$u_t(t_n, x_i) \approx \frac{u_{n+1,i} - u_{n,i}}{\Delta t}$$

Putting all this together, say for the upwind method:

$$\frac{u_{n+1,i} - u_{n,i}}{\Delta t} + \frac{u_{n,i} - u_{n,i-1}}{\Delta x} = 0$$

Since I want to know the new value at time $t_{n+1}$, I'll just isolate the $u_{n+1,i}$ term to get:

$$u_{n+1,i} = u_{n,i} - \frac{\Delta t}{\Delta x} ( u_{n,i} - u_{n,i-1} )$$

Now that everything is simplified, this doesn't look so bad! Now, we can repeatedly iterative this to compute $u$ at later and later times.