Jim Belk University of Glasgow

Homework 5

Due Date: Saturday, October 1

Instructions: Feel free to work together with other students in the class, though you must turn in your own copy of the solutions, and you must acknowledge anyone that you worked with. You can turn in your homework assignment by e-mailing me your solutions.

  1. As discussed in class, we can find an approximate solution to an initial value problem of the form \[ \frac{dy}{dt} \,=\, f(t,y),\qquad y(t_0) = y_0, \] using an iterative procedure known as Euler's method. First we choose a sequence \(\{t_n\}\) of times (typically equally spaced in steps of \(\Delta t\)), and then we compute a sequence \(\{y_n\}\) recursively by the formula \[ y_{n+1} \,=\, y_n \,+\, f(t_n,y_n)\,(t_{n+1}-t_n). \] The result is that \(y_n\) is a fairly good estimate for \(y(t_n)\). The error in this estimate comes from the fact that \(f(t_n,y_n)\) is not exactly the same as the average value of \(y'(t)\) between \(t=t_n\) and \(t=t_{n+1}\).
    1. Consider the intial value problem \[ \frac{dy}{dt} \,=\, (t-1)^2 - y^2,\qquad y(0) = 1. \] Use Euler's method with \(N=10\) steps to estimate the value of \(y(1)\). Repeat this for \(N=20\), \(N=50\), \(N=100\), and \(N=200\) steps.
    2. Use NDSolve in Mathematica to obtain an accurate value of \(y(1)\). Use this to compute the error \(\varepsilon\) of each of the estimates you found in part (a).
    3. Use ListPlot in Mathematica to make a log-log plot of the error \(\varepsilon\) vs. the number of steps \(N\).
    4. The error in Euler's method for this initial value problem satisfies an approximate power law of the form \[ \varepsilon \,\approx\, a\, N^p. \] Use the LinearModelFit command to compute a best-fit line for your plot in part (c) and estimate the values of \(a\) and \(p\).
    5. Based on your answer to part (d), how many steps would we have to use for the Euler's method estimate to be accurate to eight decimal places?
  2. There is a simple improvement to Euler's method known as the modified Euler method or Heun's method. Instead of estimating \(y_{n+1}\) using Euler's formula, we use the following procedure:
    1. First we use Euler's formula to obtain an initial estimate for \(y_{n+1}\): \[ y_{n+1}^{\text{init}} \,=\, y_n \,+\, f(t_n,y_n)\,(t_{n+1}-t_n). \]
    2. Next we use the value of \(y_{n+1}^{\text{init}}\) to obtain a more accurate estimate for the average slope between \(t=t_n\) and \(t=t_{n+1}\): \[ m_n \,=\, \frac{f(t_n,y_n) + f\bigl(t_{n+1},y_{n+1}^{\text{init}}\bigr)}{2}. \]
    3. Finally, we use the computed slope \(m_n\) to obtain a more accurate value of \(y_{n+1}\): \[ y_{n+1} \,=\, y_n + m_n(t_{n+1}-t_n) \]
    This procedure is used at each step to obtain the sequence \(\{y_n\}\).
    1. Consider again the initial value problem \[ \frac{dy}{dt} \,=\, (t-1)^2 - y^2,\qquad y(0) = 1. \] Use the modified Euler method to estimate the value of \(y(1)\) with \(N=10\), \(N=20\), \(N=50\), and \(N=100\) steps.
    2. The error \(\varepsilon\) in the modified Euler method satisfies an approximate power law of the form \[ \varepsilon \,\approx\, a\,N^p. \] Use the procedure from parts (c) and (d) in question 1 to estimate the values of \(a\) and \(p\).
    3. Based on your answer to part (b), how many steps would we have to use for the modified Euler method estimate to be accurate to eight decimal places?