Using finite difference methods for solving ordinary differential equations
The dynamics of a single pendulum and a double pendulum were computationally examined to analyse different finite difference methods for solving ordinary differential equations (ODEs). The fourth-order Runge-Kutta (RK4) was found to be the most suitable method considering the stability and the accuracy it can provide when solving general oscillatory problems. Subsequently, RK4 was employed to model the dynamics of a double pendulum. This yielded the understanding of the motion and the variation of the energy over time from which the dependence of the system on the initial conditions and the limitations of RK4 could be inferred.
Python 2.x is required to run the scripts (except for those with name beginning with 'ODE_').
Create an environment using conda as follows:
conda create -n python2 python=2.x
Then activate the new environment by:
conda activate python2
Python 3.x is required to run the scripts whose name begins with 'ODE_'. These scripts are Python 3.x version of 'Project A - Single.py' and 'Project A - Double.py'.
Create an environment using conda as follows:
conda create -n python3 python=3.x
Then activate the new environment by:
conda activate python3
- Single Pendulum
Figure 1: Dynamics of an undamped single pendulum using different FDMs. This illustrates the oscillations predicted by Leapfrog and RK4 are periodic with relatively constant amplitude. In contrast, the oscillations are becoming unbound over time for explicit Euler, whereas it appears to be converging for implicit Euler
Figure 2: The change in the total energy over time for an undamped single pendulum using the same parameters as in FIG. 1. Without damping, the law of energy conservation states that the total energy should be constant. However, the total energy is increasing and decreasing for explicit and implicit Euler, respectively.
Figure 3: Dynamics of a damped (D = 0.2) single pendulum with parameters. This illustrates that the oscillations predicted by RK4, explicit and implicit Euler are converging with time. The oscillations model by the Leapfrog method appears to converge initially. However, it becomes unbound at higher t.
Figure 4: The change in the total energy over time for a damped single pendulum using the same parameters as in FIG. 3. With damping, the law of energy conservation states that the total energy should decrease. This is true for FDMs except Leapfrog, where the total energy is decreasing at the beginning but increases at higher t.
Figure 5: The dynamics of the single pendulum and the variation of energy over time with and without the small angle approximation. The parameters are: h = 0.01, D = 0.2, theta_initial = (pi x 3)/4.
Figure 6: The dynamics of the single pendulum and the variation of energy over time with and without the small angle approximation. The parameters are: h = 0.3, D =0.2, theta_initial = (pi x 3)/4. The graph without the small angle approximation is stable, whereas the former is unstable.
- Double Pendulum
Figure 7: The dynamics of the double pendulum with parameters: h = 0.01, G = 0.0, R = {0.01, 1, 100}.
Figure 8: The variation of energy over time with parameters: h = 0.01, G = 0.0, R = {0.01, 1, 100} (i.e. the system in FIG. 7).
Figure 9: The dynamics of the double pendulum with parameters: h = 0.01, G = 1.0, R = {0.01, 1, 100}.
Figure 10: The variation of