All Courses
All Courses
Courses by Software
Courses by Semester
Courses by Domain
Tool-focused Courses
Machine learning
POPULAR COURSES
Success Stories
Steps Followed: 1. Import below modules into the sublime text editor. import numpy as np from scipy.integrate import odeint import matplotlib.pyplot as plt import math 2. Define function that passes variables as argument 3. Define Variables as input b=0.02 # Damping coefficient g=9.81 # Acceleration…
Rohit Singh
updated on 17 Jun 2021
Steps Followed:
1. Import below modules into the sublime text editor.
import numpy as np
from scipy.integrate import odeint
import matplotlib.pyplot as plt
import math
2. Define function that passes variables as argument
3. Define Variables as input
b=0.02 # Damping coefficient
g=9.81 # Acceleration due to gravity
l=1 # Length of the string
m=0.1 # mass of the ball
4. Define initial Conditions of displacement and velocity
theta_0=[0,3]
5. Define Time
t=np.linspace(0,20,100)
6. Define ODE to solve
theta=odeint(model,theta_0,t,args=(b,g,l,m))
7. Plot the displacement and velocity with respect to time
8. Animation of the pendulum
import numpy as np
from scipy.integrate import odeint
import matplotlib.pyplot as plt
import math
# Define function that returns dtheta/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
#Define Variables as a input
b=0.02 # Damping coefficient
g=9.81 # Acceleration due to gravity
l=1 # Length of the string
m=0.1 # mass of the ball
#Initial condition
theta_0=[0,3]
#Time points
t=np.linspace(0,20,100) # Define time
#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$') # To plot Displacement
plt.plot(t,theta[:,1],'r--',label=r'$\frac{d\theta_2}{dt}=-\frac{b}{m}\theta_2-\frac{g}{L}sin\theta_1$')# To plot velocity
plt.ylabel('Displacement and velocity')
plt.xlabel('time')
plt.legend(loc='best')
plt.show()
#Animation
A=theta[:,0]
ct=1
x0=0;
y0=0;
for i in A:
#Define coordinates for the center of the ball w.r.t theta
x1=l*(math.sin(i));
y1=-l*(math.cos(i));
#Plotting fixed Point
filename=str(ct)+'.png'
ct=ct+1
plt.figure()
plt.plot([-1,1],[0,0])
#Plotting length of the string
plt.plot([x0,x1],[y0,y1])
plt.plot(x1,y1,marker='.',markersize=35)
plt.xlim([-1.5,1.5])
plt.ylim([-1.5,0.5])
plt.savefig(filename)
Output:
Above graph shows the angular displacement and angular velocity changes with respect to time.
Animation:
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 10 - Simulating Combustion of Natural Gas.
Combustion: Thermal NOx Thermal is produced during the combustion process when nitrogen and oxygen are present at elevated temperatures. Prompt NOx Prompt NOx is formed from molecular nitrogen in the air combining with fuel in fuel-rich conditions which exist, to some extent, in all combustion…
17 Aug 2021 07:34 AM IST
Week 9 - Parametric study on Gate valve.
Aim: To perform a parametric study on the gate valve simulation by setting the opening from 10 % to 80%. Obtain the mass flow rates at the outlet for each design point. Calculate the flow coefficient and flow factor for each opening and plot the graph. Discuss the results of the mass flow rate and flow coefficient. Geometry…
06 Aug 2021 03:59 AM IST
Week 8 - Simulating Cyclone separator with Discrete Phase Modelling
Cyclone separators Cyclone separators are separation devices (dry scrubbers) that use the principle of inertia to remove particulate matter from flue gases. Cyclone separators is one of many air pollution control devices known as precleaners since they generally remove larger pieces of particulate matter. Cyclone…
27 Jul 2021 09:50 AM IST
Week 6 - CHT Analysis on a Graphics card
Problem Statement: To Perform a steady-state conjugate heat transfer analysis on a model of a graphics card. Run the simulation by varying the velocity from 1m/sec to 5m/sec for at least 3 velocities and discuss the results. Find out the maximum temperature and heat transfer coefficient attained by the processor. Prove…
17 Jul 2021 12:57 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.