A comprehensive computational physics notebook exploring coupled oscillator systems through rigorous theory, numerical integration, and multi-domain diagnostics
| Three Pendulum System | Double Pendulum Beats |
|---|---|
![]() |
![]() |
This repository provides a theory-first, computation-forward study of coupled oscillations across two canonical physical systems:
- Spring-Coupled Pendulums — Nonlinear dynamics with spring coupling dependent on horizontal displacement
- Coupled Mass–Spring Chains — Finite chains with matrix/eigenmode structure and normal-mode decomposition
The project bridges classical mechanics theory with modern computational physics, combining:
- Lagrangian derivations for exact equations of motion
- Numerical ODE integration using scipy's
solve_ivp - Normal mode analysis via eigenvalue decomposition
- Frequency-domain diagnostics (FFT, modal projection, peak detection)
- Interactive animations and phase-space visualizations
- Two & Three Spring-Coupled Pendulums: Exact nonlinear equations + small-angle linearization
- Two-Mass Three-Spring System: Wall-bounded oscillators with explicit coupling
- N-Mass Chains: Generalized framework for arbitrary finite chains with tridiagonal stiffness matrices
- Full Lagrangian derivations (kinetic + potential energy → Euler–Lagrange equations)
- Exact nonlinear ODEs (no approximations during integration)
- Linearized small-angle theory for analytical normal-mode predictions
- Generalized eigenvalue problems:
$K\mathbf{v} = \omega^2 M\mathbf{v}$
- Clean, reusable state-space derivative functions
- High-order integration with
solve_ivp(RK45 adaptive method) - Modal projection + FFT for frequency extraction from simulated data
- Hann windowing to reduce spectral leakage
- Time Series: Angular/displacement evolution with energy tracking
-
Phase Portraits:
$(\theta, \dot\theta)$ and$(x, \dot x)$ trajectories - Configuration Space: Multi-dimensional coordinate plots
- Frequency Analysis: FFT spectra with theoretical mode overlays and peak annotations
- Poincaré Sections: Stroboscopic sampling for quasi-periodic motion
- Real-time animations synchronized with physics simulations
- Dynamic spring rendering (compression/extension with realistic coils)
- Exportable animations (GIF/MP4 formats)
📦 Coupled-Oscillations-Physics-Notebook
├── 📓 coupled_oscillations.ipynb # Main Jupyter notebook (11,000+ lines)
├── 📄 README.md # This file
├── 📋 requirements.txt # Python dependencies
├── 📝 theory.md # Extended theoretical derivations (if present)
├── 🎞️ OUTPUTS/ # Output directory
│ ├── ANIMATIONS/ # Saved animation files
│ └── FIGURES/ # Static plots and diagrams
- Python 3.8 or higher
- Jupyter Notebook or JupyterLab
- Required packages (see below)
-
Clone the repository
git clone https://github.com/PuspenduPH/coupled-oscillations-physics.git cd coupled-oscillations-physics -
Install dependencies
pip install -r requirements.txt
Or manually install core packages:
pip install numpy scipy matplotlib jupyter ipympl
-
Launch Jupyter Notebook
jupyter notebook coupled_oscillations.ipynb
For JupyterLab (recommended for interactive widgets):
jupyter lab coupled_oscillations.ipynb
Open notebook.ipynb and execute cells sequentially. The notebook is organized into self-contained sections:
- Section 1: Two spring-coupled pendulums (nonlinear model)
- Section 2: Three spring-coupled pendulums
- Section 3: Two coupled mass–spring oscillators
- Section 4: N-mass N-spring chains with arbitrary configurations
Each section includes:
- Geometry visualization
- Theoretical derivations (displayed as LaTeX)
- Numerical integration functions
- Animation generation
- Diagnostic plots (time series, FFT, phase space)
Consider two pendulums of length
Exact Nonlinear Equations (no small-angle approximation):
Linearized Normal Modes (small angles:
- In-phase mode:
$\omega_1^2 = g/L$ - Out-of-phase mode:
$\omega_2^2 = g/L + k(1/m_1 + 1/m_2)$
For
where
Normal modes satisfy the generalized eigenvalue problem:
This notebook is ideal for:
- Classical Mechanics Courses: Supplement lectures on oscillations, normal modes, and Lagrangian mechanics
- Computational Physics Labs: Hands-on experience with ODE integration, eigenvalue problems, and FFT analysis
- Research: Template for studying more complex coupled systems (e.g., nonlinear resonances, chaos)
- Self-Study: Learn advanced physics through interactive coding and visualization
- ODE Solver:
scipy.integrate.solve_ivpwith RK45 (Runge-Kutta 4th/5th order adaptive) - Eigenvalue Solver:
scipy.linalg.eighfor symmetric generalized problems - FFT:
numpy.fft.rfftfor real-valued signals (optimized Fourier transform) - Peak Detection:
scipy.signal.find_peakswith prominence/height filtering
- Framework: Matplotlib's
FuncAnimation - Rendering: Real-time spring coil generation with parametric curves
- Export: Pillow (GIF) and FFmpeg (MP4) backends
- Interactive Mode:
%matplotlib ipymplfor in-notebook widgets
- Dense output evaluation for smooth animations (uniform time grid)
- Vectorized NumPy operations for coordinate transformations
- Precomputed geometry (spring hooks, equilibrium positions)
- Efficient modal projection via matrix multiplication
beats_time_series.mp4
energy_transfer_time_series.mp4
beats_mass_spring_time_series_demo.mp4
FFT Spectrum with Peak Annotations |
Phase Portrait (θ, ω) |
3D Configuration Space Trajectory |
Poincaré Section Analysis |
Key Diagnostic Features:
- FFT Spectra: Dominant peaks annotated with frequencies (Hz) and theoretical predictions
-
Phase Portraits: Limit cycles and fixed points in
$(\theta, \omega)$ space -
Configuration Space: 3D trajectories in
$(x_1, x_2, x_3)$ coordinates - Poincaré Sections: Cross-sectional slices revealing quasi-periodic structure
Edit function calls to explore different regimes:
animation = simulate_double_pendulum(
theta_1_init=30.0, # Initial angle (degrees)
theta_2_init=-30.0, # Out-of-phase start
m1=1.0, m2=2.0, # Unequal masses
k=50.0, # Strong coupling
L=1.5, # Pendulum length
g=9.81, # Earth gravity
simulation_time=30.0 # Long integration
)Follow the modular structure:
- Define geometry function (optional visualization)
- Implement state-space derivatives
- Compute theoretical normal modes
- Create numerical frequency estimator
- Build animation routine
Save simulation results for external analysis:
# After integration
np.savetxt('trajectory.csv',
np.column_stack([t, theta1, theta2]),
header='time,theta1,theta2',
delimiter=',')This project is licensed under the MIT License — see the LICENSE file for details (or specify your preferred license).
- Classical Mechanics: Goldstein, Taylor & Marion, and Landau & Lifshitz for theoretical foundations
- Numerical Methods: SciPy community for robust scientific computing tools
- Visualization: Matplotlib developers for publication-quality graphics
- Inspiration: Physics educators and researchers advancing computational pedagogy
- Goldstein, H., Poole, C., & Safko, J. (2002). Classical Mechanics (3rd ed.). Addison-Wesley.
- Taylor, J. R. (2005). Classical Mechanics. University Science Books.
- Strogatz, S. H. (2015). Nonlinear Dynamics and Chaos (2nd ed.). CRC Press.
- Press, W. H., et al. (2007). Numerical Recipes: The Art of Scientific Computing (3rd ed.). Cambridge University Press.
Made with ❤️ and Python | Bridging Theory and Computation








