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 .
- Rewrite this problem as a system of two first-order ordinary differential equations in a state vector .
- Implement the forward Euler method with step size to approximate the solution from to .
- Using your implementation, compute the numerical approximation of .
- The exact solution is . Plot on the same axes the forward Euler approximation and the exact solution over .
- 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.
- Implement the classical fourth-order Runge–Kutta (RK4) method with step size for this first-order system on the interval .
- Using your implementation, compute the numerical approximation of .
- On a single plot, display the RK4 approximation, the forward Euler approximation from Question 5.1, and the exact solution over .
- 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