I’ll help you create a $Python$ program to simulate and visualize the dynamics of a pendulum, including both simple and damped pendulum cases.
1 | import numpy as np |
Let me explain the code and the physics:
Physical System:
- The pendulum consists of a mass m at the end of a rigid, massless rod of length $L$
- Motion is governed by gravity ($g$) and optional damping ($b$)
- The equation of motion is: $θ̈ + (b/m)θ̇ + (g/L)sin(θ) = 0$
Code Structure:
PendulumSimulatorclass handles the physics calculations- Uses
scipy.integrate.odeintfor numerical integration of the equations of motion - Simulates both simple (undamped) and damped pendulum cases
Visualizations (4 plots):

a) Angular Displacement vs Time:
- Shows how the angle changes over time
- Simple pendulum oscillates continuously
- Damped pendulum’s oscillations decay
b) Angular Velocity vs Time:
- Shows how the angular velocity changes
- Simple pendulum maintains amplitude
- Damped pendulum shows decreasing velocity magnitude
c) Phase Space Plot:
- Shows relationship between angle and angular velocity
- Simple pendulum forms closed orbit (conservation of energy)
- Damped pendulum spirals toward center (energy dissipation)
d) Total Energy vs Time:
- Shows sum of kinetic and potential energy
- Simple pendulum maintains constant energy
- Damped pendulum shows energy decay
- Parameters Used:
- Length ($L$) = $1.0$ m
- Initial angle = $π/3$ radians ($60$ degrees)
- Initial angular velocity = $0$
- Damping coefficient (b) = $0.5$ kg/s for damped case
The simulation shows key physical principles:
- Conservation of energy in the simple pendulum
- Energy dissipation in the damped pendulum
- Nonlinear behavior at large angles
- Phase space representation of the dynamics









