All Courses
All Courses
Courses by Software
Courses by Semester
Courses by Domain
Tool-focused Courses
Machine learning
POPULAR COURSES
Success Stories
AIM: To simulate the transient behavior of a simple pendulum and to create an animation of it's motion. OBJECTIVE : To write a program in Python that solves the second-order ODE corresponding to the motion of a simple pendulum and to plot its angular displacement and angular velocity wrt time. To…
Sourabh Lakhera
updated on 17 Jul 2020
AIM: To simulate the transient behavior of a simple pendulum and to create an animation of it's motion.
OBJECTIVE :
THEORY: A simple pendulum is defined to have an object that has a small mass, also known as the pendulum bob, which is suspended from a light wire or string, such as shown in Figure 1.
Figure 1
BODY OF THE CONTENT :
PYTHON CODE FOR SOLVING ODEs AND Its ANIMATION :-
''' Code for solving second order ODE's and simulate its motion'''
import math
import matplotlib.pyplot as plt
import numpy as np
from scipy.integrate import odeint
def ode_function(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
# Inputs for the simple pendulum
# Damping coefficient
b = 0.05
# Acceleration due to gravity(m/s^2)
g = 9.81
# Length of string (m)
l = 2
# Mass of bob (kg)
m = 2
# Initial Conditions
theta_0 = [0,3]
# time points
t_span = np.linspace(0,20,150)
# Solving Second order differential equation with scipy plugin
theta = odeint(ode_function,theta_0,t_span,args = (b,g,l,m))
# Plotting the graph for the Damped harmonic motion of a pendulum
plt.plot(t_span,theta[:,0],'b-',label=r'$frac{dtheta1}{dt}=theta2$')
plt.plot(t_span,theta[:,1],'r--',label=r'$frac{dtheta2}{dt}=-frac{b}{m}theta2-frac{g}{l}sintheta1$')
plt.xlabel('Time (second)')
plt.ylabel('Plot')
plt.title('Harmonic motion of a Damped Simple Pendulum')
plt.legend(loc='best')
plt.grid()
plt.show()
# Iteration using for loop to create animation. Hence to obtain image at different position of motion of pendulum
loop_counter =1
tmp = theta[:,0]
for i in tmp:
x_start = 0
y_start = 0
x_end = l*math.sin(i)
y_end = -l*math.cos(i)
# Plotting for animation
plt.figure()
# Plotting String of pendulum
plt.plot([x_start,x_end],[y_start,y_end],linewidth=3)
# Plotting Bob of pendulum
plt.plot(x_end,y_end,'o',markersize=20,color='r')
# Plotting the rigid support through which string of pendulum is attached
plt.plot([-0.5,0.5],[0,0],linewidth=8,color='k')
# Plotting hatched vertical line for refernce
plt.plot([0,0],[0,-1.5],'--',color='y')
plt.xlim([-2,2])
plt.ylim([-3,2])
plt.title('Animation of transient behaviour of a Simple Pendulum')
filename = 'test%05d.png' % loop_counter
plt.savefig(filename)
loop_counter = loop_counter + 1
ERRORS :
1. missed to provide loop_counter value
Rectified by :-
RESULTS :
The above plot of angular displacement and angular velocity shows the pendulum's motion to be gradually decreasing. This is due to damping effect which exponentially decreases the amplitude and the velocity of motion.
For animation 150 plots were generated and were stitched together to form animation.The link of the animation of simulation-
CONCLUSION : In this way we can understand that any second order or any higher order ODE can easily be solved using Python, and simulation of transient behaviour of simple pendulum was made using it to explain the effect of damping on it's motion.
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...
Project 1 - Data Cleaning and Transformation using Pivot table and Charts for the Report on requirement of Team Hiring
Project Documentation: Optimizing Team Hiring Insights through Data Cleaning and TransformationIntroductionIn today's data-driven environment, businesses thrive on informed decision-making. At ABC Private Limited, a manufacturer and seller of diverse products ranging from Classic Cars to Trucks and Buses, understanding…
26 Sep 2024 02:54 PM IST
Project 2
Project Documentation: Alumni Career Choices AnalysisAimThe aim of this project is to analyze the career choices of alumni from two universities with respect to their passing year and the courses they completed. This analysis helps in understanding the career growth of alumni, which plays a crucial role in the institute's…
10 Jul 2024 08:03 AM IST
Project 1
From the series of queries and actions conducted on the ecommerce database, several insights can be derived regarding the user demographics and their activities on the platform. Firstly, the database contains information about users' demographics, such as their gender, country, language, and usage of applications like…
28 Feb 2024 07:45 PM IST
Project 2 - EDA on Vehicle Insurance Customer Data
EDA on Vehicle Insurance Customer Data Aim: The aim of this project is to perform exploratory data analysis (EDA) and data cleaning on two datasets containing customer details and policy details. The objective is to prepare the data for future analysis and modeling, identify patterns, and derive insights to aid business…
19 Feb 2024 08:36 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.