All Courses
All Courses
Courses by Software
Courses by Semester
Courses by Domain
Tool-focused Courses
Machine learning
POPULAR COURSES
Success Stories
AIM: To write a python program that represents the(ODE) equation of motion of a simple pendulum with damping. THEORY: The second-order ODE is simple pendulum's harmonic motion with damper, hence with decreasing amplitude. d2θdt2+(bm)⋅(dθdt)+(gL)⋅sin(θ)=0 This system is equivalent…
Sai Krishna S
updated on 25 Dec 2021
AIM:
To write a python program that represents the(ODE) equation of motion of a simple pendulum with damping.
THEORY:
The second-order ODE is simple pendulum's harmonic motion with damper, hence with decreasing amplitude.
d2θdt2+(bm)⋅(dθdt)+(gL)⋅sin(θ)=0
This system is equivalent to mass attached with spring and damper. Generally, higher-order ODEs are solved by breaking them into single-order ODE. This is applicable in our case also.
dθ1dt=θ2
dθ2dt=−(bm)⋅θ2−(gL)⋅sinθ1
These are the 2 equations we get here
CODE:
import numpy as np
from scipy.integrate import odeint
import matplotlib.pyplot as plt
import math
# function that returns dz/dt
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
b=0.05
g=9.81
l=1
m=1
#initial condition
theta_0=[0,3]
#time points
t=np.linspace(0,20,200)
#solve ODE
theta=odeint(model,theta_0,t,args=(b,g,l,m))
#plot results
plt.plot(t,theta[:,0],'b-',label=r'$\frac{d\theta_1}{dt}=\theta_2$')
plt.plot(t,theta[:,1],'r--',label=r'$\frac{d\theta_2}{dt}=-\frac{b}{m}\theta_2-\frac{g}{L}sin\theta_1$')
plt.xlabel('Time (s)')
plt.ylabel('Position and Velocity')
plt.title("Plot of ang. disp and ang. vel w.r.t time")
plt.legend(loc='best')
#plt.show()
x = theta[:,0]
ct = 1
# the for loop has been created because to show that the pendulum has run for 20 sec for different values of theta.
for i in x:
x0 = 0
y0 = 0
x1 = (x0 + l*math.sin(i))
y1 = -(y0 + l*math.cos(i))
# plot function
plt.figure()
plt.plot([-1 ,1] , [0,0] , color = "yellow" , linewidth = 8)
plt.plot(x0,y0 , 'o' ,marker = 'o', markersize = 5 , color = "purple")
plt.plot([ x0,x1] , [y0, y1] , linewidth = 3 , color = "red")
plt.plot( x1 ,y1 , 'o' ,marker = 'o', markersize = 25 , color = "green")
plt.title("Damping of Simple Pendulum")
plt.xlim([-2,2])
plt.ylim([-2,2])
plt.grid ('on')
filename = 'test%05d.png' % ct # name for saving the filename to create image one by one
#filename=str(ct)+'.png'
plt.savefig(filename)
ct =ct +1
plt.show()
EXPLANATION:
We can infer that the animation/video is more smooth/continuous due to the low damping coefficient, if the damping coefficient is increased then, the resistance to the motion will be higher.
OUTPUT:
LINK: https://drive.google.com/file/d/18e2g5cbwN-kzjBv7g4p0_fCObnNC_iml/view?usp=sharing
Animation GIF has been created using the ImageMagick software.
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...
Week 4 -Breaking Ice with Air cushion Vehicle - Find minimum pressure with Newton-Raphson method
OBJECTIVE : Write a python code to find out the minimum value of pressure at h=0.6ft by using the Newton Raphson method. Write a python code to find the optimal relaxation factor for this problem with the help of a suitable plot. Write a python code to tabulate the results of pressure for h = [0.6,1.2,1.8,2.4,3,3.6,4.2]…
16 Jan 2022 06:06 PM IST
Week 6 - Data analysis
AIM : To write a python script to analyze the data available in the given file. OBJECTIVE : Check the compatibility of the file Calculate the area under the P-V diagram. Calculate the power output of this engine assuming that RPM is 1500 Calculate its specific fuel consumption. THEORY : Parsing means to break it…
14 Jan 2022 06:12 PM IST
Week 5 - Curve fitting
AIM : To write a code in Python to fit a linear and cubic order polynomial for the given Cp data. THEORY : Curve fitting is the process of constructing a curve or mathematical function that has the best fit to a series of data points, possibly subject to constraints or it can be defined as the process of finding…
30 Dec 2021 06:04 PM IST
Week 3 - Solving second order ODEs
AIM: To write a python program that represents the(ODE) equation of motion of a simple pendulum with damping. THEORY: The second-order ODE is simple pendulum's harmonic motion with damper, hence with decreasing amplitude. d2θdt2+(bm)⋅(dθdt)+(gL)⋅sin(θ)=0 This system is equivalent…
25 Dec 2021 05:32 PM IST
Related Courses
0 Hours of Content
Skill-Lync offers industry relevant advanced engineering courses for engineering students by partnering with industry experts.
© 2025 Skill-Lync Inc. All Rights Reserved.