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 program in PYTHON that solves the Second order ODE corresponding to motion of a simple pendulum and plot its Angular Displacement and Angular Velocity. Create an animation of the motion of pendulum by simulating the motion between 0-20sec with angular displacement = 0, angular velocity = 3rad/sec at time…
Ashwin Deepak
updated on 04 Sep 2021
A point mass attached to a light inextensible string and suspended from fixed support is called a simple pendulum. The vertical line passing through the fixed support is the mean position of a simple pendulum.
Pendulum is a weight suspended from a pivot so that it can swing freely. When a pendulum is displaced sideways from its resting, equilibrium position, it is subject to a restoring force due to gravity that will accelerate it back toward the equilibrium position. When released, the restoring force acting on the pendulum's mass causes it to oscillate about the equilibrium position, swinging back and forth. The time for one complete cycle, a left swing and a right swing, is called the period. The period depends on the length of the pendulum and also to a slight degree on the amplitude, the width of the pendulum's swing.
#Program to solve second order ODE's and simulate its pendulum motion
import matplotlib.pyplot as plt #Library for plotting functions
import math #Library for math functions
from scipy.integrate import odeint #For 'odeint' function
import numpy as np #For 'linspace' function
#Function Definition
def model(theta,t,b,g,l,m):
theta1=theta[0] #ODE 1
theta2=theta[1] #ODE 2
dtheta1_dt=theta2
dtheta2_dt=-(b/m)*theta2-(g/l)*math.sin(theta1)
dtheta_dt=[dtheta1_dt,dtheta2_dt]
return dtheta_dt
#Input Parameters
b=0.05 #Damping Coefficient
g=9.81 #Acceleration due to Gravity
l=1 #Length of Pendulum
m=1 #Mass of Pendulum
#Initial Condition
theta_0=[0,3] #Angular Displacement and Velocity
#Time point
t=np.linspace(0,20,300) #20 sec motion
#Solving ODE using 'odeint' function
theta=odeint(model,theta_0,t,args=(b,g,l,m))
#Plotting points
plt.plot(t,theta[:,0],'r-',label=r'$frac{dtheta_1}{dt}=theta_2$')
plt.plot(t,theta[:,1],'b--',label=r'$frac{dtheta_2}{dt}=-frac{b}{m}.theta_2-frac{g}{l}.sin(theta_1$)')
plt.xlabel('Displacement')
plt.ylabel('Time')
plt.title('Damped Harmonic motion')
plt.legend(loc='best')
plt.show()
#Animation of Simple pendulum
#Initial Position
xstart=0
ystart=0
ct=1
for i in theta[:,0]: #File
xend=l*math.sin(i)
yend=-l*math.cos(i)
plt.figure()
#Base of Pendulum
plt.plot([-1,1],[0,0],'black',linewidth=8)
#String of Pendulum
plt.plot([xstart,xend],[ystart,yend],'black')
#Bob of Pendulum
plt.plot(xend,yend,'o',markersize=20,color='r')
#Graph Limits of x nad y axis
plt.xlim(-1.5,1.5)
plt.ylim(-1.5,1.5)
#Saving the Frames
filename=str(ct)+'.png'
plt.savefig(filename)
ct=ct+1
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...
Solving second order ODE's using PYTHON Programming
AIM: To write a program in PYTHON that solves the Second order ODE corresponding to motion of a simple pendulum and plot its Angular Displacement and Angular Velocity. Create an animation of the motion of pendulum by simulating the motion between 0-20sec with angular displacement = 0, angular velocity = 3rad/sec at time…
04 Sep 2021 08:24 AM IST
OTTO CYCLE SOLVING USING PYTHON
AIM: To write a program in PYTHON to solve the Otto Cycle and Plot the PV Diagram. The code should create a PV diagram Find the Thermal Efficiency of the engine THEORY: An Otto cycle is an idealized thermodynamic cycle that describes the functioning of a typical spark ignition piston engine. It is the thermodynamic…
31 Aug 2021 08:14 PM IST
Meshing of Hood using Hypermesh
Aim : The aim is to generate a mid-surface and to create a mesh for the given Hood Model. FILE : HOOD_MODEL Quality Criteria : S.N Quality Criteria Value 1 Aspect Ratio 5 2 Skewness 45 3 Warping 15 4 Taper 0.5 5 Min. Length 2 Units 6 Max. Length 8 Units 7 Min angle Quad 45…
26 Apr 2021 06:53 PM IST
Static Structural Simulation of Bending of iPhone (ANSYS WORKBENCH)
Aim : Simulate the bending of Iphone as per the given cases : CASE 1 : Simulate the model with the given conditions CASE 2 : Move the bottom fingers from their defined position to the given position X= 22.5mm & Z= 10mm and obtain the results for the simulation. Also define the S-N curve for…
14 Apr 2021 02:47 PM 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.