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 BEHAVIOUR OF A SIMPLE PENDULUM AND TO CREATE AN ANIMATION OF IT’S MOTION USING PYTHON THEORY: In Engineering, ODE is used to describe the transient behavior of a system. A simple example is a pendulum. The way the pendulum moves depends on Newton's second law. When this law is…
Sidharth Kalra
updated on 07 Jul 2020
AIM: TO SIMULATE THE TRANSIENT BEHAVIOUR OF A SIMPLE PENDULUM AND TO CREATE AN ANIMATION OF IT’S MOTION USING PYTHON
THEORY: In Engineering, ODE is used to describe the transient behavior of a system. A simple example is a pendulum.
The way the pendulum moves depends on Newton's second law. When this law is written down, we get a second order Ordinary Differential Equation that describes the position of the "bob" w.r.t time.
GOVERNING EQUATIONS:
d2θdt2+bm×dθdt+gLsinθ=0
where,
g = gravity (m/s2)
L = length of the pendulum (m)
m = mass of the ball (kg)
b = damping coefficient
OBJECTIVES:
INPUT VALUES:
L = 1 m
m = 1 kg
b = 0.05
g = 9.81 m/s2
FUNCTION PROGRAM:
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,300)
# 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}=\theta2$')
plt.plot(t,theta[:,1],'r--',label = r'$\frac{d\theta_2}{dt}=-\frac{b}{m}\theta_2-\frac{g}{L}sin\theta1$')
plt.ylabel('Plot')
plt.xlabel('Time')
plt.legend(loc='best')
plt.show()
# Animation using image stitching
# Defining counter variable
ct = 1
for th in theta[:,0]:
x_start = 0
y_start = 0
x_end = l*math.sin(th)
y_end = -l*math.cos(th)
# Naming the figures using the counter variable and saving them in '.png' format
filename = 'test%05d.png' %ct
ct = ct + 1
# Plotting figures and saving them with particular filename
plt.figure()
#Plotting the support
plt.plot([-1,1],[0,0], linewidth=4, color='red')
#Plotting the string through which the bob is attached
plt.plot([x_start,x_end],[y_start,y_end], linewidth=2, color='blue')
# Plotting the bob
plt.plot(x_end,y_end, marker='o', markersize=25, color='green')
plt.xlim([-2,2])
plt.ylim([-1.5,0.5])
plt.savefig(filename)
EXPLANATION OF PROGRAM:
TRANSIENT BEHAVIOUR:
PLOTS:
PLOTS SAVED WITH A DEFINITE FILENAME FORMAT INTO ANIMATION FOLDER
ANIMATION: The link for the animation has been mentioned below.
CONCLUSION: Establishing a clear view of the transient behavior of the simple pendulum by solving the second-order ODE defining its motion. Also, the animation of the pendulum motion is observed by stitching the successive plots into a gif and thereby converting into a '.avi' file format.
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...
DATA ANALYSIS (PYTHON)
AIM: DATA VISUALIZATION, COMPATIBILITY CHECK, AND BASIC PERFORMANCE CALCULATION USING PYTHON. INTRODUCTION: Data analysis is a process of inspecting, cleansing, transforming, and modeling data with the goal of discovering useful information, informing conclusions, and supporting decision-making. Data analysis has…
12 Jul 2020 03:37 PM IST
CURVE FITTING (PYTHON)
AIM: TO PERFORM CURVE FITTING FOR THE GIVEN TEMPERATURE AND CP DATA IN PYTHON 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. Curve fitting can involve either interpolation, where an exact fit…
09 Jul 2020 08:37 PM IST
BREAKING ICE WITH AIR CUSHIONED VEHICLE - FINDING MINIMUM PRESSURE WITH NEWTON-RAPHSON METHOD
AIM: TO CALCULATE THE MINIMUM PRESSURE OF AN ICE BREAKING AIR CUSHION VEHICLE USING NEWTON-RAPHSON METHOD THEORY: A hovercraft, also known as an air-cushion vehicle or ACV, is an amphibious craft capable of traveling over land, water, mud, ice, and other surfaces. Hovercraft use blowers to produce a large volume…
09 Jul 2020 03:04 PM IST
SOLVING SECOND ORDER ODE'S
AIM: TO SIMULATE THE TRANSIENT BEHAVIOUR OF A SIMPLE PENDULUM AND TO CREATE AN ANIMATION OF IT’S MOTION USING PYTHON THEORY: In Engineering, ODE is used to describe the transient behavior of a system. A simple example is a pendulum. The way the pendulum moves depends on Newton's second law. When this law is…
07 Jul 2020 09:03 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.