A Python implementation of a chaotic N-pendulum simulation using Lagrangian mechanics. Extreme sensitivity of chaotic systems to initial conditions.
4_pendulum_50_instances.mp4
pip install -r requirements.txtNote: For video export, you'll need FFmpeg installed:
- macOS:
brew install ffmpeg - Linux:
sudo apt-get install ffmpeg - Windows: Download from ffmpeg.org
python run_all.pyConfig: Edit the configuration in run_all.py:
N = int # Number of pendulum segments (2, 3, 4, ...)
T = int # Simulation duration in seconds
M = int # Number of pendulum instances
pertubation = float # Positional deviation from each otherfunc_N{N}k.pkl: Saved equations of motionsimulation_results.npz: Simulation data (positions over time){N}_pendulum_{M}_instances.mp4: Final animation video
A C++ renderer is available for high-resolution, high-instance videos. It reads the simulated trajectories from Python and streams raw RGB frames directly into FFmpeg.
cd cpp_renderer
cmake -S . -B build
cmake --build build --config ReleaseRequirements:
- CMake ≥ 3.16 (
brew install cmakeon macOS,sudo apt install cmakeon Debian/Ubuntu) - A C++17-capable compiler such as clang++ or g++ (Xcode command-line tools or
build-essential) - FFmpeg available on your PATH (
brew install ffmpeg,sudo apt install ffmpeg)
- Toggle
use_cpp_renderer = Trueinsiderun_all.py.