## Simulation of Transient Behaviour of Simple Pendulum by Animation

Simulation of Transient Behaviour of Simple Pendulum by Animation

Objective:

• simulate the transient behaviour of pendulum in given timeframe by solving ODE in python.
• create  an animation of the results obtained from simulation.

Description:

• The motion of pendulum is described by the following second order ODE :

• where
• b=damping coeffcient
• m=mass of pendulum
• g=gravity
• l=length of pendulum

To solve this in python we need to convert it into two single order ODEs:

let θ=θ1 and

dθ1/dt=θ2                               ---->  1

by substituting θ=θ1,we get

and finally

------>  2

we have now 2 single order ODEs which can be solved in python.

programming in python:

import numpy as np
import math
from scipy.integrate import odeint
import matplotlib.pyplot as plt

b,g,l,m=0.05,9.81,1,1

def pendulum(theta,t):
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

initial=[0,3]
timeFrame=np.linspace(0,20,150)
simulation_values=odeint(pendulum,initial,timeFrame)

x0,y0,f=0,0,0
x2,y2=5,4
for i in simulation[:,0]:
x1= l*math.sin(i)
y1=-l*math.cos(i)
plt.figure();plt.grid();plt.plot([-1,1],[0,0]);plt.xlim(-3,3);plt.ylim(-2,1);plt.plot((x0,x1),(y0,y1))
plt.plot(x1,y1,'o',markersize=15)
f=f+1
plt.savefig("C:\\Users\\Admin\\Pictures\\gif2\\pen"+str(f)+".png")

plt.figure()
plt.plot(timeFrame,simulation_values[:,0],'b-')
plt.plot(timeFrame,simulation_values[:,1],'r--')
plt.xlabel("time frame")
plt.legend(["angular displacement","angular velocity"])
plt.savefig("C:\\Users\\Admin\\Pictures"+".png")

• In order to solve ODEs, scipy.integrate module and for plotting, matplotlib.pyplot and for arrays, numpy modules are necessary
• Initialization of variables are done and ODEs are defined in function named pendulum(theta,t)
• To study the simulation of transient behaviour of pendulum we must specify the initial conditions and timeframe in which we want to study.
• List named initial is initial conditions and array named timeFrame is time frame specified
• odeint is a function of scipy.integrate which is used to solve ODEs it takes three arguments
• 1- ODEs  which are written in a function  (here-function pendulum(theta,t))
• 2-initial conditions  for  ODEs(here- list-initial)
• 3-time frame in which we want to study the behaviour (here- list-timeframe)
• Then solutions are obtained in simulation_values as list where it consists of two values simualtion_values[0] = angular displacement values and simulation_values[1] = velocity values
• Then the results are plotted using matplotlib module
• Here we plotted two plot
• 1-the motion of pendulum, which can be plotted by using angular displacement (simulation_values[0] ) of pendulum and length of pendulum(l)
• 2-angular displacement vs time and angular velocity vs time two comparisions in one plot.

commands used in program:

Performing Animation:

• To perform animation here we used magick tool.
• Go to command prompt change directory to location where these pictures are saved
• Go to command prompt

>>> cd C:\Users\Admin\Pictures\gif2

>>> magick *.png output.gif

• Then you will get a gif file named output in the same loction.

Results:

The following are the outputs of the code:

Conclusion:

• Simulation of simple pendulum's transient behviour has been done sucessfully with scipy module in python.
• Animation of the pendulum has been done with magick tool from the obtained plots.

### Side crash Analysis of Neon Car Yugandhar Gopisetty · 2019-10-31 05:31:06

Side crash Analysis of Neon Car objective: Analyze the side crash analysis of neon and determination of sectional forces on the cross-members and cabin reinforcement, intrusions, and velocities in critical areas.  Methodology: The side model of Neon with Read more

### Frontal crash Analysis of Neon Car Yugandhar Gopisetty · 2019-10-30 15:06:37

Frontal crash Analysis of Neon Car objective: Analyze the frontal crash analysis of neon and determination of sectional forces on the shotgun, A-pillar, axial forces on the bumper, intrusions, and velocity at critical areas. Methodology : The frontal model of Read more

### Crash tube Analysis in Radioss using Hypermesh Yugandhar Gopisetty · 2019-10-22 07:53:26

Crash tube Analysis in Radioss using Hypermesh                   Objective: Simulate crash tube with different notch replacements and with type 11 contact. Analyze the simulations  by creating TH/part for componen Read more

### Analysis of simulation results of base setup and improved shell element properties Yugandhar Gopisetty · 2019-09-23 15:54:25

Simulation and Analysis of Rupture Plate Using Radioss in HyperMesh Objective: Run simulations on Rupture plate with various material law properties of radioss in HyperWorks. Observe and find the optimal material law property for rupture plate Description: Radi Read more

### Analysis of simulation results of base setup and improved shell element properties Yugandhar Gopisetty · 2019-09-20 15:21:43

Analysis of simulation results of base setup and improved shell element properties   Objective: Analyse the results of base setup before and after improving shell element properties. Interpret the observations spotted while comparison and plot graphs for the Read more

### 2D and 3D Tetra and Hexa Meshing in HyperMesh Yugandhar Gopisetty · 2019-09-20 08:26:17

2D and 3D Tetra and Hexa Meshing in HyperMesh   Objective: Create error free 2D meshing of the given models in hypermesh by using advanced pre-processing tools Generate 3D tera and hex volume meshing of the models in hypermesh Description: The following a Read more

### Geometry Clean-up and Maintaining Mesh Quality using HyperMesh Yugandhar Gopisetty · 2019-09-17 08:21:31

Geometry Clean-up and Maintaining Mesh Quality using HyperMesh Objective: Create an error free geometry using commands of HyperMesh for meshing. Generate an error free mesh  and maintain Mesh Quality using HyperMesh. Description: The following are the mode Read more

### Geometry Clean-up and Maintaining Mesh Quality using HyperMesh Yugandhar Gopisetty · 2019-09-17 08:18:03

Geometry Clean-up and Maintaining Mesh Quality using HyperMesh Objective: Create an error free geometry using commands of HyperMesh for meshing. Generate an error free mesh  and maintain Mesh Quality using HyperMesh. Description: The following are the mode Read more

### 2R Robotic Arm Simulator using Python Yugandhar Gopisetty · 2019-09-13 06:29:38

2R Robotic Arm Simulator using Python   Objective: create the animation of 2R Robotic arm for different θ values using python. Description: A 2R robotic arm consists of 2 links and has a manipulator at the end of 2nd link. First link is fixed at Read more

### Reading and Interpreting Data from File Using Python Yugandhar Gopisetty · 2019-09-13 06:27:40

https://projects.skill-lync.com/projects/Reading-and-Interpreting-Data-from-File-Using-Python-92768 Read more

Loading...