Skip to content

A scientific double pendulum simulator using Lagrangian mechanics and RK4, with graphs showing dynamics and energy 🍎

License

Notifications You must be signed in to change notification settings

GabrieleDG0/Double-Pendulum

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

24 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

WORK IN PROGRESS

Introduction

In this project, a double pendulum simulator is implemented using Lagrangian mechanics and a 4th order Runge-Kutta integrator (RK4). The simulation is presented in a graphical interface with real-time animation and plots for angular positions and energy evolution.

Note: you can find and .exe file on the Release section ready to use!

dp-simulator

Physical and Mathematical model

The double pendulum consists of two rigid rods, each with a concentrated mass at its end, connected serially with the first rod pivoted to a fixed point. The system is governed by Lagrangian mechanics, where the Lagrangian L is the difference between the kinetic energy T and the potential energy V:

image

The kinetic energy accounts for the translational motion of both bobs, including the interaction between the two masses:

image

The potential energy is determined by the height of each mass in the gravitational field:

image

with cartesian coordinates:

image

The Lagrangian of the system L = T - V:

image

The equations of motion are derived using the Euler-Lagrange formalism:

image

where b is viscous damping coefficient. The Euler-Lagrange equations lead to a coupled set of nonlinear second-order differential equations:

image

Using a matrix formalism, the angular accelerations can be expressed as:

image

where M is the matrix that groups the coefficients of the accelerations, respectively the first two terms of each of the two differential equations written in system form. The matrix C groups the coefficients of the velocities, related to the Coriolis and centripetal effects, while the vector G contains the contributions due to gravity.

Solving for the acceleration, useful for numerical implementation:

image

thus:

image

It is important to note that the explicit form of the accelerations may appear different in some educational texts or books. In fact, the terms are often rewritten by means of algebraic simplifications, collected in different ways or normalised with respect to lengths, masses or numerical constants to obtain more compact or didactic denominators. However, the representation proposed here is formally correct, and above all, directly derivable from the matrix formalism and the previous Euler-Lagrange equations, of consequence fully verifiable.

Numerical integration

The 4th-order Runge-Kutta is a numerical further, in particular a four-stage explicit integration method that combines several evaluations of the f-function in the step to achieve higher precision. Four increments (or slopes) are calculated at each interval h:

image

The next step approximation is obtained as a weighted combination of these values:

image

The higher the time step, the smoother the animation, but the lower the physical accuracy. Conversely, the lower the time step, the less smooth the animation, but the more physically accurate the simulation. The current time step (0.02) is a good compromise. In practical terms, RK4 achieves high accuracy with a much smaller number of steps than Euler method. The disadvantage is that it requires four times as many evaluations of the function f per step (4 steps instead of 1), but on the whole this additional cost is compensated for by the possibility of using considerably larger h. The RK4 method is in fact considered an excellent compromise between accuracy, computational cost and stability, even if it is more expensive per step. Graphical RK4 on approximating the blue function:

image

Graphical Interface

The simulator is implemented with Tkinter and features a responsive window that adapts to different screen sizes. The interface is divided into two main regions: a control panel and a visualization panel. The control panel allows adjustment of all physical parameters, initial conditions, and simulation parameters such as time step, the friction coefficients, masses, lenghts and angles. The visualization panel displays the pendulum animation, along with two auxiliary plots: angles versus time and energy versus time.

2

The pendulum animation represents each bob as a colored circle connected by rods, with optional trails to visualize the trajectory. The trail lines are semi-transparent and retain a fixed number of past positions, providing insight into the system's chaotic motion. The radius of each bob is proportional to the square root of its mass, providing a direct visual cue for relative mass distribution.

The angles versus time plot wraps angular positions in the [βˆ’Ο€,Ο€] range to avoid discontinuities and to facilitate comparison with typical theoretical analyses. The energy plot dynamically scales the vertical axis and displays kinetic, potential, and total energy using distinct colors. These plots are continuously updated alongside the animation, offering a comprehensive view of both the geometrical evolution and the energy dynamics of the system.

Simulation

The simulation runs in discrete time steps according to the RK4 integrator. The user can interrupt or continue the simulation at any time, reset the system to the initial conditions or switch the visibility of the trajectories. Changes to parameters or initial conditions are made in real time and the simulation is automatically reset to reflect these updates. This interactivity allows experimentation with different masses, lengths, damping and initial angular displacements and provides instant visual feedback on the resulting dynamics.

The combination of real-time animation, angle diagrams and energy monitoring allows a deep understanding of the complex behaviour of the double pendulum, including periodic, quasi-periodic and chaotic states. By slightly changing the initial conditions, users can observe drastically different results, illustrating the sensitive dependence on initial conditions that characterises chaotic systems.

This simulator represents a bridge between theoretical physics, applied mathematics, and computational implementation, making it suitable for educational, research, and exploratory purposes.

Contributions

If you find any bugs, errors or anything else, feel free to open an issue!

About

A scientific double pendulum simulator using Lagrangian mechanics and RK4, with graphs showing dynamics and energy 🍎

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages