1.5. ODEs Exercises#

Answer the following exercises based on the content from this chapter. The solutions can be found in the appendices.

Exercise 1.1

Solve the following IVP using the Euler method with a step length of \(h = 0.5\). Write down your solutions correct to 4 decimal places.

\[\begin{align*} y' + y = 1 - e^{-t} \qquad t\in [0,4], \qquad y(0) = 1. \end{align*}\]

Exercise 1.2

The exact solution to the IVP from Exercise 1.1 is \(y = 1 - te^{-t}\). Write a Python or MATLAB program to compute the solution to this IVP and calculate the absolute error for each value. Present your results in the form of a table and a plot of the numerical and exact solutions.

Exercise 1.3

Repeat Exercise 1.2 using values of \(h = 0.4, 0.2, 0.1, 0.05\) to solve the IVP.

(a) Produce a plot of the numerical solutions on the same axes.

(b) Calculate the global truncation error for \(y(1)\) and present your results as a table and a plot of the global truncation error against the step length \(h\). (Hint: you can use the NumPy command idx = np.argmin(abs(t - t0)) or the MATLAB command [~,idx] = min(abs(t - t0)) to determine the index of the value in the array t which is closest to t0).

(c) Comment on your results. What do they tell you about the Euler method?

Exercise 1.4

The motion of a pendulum can be modelled by the following ODE

\[ \begin{align*} \ddot{\theta} + \frac{g}{L} \sin(\theta) = 0, \end{align*} \]

where \(\theta\) is the angle between the pendulum and the vertical, \(L\) is the length of the pendulum and \(g=9.81\text{ms}^{-2}\) is the acceleration due to gravity.

../_images/pendulum.svg

Write a program that solves this IVP using the Euler method with \(h=0.001\) over the interval \(t\in [0, 5]\) for a pendulum of length \(L = 1\) set at an initial angle \(\theta = \frac{\pi}{2}\). Produce a plot of the displacement angle \(\theta\) against \(t\).