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 motion of simple pendulum by solvind 2nd order differential equation using python considering damping coefffcient. Objective: 1)To Understand the concept of converting 2nd order ODE to first order linear system. 2) To understand the odeint function to solve the diffential equation when provided…
Vinay Omase
updated on 12 Aug 2021
Aim: To simulate the motion of simple pendulum by solvind 2nd order differential equation using python considering damping coefffcient.
Objective: 1)To Understand the concept of converting 2nd order ODE to first order linear system.
2) To understand the odeint function to solve the diffential equation when provided with function and its derivative.
Equation for motion of simple pendulum:
To convert 2nd order ode to 1st order ode
consider, θ=θ1(displacement),
dθ/dt=dθ1/dt=θ2(velocity)
substituting the above in our 2nd order ode
we get,
The above equation is linear and can be solved using python
Differential equations are solved in Python with the Scipy.integrate package using function odeint
theta=odeint(model1,theta_0,t, args = (b,m,g,l))
model1 = Function name that returns derivative values at requested θ and t values as dθ/dt
theta_0=initial values angular displavement and velocit in our case
t=Time points at which the solution should be reported.
args()= Allows additional information to be passed into the model function.The args input is a tuple sequence of values.
Code:
import math
import numpy as np
from scipy.integrate import odeint
import matplotlib.pyplot as plt
def model1(theta,t,b,m,g,l):
theta1=theta[0]
theta2=theta[1]
theta1_dt=theta2
theta2_dt=-(b/m)*theta2-(g/l)*math.sin(theta1)
dtheta_dt=[theta1_dt,theta2_dt]
return dtheta_dt
b=0.05
g=9.81
l=1
m=1
#initial condition
theta_0=[0,3]
#time step
t=np.linspace(0,20,150)
#solve ode
theta=odeint(model1,theta_0,t, args = (b,m,g,l))
print(theta)
plt.plot(t,theta[:,0],'blue',label=r'$\frac{d\theta_1}{dt}=\theta2$')
plt.plot(t,theta[:,1],'red',label=r'$\frac{d\theta2}{dt}=-\frac{b}{m}\theta_2-\frac{g}{l}sin\theta_1$')
plt.legend(loc='best')
plt.show()
#animation and ploting
ct=1
displacement=theta[:,0]
for i in displacement:
x0=0
y0=0
x1=l*math.sin(i)
y1=-l*math.cos(i)
#plotting
plt.figure()
# point of attachment of string
plt.plot([-1.5,1.5],[0,0],linewidth=9)
#rope of pendulum
plt.plot([x0,x1],[y0,y1],linewidth=5)
#bob of pendulum
plt.plot(x1,y1,'-o',markersize=20)
plt.xlim=([-1.5,1.5])
plt.ylim=([-1.5,0.5])
filename='test%05d.png'%ct
plt.savefig(filename)
ct=ct+1
Plot:
The angular displacemet starts from 0 as we have provided the input, while the angular velocity starts at 3m/s. Both velocity and displacement are changing sinusoidal function whose amplitude approaches zero as time increases as we have considered damp factor in our equation.
Animation:
Errors: No major errors faced in program, but error with cygwin to create animation was consistent.
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 3 - Solving second order ODEs
Aim: To simulate the motion of simple pendulum by solvind 2nd order differential equation using python considering damping coefffcient. Objective: 1)To Understand the concept of converting 2nd order ODE to first order linear system. 2) To understand the odeint function to solve the diffential equation when provided…
12 Aug 2021 09:32 AM IST
Week 3 - Adiabatic Flame Temperature calculation
AIM:To calculate the abiabatic flame temperature for the combustion of fuel using pyhton. Objective: 1. Use the concept of newton raphsons method to solve the enthapy equation of products and reactants at constant pressure. 2.To monitor the effect of equivalence ratio on adiabatic flame temperature Adiabatic flame temperature:…
09 Aug 2021 02:19 PM IST
Week 2 Air standard Cycle
Aim: To write a program to simulate otto cycle using python, Considering the volume change w.r.t crank angle. Objective: To trace the volumetric compression and expansion with respect to crank angle. Otto cycle: The Otto cycle is a description of what happens to a mass of gas as it is subjected to changes of pressure,…
28 Jul 2021 09:59 AM IST
Week 10 - Simulating Combustion of Natural Gas.
Aim: The aim of the challeneg is to carry out combustion simulation and also consider the effect of water added in fuel on emmisions. Objective: The objective of the challenege is to understand chemical kinetics and its use to simulate the process of combustion using computer program. The reactant and product are discritized…
29 Apr 2021 03:12 AM 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.