All Courses
All Courses
Courses by Software
Courses by Semester
Courses by Domain
Tool-focused Courses
Machine learning
POPULAR COURSES
Success Stories
Simple Pendulum Simulation by solving second order ODE . . The objective of this program is to simulate a simple pendulum by solving second order ODE…
Aadil Shaikh
updated on 22 Jan 2020
Simple Pendulum Simulation by solving second order ODE .
.
b = damping Co-efficient
g = gravity m/s^2
L = length of string in (m)
m = mass of ball (kg)
d(θ1)dt=θ2 & d(θ2)dt=−bm⋅θ2−glsin⋅θ1
Python Program :
'''
Transient behaviour of simple pendulum by solving 2nd order ode
Code by AADIL SHAIKH
'''
import numpy as np
from scipy.integrate import odeint
import matplotlib.pyplot as plt
import math
# Function
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
# Inputs
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))
disp_data = theta[:,0]
# plot results
plt.figure(1)
plt.subplot(2,1,1)
plt.plot(t,theta[:,0],'b-',label=r'$\frac{d\theta_1}{dt}=\theta2$')
plt.ylabel('Angular displacement',fontsize = 'large' , fontweight = 'bold')
plt.xlabel('Time',fontsize = 'large' , fontweight = 'bold')
plt.legend(loc='best')
plt.title('Angular_disp vs Time & Angular_vel vs Time',fontsize = 'large' , fontweight = 'bold')
plt.subplot(2,1,2)
plt.plot(t,theta[:,1],'r--',label=r'$\frac{d\theta2}{dt}=-\frac{b}{m}\theta_2-\frac{g}{L}sin\theta_1$')
plt.ylabel('Angular Velocity (rad/s)',fontsize = 'large' , fontweight = 'bold')
plt.xlabel('Time',fontsize = 'large' , fontweight = 'bold')
plt.legend(loc='best')
#plt.savefig('Angular.png')
plt.show()
ct = 1
for i in range(len(t)) :
x0 = 0
y0 = 0
x1 = l*math.sin(theta[i,0])
y1 = -l*math.cos(theta[i,0])
filename = 'Pendu%04d.png' % ct
ct = ct + 1
plt.figure()
plt.plot([x0,x1],[y0,y1],'red',linewidth=2)
plt.plot([-1,1],[0,0],'g',linewidth = 4)
plt.plot(x0,y0,'o',markersize =10,markerfacecolor = 'k')
plt.plot(x1,y1,'o',markersize =30,markerfacecolor = 'm')
plt.title('Pendulum system')
plt.xlim([-1.2,1.2])
plt.ylim([-1.5,0.5])
plt.savefig(filename)
# https://youtu.be/V7UH3Ho2xZs
#
# THE END #
Explanation :
Plot :
Animation :
# THE END #
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...
Flow over a Throttle body - Using CONVERGE CFD
I. Introduction: In this Project, A Steady & Transient state simulation is done of a Flow through an Elbow joint consisting of a throttle valve. The steady state case is solved with the Throttle valve fully open until convergence is reached. While the Transient case is ran with the throttle valve rotating i.e…
18 Sep 2020 08:29 PM IST
Literature review – RANS Derivation and analysis
Introduction: The Reynolds-averaged Navier–Stokes equations (or RANS equations) are time-averaged equations of motion for fluid flow. The idea behind the equations is Reynolds decomposition, whereby an instantaneous quantity is decomposed into its time-averaged and fluctuating quantities,…
18 Sep 2020 08:28 PM IST
C.H.T Analysis on a Graphic card using ANSYS FLUENT
I. Introduction : In this project, A steady state conjugate heat transfer analysis on a Graphic card model is done. Graphic card has become an everyday used object and a very importat part of any computer system, laptops etc. This product is mass produced daily in millions and has made computers exceptionally efficient.…
18 Sep 2020 08:23 PM IST
Aerodynamics : Flow around the Ahmed Body using ANSYS FLUENT
I. Introduction : Automotive aerodynamics comprises of the study of aerodynamics of road vehicles. Its main goals are reducing drag, minimizing noise emission, improving fuel economy, preventing undesired lift forces and minimising other causes of aerodynamic instability at high speeds. Also, in order to maintain…
18 Sep 2020 08:21 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.