All Courses
All Courses
Courses by Software
Courses by Semester
Courses by Domain
Tool-focused Courses
Machine learning
POPULAR COURSES
Success Stories
AIM: Simulation of the transient behaviour of a simple pendulum and creating an animation of its motion. GOVERNING EQUATION: A simple pendulum consists of a mass m hanging from a string of length L and fixed at a pivot point P. When displaced to an initial angle and released, the pendulum will swing…
NAVEEN SWAMI
updated on 18 May 2020
AIM: Simulation of the transient behaviour of a simple pendulum and creating an animation of its motion.
GOVERNING EQUATION:
A simple pendulum consists of a mass m hanging from a string of length L and fixed at a pivot point P. When displaced to an initial angle and released, the pendulum will swing back and forth with the periodic motion. When the motion of a pendulum reduces due to an external force, the pendulum and its motion are damped. These periodic motions of gradually decreasing amplitude are damped simple harmonic motion.
By applying Newton's second law for rotational systems, the equation of motion for the pendulum can be obtained:
θ = anglular displacement
t = time
b = damping coefficient, 0.05
m = mass ; 1 kg
l = length of pendulum; 1 m
g = gravity; 9.81 m/s^2
time domain= (0,20); in seconds
Initial conditions; at t=0
θ =0 and ώ=3 rad/sec
OBJECTIVE:
To solve the second-order ODE in PYTHON, we first convert it into two first-order ODE as shown below:
Ode solver in python takes the above matrix as input and provide the solution to second-order ODE.
PROGRAM:
import numpy as np
import math
import matplotlib.pyplot as plt
from scipy.integrate import odeint
#Solving 2nd order ODE to simulate pendulum behaviour
#pendulum constants
b=0.05
m=1
g=9.81
l=1
#defining initial conditions
theta_0=[0,3]
#time domain
t=np.linspace(0,20,150)
def model(theta,t,b,g,l,m):
theta1=theta[0]
theta2=theta[1]
dtheta1_dt=theta2
dtheta2_dt=(-b/m)*theta2 + (-g/l)*math.sin(theta1)
dtheta_dt=[dtheta1_dt,dtheta2_dt]
return dtheta_dt
#solving ODE
theta=odeint(model,theta_0,t,args=(b,g,l,m))
ang_disp=theta[:,0]
velocity=theta[:,1]
#plotting velocity and ang displacement graph
plt.plot(t,ang_disp,label='Angular Displacement')
plt.plot(t,velocity,label='Velocity')
plt.legend()
plt.xlabel('time (sec)')
plt.grid()
plt.xlim([0,20])
plt.show()
#Creating pendulum motion
ct=1
for p in ang_disp:
x_bob=l*math.sin(p)
y_bob=-l*math.cos(p)
plt.figure()
#rod
plt.plot([0,x_bob],[0,y_bob],linewidth=8)
#bob
plt.plot(x_bob,y_bob,'o',markersize=30)
#horizintal reference
plt.plot([-0.4,0.4],[0,0],linewidth=5)
#hinge
plt.plot(0,0,'o',markersize=3)
#vertical reference
plt.plot([0,0],[0,-1],'--',linewidth=2)
plt.plot
plt.xlim([-1,1])
plt.ylim([-1.2,0.2])
plt.title('Pendulum Simulation')
filename=str(ct)+'.png'
plt.savefig(filename)
ct=ct+1
STEPS:
1. Given pendulum constants(mass, length, damping coefficient and g) were defined.
2. theta_0 array created to define initial conditions.
3. t array was created using np.linespace command to create 150 equally spaced time intervals from 0 to 20 sec.
4. model function was created in which two first-order ODE as derived above were provided in a matrix form.
5. Using odeint solver, calling model and providing arguments, second-order ODE is solved and solutions(disp, velocity) along with time are saved in the matrix theta.
6. Angular displacement and velocity obtained were plotted against time.
7. To create the animation of pendulum motion, for loop was executed.
8. under for loop, the endpoint of pendulum rod was defined and line consisting of origin and endpoint was plotted for each time interval.
9. All the figures were saved sequentially using plt.savefig command.
10. All the figures were combined together to form animation of swinging pendulum.
ERROR FACED: No error encountered
OUTPUT:
The plot of displacement and velocity clearly states the motion of a pendulum reduces due to the damping effect. There is a gradual decrease in the amplitude of angular displacement and velocity.
Animation of pendulum motion: https://youtu.be/thxOzXkw8PU
CONCLUSION:
To simulate the transient behaviour of simple pendulum, second-order ODE was solved using PYTHON and animation of pendulum motion was created to describe the damping effect.
Leave a comment
Thanks for choosing to leave a comment. Please keep in mind that all the comments are moderated as per our comment policy, and your email will not be published for privacy reasons. Please leave a personal & meaningful conversation.
Other comments...
MBD Simulation on IC Engine Valve Train
AIM: MOTION ANALYSIS OF IC ENGINE VALVE TRAIN MECHANISM THEORY: Valve Train is a mechanical system in an IC engine that is responsible for controlling the intake and the exhaust of the combustion process. During the intake process, the intake valve opens to let air enter the combustion chamber and during the exhaust process,…
21 Jun 2020 08:00 AM IST
MOTION ANALYSIS OF IC ENGINE PISTON ASSEMBLY MECHANISM
AIM: MOTION ANALYSIS OF IC ENGINE PISTON ASSEMBLY MECHANISM. THEORY: In IC Engine, the combustion is driven by Slider Crank Mechanism. Inside the cylinder, the piston performs reciprocating motion which results in compression and expansion of gas inside the cylinder. This motion of the piston is guided by the Slider Crank…
18 Jun 2020 06:12 AM IST
MOTION ANALYSIS OF PLANETARY GEAR SYSTEM
AIM: MOTION ANALYSIS OF PLANETARY GEAR SYSTEM THEORY: A planetary gear mechanism also is known as Epicyclic Gear Train, is a gear mechanism consisting of 4 components, namely, sun gear A, several planet gears B, internal gear(ring gear) C and carrier D that connects planet gears as seen in the image below. It has a very…
11 Jun 2020 11:28 AM IST
MULTI-BODY DYNAMICS SIMULATION OF INTERNAL GENEVA MECHANISM IN SOLIDWORKS
AIM: MULTI-BODY DYNAMICS SIMULATION OF INTERNAL GENEVA MECHANISM IN SOLIDWORKS. THEORY: Geneva mechanism is the mechanism through which continuous rotation motion is converted into intermittent rotation motion. In this, the driver wheel rotates continuously and the driven wheel has rotation in regular intervals not continuously.…
02 Jun 2020 09:49 AM IST
Related Courses
Skill-Lync offers industry relevant advanced engineering courses for engineering students by partnering with industry experts.
© 2025 Skill-Lync Inc. All Rights Reserved.