4.5 Exercises

Exercise 4.1 Verify that \(I(t) = 130-120e^{-0.25t}\) is a solution to the differential equation \[\displaystyle \frac{dI}{dt} = 130-0.025I \] with \(I(0)=10\).

 

Exercise 4.2 Apply the rk4 solver with \(\Delta t = 0.1\) with \(N=10\) to the initial value problem \(\displaystyle \frac{dI}{dt} = 0.003 I \cdot (4000-I) \; I(0)=10\). Compare your graph to Figure 4.2. What differences do you observe? Which solution method (euler or rk4) is better (and why)?

 

Exercise 4.3 The following exercise will help you explore the relationships between stepsize, ending points, and number of steps needed. You may assume that we will start at \(t=0\) in all parts.

  1. If we wish to do an Euler’s method solution with step size 1 second and ending at \(t=5\) seconds, how many steps will we take?
  2. If we wish to do an Euler’s method solution with step size 0.5 seconds and ending at \(t=5\) seconds, how many steps will we take?
  3. If we wish to do an Euler’s method solution with step size 0.1 seconds and ending at \(t=5\) seconds, how many steps will we take?
  4. If we wish to do an Euler’s method solution with step size \(\Delta t\) and go to ending value of \(T\), what is an expression that relates the number steps \(N\) as a function of \(\Delta t\) and \(T\)?

 

Exercise 4.4 To get a rough approximation between error and step size, let’s say for a particular differential equation that we are starting at \(t=0\) and going to \(t=2\), with \(\Delta t = 0.2\). We know that the Runge-Kutta error will be on the order of \((\Delta t)^{4} =0.0016\). If we want to use Euler’s method with the same order of error, we could say \(\Delta t = .0001\). For that case, how many steps will we need to take?

 

Exercise 4.5 For each of the following differential equations, apply Euler’s method to generate a numerical solution to the differential equation and plot your solution. The stepsize (\(\Delta t\)) and number of iterations (\(N\)) are listed.

  1. Differential equation: \(\displaystyle \frac{dS}{dt} =3-S\). Set \(\Delta t = 0.1\), \(N = 50\). Initial conditions: \(S(0) = 0.5\), \(S(0) = 5\).
  2. Differential Equation: \(\displaystyle \frac{dS}{dt} =\frac{1}{1-S}\). Set \(\Delta t = 0.01\), \(N = 30\). Initial conditions: \(S(0) = 0.5\), \(S(0) = 2\).
  3. Differential equation: \(\displaystyle \frac{dS}{dt} = 0.8 \cdot S \cdot (10-S)\). Set \(\Delta t = 0.1\), \(N = 50\). Initial conditions: \(S(0) = 3\), \(S(0) = 10\).

 

Exercise 4.6 For each of the following differential equations, apply the Runge-Kutta method method to generate a numerical solution to the differential equation and plot your solution. The stepsize (\(\Delta t\)) and number of iterations (\(N\)) are listed. Contrast your answers with Exercise 4.5.

  1. Differential equation: \(\displaystyle \frac{dS}{dt} =3-S\). Set \(\Delta t = 0.1\), \(N = 50\). Initial conditions: \(S(0) = 0.5\), \(S(0) = 5\).
  2. Differential Equation: \(\displaystyle \frac{dS}{dt} =\frac{1}{1-S}\). Set \(\Delta t = 0.01\), \(N = 30\). Initial conditions: \(S(0) = 0.5\), \(S(0) = 2\).
  3. Differential equation: \(\displaystyle \frac{dS}{dt} = 0.8 \cdot S \cdot (10-S)\). Set \(\Delta t = 0.1\), \(N = 50\). Initial conditions: \(S(0) = 3\), \(S(0) = 10\).

 

Exercise 4.7 Complete the following steps:

  1. Apply the code euler to generate a numerical solution to the differential equation:
  • Differential equation: \(\displaystyle \frac{dS}{dt} = r \cdot S \cdot (K-S)\).
  • Set \(r=1.2\) and \(K=3\).
  • Set \(\Delta t = 0.1\), \(N = 50\).
  • Initial conditions (three different ones): \(S(0) = 1\), \(S(0) = 3\), \(S(0) = 5\).
  1. Plot your Euler’s method solutions with the three initial conditions on the same plot. What do you notice when you do plot them together?
  2. Make a hypothesis regarding the long term behavior of this system. Then plot a few more solution curves to verify your guess.

 

Exercise 4.8 Complete the following steps:

  1. Apply the code euler to generate a numerical solution to the differential equation:
  • Differential equation: \(\displaystyle \frac{dS}{dt} =K-S\).
  • Set \(K=2\).
  • Set \(\Delta t = 0.1\), \(N = 50\).
  • Initial conditions (three different ones): \(S(0) = 0\), \(S(0) = 2\), \(S(0) = 5\).
  1. Plot your Euler’s method solutions with the three initial conditions on the same plot. What do you notice when you do plot them together?
  2. Make a hypothesis regarding the long term behavior of this system. Then plot a few more solution curves to verify your guess.

 

Exercise 4.9 Let’s do some more work with Euler’s method for \(\displaystyle \frac{dS}{dt} = 0.8 \cdot S \cdot (10-S)\). This time set \(S(0)=15\), \(\Delta t = 0.1\), \(N = 10\). When you examine your solution, what is incorrect about the Euler’s method solution based on your qualitative knowledge of the underlying dynamics? Now calculate Euler’s method for the same differential equation for the following conditions: \(S(0)=15\), \(\Delta t = 0.01\), \(N = 100\). What has changed in your solution?

 

Exercise 4.10 Let’s do some more work with Euler’s method for \(\displaystyle \frac{dS}{dt} =\frac{1}{1-S}\). This time set \(S(0)=1.5\), \(\Delta t = 0.1\), \(N = 10\) and also \(S(0)=1.5\), \(\Delta t = 0.01\), \(N = 100\). Between these two solutions, what has changed? Do you think it is numerically possible to calculate a reasonable solution for Euler’s method near \(S=1\)? (note: this differential equation is an example of finite time blow up)

 

Exercise 4.11 Similar to Exercise 4.10, let’s apply the rk4 method for \(\displaystyle \frac{dS}{dt} =\frac{1}{1-S}\). This time set \(S(0)=1.5\), \(\Delta t = 0.1\), \(N = 10\) and also \(S(0)=1.5\), \(\Delta t = 0.01\), \(N = 100\). Between these two solutions, what has changed? Does this numerical solver do a better job in computing solutions compared to the Euler method?

 

Exercise 4.12 One way to model the growth rate hares is with \(\displaystyle f(H) = \frac{r H}{1+kH}\), where \(r\) and \(k\) are parameters. This is in constrast to exponential growth, which assumes \(f(H) = rH\).

  1. First evaluate \(\displaystyle \lim_{H \rightarrow \infty} rH\).
  2. Then \(\displaystyle \lim_{H \rightarrow \infty} \frac{r H}{1+kH}\).
  3. Compare your two answers. Discuss how the growth rate \(\displaystyle f(H) = \frac{r H}{1+kH}\) seems to be a more realistic model.
 

Exercise 4.13 In the lynx hare example we can also consider an alternative system where the growth of the hare is not exponential:

\[\begin{equation} \begin{split} \frac{dH}{dt} &= \frac{2 H}{1+kH} - 0.5HL \\ \frac{dL}{dt} &= 0.05 H L - dL \end{split} \end{equation}\]

Set the number of timesteps to be 2000. Apply Euler’s method to numerically solve this system of equations when \(k=0.1\) and \(k=1\). Plot your simulation results.

 

Exercise 4.14 Consider the differential equation \(\displaystyle \frac{dS}{dt} = \frac{1}{1-S}\). Notice that at \(S=1\) the rate \(\displaystyle \frac{dS}{dt}\) is not defined.

  1. If you applied Euler’s method solution with initial condition \(S(0)=0.9\), what do you think your solution would approach as the number of timesteps increased?
  2. If you applied Euler’s method solution with initial condition \(S(0)=1.1\), what do you think your solution would approach as the number of timesteps increased?
  3. Explain how you could come to the same conclusion as the previous two problems if you graphed \(\displaystyle f(S) = \frac{1}{1-S}\).

 

Exercise 4.15 Building on Exercise 4.4, let’s say for a particular differential equation we have \(N\) steps from \(0 \leq t \leq b\). An error of \(\epsilon\) is desired.

  1. What is the ratio \(\displaystyle \frac{N_{E}}{N_{RK4}}\), where \(N_{RK4}\) represents the number of steps needed for the Runge-Kutta method, and \(N_{E}\) the number of steps for Euler’s method?
  2. Make a plot of the ratio \(\displaystyle \frac{N_{E}}{N_{RK4}}\) for \(0 \leq \epsilon \leq 1\). How many more steps does Euler’s method need to do to achieve the same level of error, compared to the Runge-Kutta method?