MTH3007B Weekly Problems 5

Vibes: …

Used Techniques:


5.1. Forward Euler for Second-Order ODE IVP

Question

Consider the second-order ordinary differential equation with initial conditions and .

  1. Rewrite this problem as a system of two first-order ordinary differential equations in a state vector .
  2. Implement the forward Euler method with step size to approximate the solution from to .
  3. Using your implementation, compute the numerical approximation of .
  4. The exact solution is . Plot on the same axes the forward Euler approximation and the exact solution over .
  5. Briefly comment on the accuracy and stability of the forward Euler method for this problem and step size, referring to your plot and the error at .

Hint: Choose and to form the system.

full solution below


5.2. RK4 for the Same Second-Order ODE IVP

Question

Consider again the initial value problem , , , written as a first-order system as in Question 5.1.

  1. Implement the classical fourth-order Runge–Kutta (RK4) method with step size for this first-order system on the interval .
  2. Using your implementation, compute the numerical approximation of .
  3. On a single plot, display the RK4 approximation, the forward Euler approximation from Question 5.1, and the exact solution over .
  4. Compare the error at for the forward Euler and RK4 methods, and discuss how the order of the methods is reflected in your numerical results and plots.

Hint: Reuse your system formulation and only change the time-stepping method.

full solution below

Python
Output