Animation of the chaotic motion a double-pendulum using Julia and Python. The julia version is implemented in a Jupyter notebook environment whereas the python version is a conventional script. Double pendulums of arbitrary lengths, masses, initial positions, and the initial velocities can be simulated using this code. Both versions of the code allow the animation to be saved in either mp4 or gif format.
The code can save the animation as a gif file. It can also playback the video in Jupyter notebook environment. The animation is recorded at equal time steps to preserve relative velocity of the pendulums in the video.
The animation is done using FuncAnimation() of matplotlib. The code can save the animation as a mp4 file. The python script was tested in spyder environment. Plotting in external window should be enabled to view the animation.
Package requirements for Julia version
- Differential Equations
Package requirements for Python version
- scipy.integrate (odeint)
- pylab, matplotlib (animation)
- imagemagick (to save animation as a gif file)
The mass and length of the pendulums, gravitational acceleration constant, the initial conditions and the simulaiton duration are defined at the beginning of the code. Different cases can be simulated by changing these parameters.
Double pendulum system animation. The left animation is from the julia code with m1 = m2 = 1kg, L1 = L2 = 1m, initial conditions: θ1 = 5π/8, θ2 = 5π/9, ω1 = 0, ω2 = 0. The right animation is from the python code with m1 = 2kg, m2 = 1kg, L1 =1.4m, L2 = 1m, initial conditions: θ1 = 5π/11, θ2 = 5π/9, ω1 = 0, ω2 = 0.
Here, θ1 and θ2 are the initial angular positions, and, ω1 and ω2 are initial angular velocities in SI units.