## 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.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"])


• 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

>>> 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.

### 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:25:51

Reading and Interpreting Data from File Using Python   Objective: Read the data from given file and interpret the results in plots using python Creata a code which couldn't accept files not having specified extenion and it pops out the error in manual string Read more

### Curve Fitting for Temprature and C_p values Yugandhar Gopisetty · 2019-09-12 15:46:34

Curve Fitting for Temprature and C_p values Objective: create a linear and polynomial curve to fit for the given temperature and c_p values using scipy module. Description: The values for temperature and C_p are in a file called data, which can be read and sto Read more

### Analysis of Newton-Raphson values for Minimum Air Cushion Vehicle Pressure Yugandhar Gopisetty · 2019-09-11 10:29:53

Minimization of following function with respect to constraint equation function-  f(x,y)=5-(x-2)^2-2*(y-1)^2 constraint-  lambda(x,y)=x+4y-3   solution:- According to lagrangian method we consider two equations as one new equation i. Read more