## Transient Simulation of a Simple Pendulum Motion Using PYTHON

OBJECTIVE:

1. To simulate the Transient Behaviour of a Pendulum by Solving Second Order Differential        Equation

2. Obtain Plots for Angular Displacement and Angular Velocity vs Time.

INTRODUCTION:

Consider a simple pendulum system. A ball of mass m connected to a mass-less string of length L. The ball is made to swing to and fro. Due to action of gravity and air resistance the ball stops swinging at some particular point of time. The way a pendulum moves simply depends on newtons second law, F = ma. The second order linear non-homogenous equation is given below.

Here, L = length of the pendulum in m

g = gravitational acceleration in m/sec^2

m = mass of the ball in kg

b = damping coefficient

What we will do next is try creating an array so that we can pass our initial conditions value and compute the equation. Below given is an image showing how a second order derivative could be converted into first order derivative.

Value of Constant parametres:

L = 1 m

m = 0.1 kg

b = 0.02

g = 9.81 m/sec^2

Initial Conditions:

We will simulate the motion between 0-10 sec, for initial conditions we will take angular displacement = 0 rad and initial angular velocity =3rad/sec^2 at time t = 0

PYTHON CODE SNIPPET:

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

def pendulum_eq(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

b=0.02
g=9.81
l=1
m=0.1
theta_0 = [0,2] #initial conditions
t = np.linspace(0,10,150)
points = len(t)
L= np.arange(0,points,1)
theta = odeint(pendulum_eq,theta_0,t, args=(b,g,l,m) )
plt.plot(t,theta[:,0],'r-')
plt.plot(t,theta[:,1],'b--')
plt.xlabel('Time')
plt.ylabel('Plot')
plt.title('Displacement and Angular velocity vs time ')
# Animation
theta1 = theta[:,1]
x = l*np.sin(theta1)
y = -l*np.cos(theta1)
for points in L:
plt.figure()
plt.plot(x[points],y[points],'bo',markersize=20)
plt.plot([0,x[points]],[0,y[points]])
plt.xlim(-l-0.5,l+0.5)
plt.ylim(-l-0.5,l+0.5)
plt.xlabel( 'X cordinates')
plt.ylabel('Y cordinates')
plt.title('Transient Pendulum Simulation')
file_no = points
file_no = format(file_no,"01")
filename = "{}.png".format(file_no)
plt.savefig(filename)
plt.close()



### Simulating Conjugate Heat Transfer Flow Through Solid Pipe Using CONVERGE Saikat Paul · 2019-10-13 19:35:45

OBJECTIVE: 1. Simulating Conjugate Heat Transfer Flow through a solid pipe and post process using            CONVERGE Studio 2. Perform Grid dependancy Test and study the effect of Supercycling Stage Interval. INTRODUCTION: Conjugate he Read more

### Simulating Prandtl Meyer Shock Flow using Converge CFD Saikat Paul · 2019-09-29 17:24:54

OBJECTIVE: 1. To simulate a 2D shock flow on a plate, post process the results using converge CFD and        analyse the fluid property variations using paraview 2. To study the effect of SGS parameter on shock location INTRODUCTION: A shock is Read more

### Building a Otto Cycle Simulator Using Python and Sublime Text Editor Saikat Paul · 2019-09-27 21:28:58

OBJECTIVE:  1) To build a otto cycle simulator with engine kinematics using python. 2) Plotting the PV diagram as well as calculating efficiency of the otto cycle. INTRODUCTION: We are all familiar with air standard cycles which are used to describe the functio Read more

### Minimizing an Objective Function With Respect to Variables as Constraints. Saikat Paul · 2019-09-24 18:09:21

OBJECTIVE: i.) To minimize a objective function with respect to variables in the presence of constraints. ii.) Understanding application of minimizing cost functions for industrial or economic use. INTRODUCTION: Mathematical optimization is the process of optimizing Read more

### 2R Robotic Arm Simulation Using Python and Sublime Saikat Paul · 2019-09-23 10:12:32

OBJECTIVE:  To Simulate The  Forward Kinematics of a 2D Robotic Arm Using Python and Sublime.  INTRODUCTION: Why Python for Robotics ? Python is a very widely used language in the field of robotics because it can be implemented very easilly. Python pr Read more

### Calculating Drag Forces Over a Bicycle Using Python and Sublime Saikat Paul · 2019-09-22 16:53:20

OBJECTIVE: 1.) To compute the drag force experienced by a cyclist using python and sublime.  2.) Developing code to plot (velocity vs drag force) and (drag-coefficient vs drag Force). INTRODUCTION: The force generated on the frontal area of a bicycle due to air Read more

### Steady State Flow Over a Throttle Body using Converge CFD and Paraview Saikat Paul · 2019-09-12 15:35:34

OBJECTIVE:  1.) To perform a steady state simulation of fluid flowing over a throttle body and post process the results. 2.) Generate fine mesh using embedded grid system, plot Graphs for pressure, velocity, mass flow rate and total cell count . INTRODUCTION: I Read more

### Simulating Flow Through a Backward Facing Step using openFOAM Saikat Paul · 2019-09-11 04:53:49

OBJECTIVE : Use the icoFOAM solver to simulate the flow through a backward facing step for diferent mesh grades and compare the results obtained in each meshes. INTRODUCTION: openFoam provides few tutorials for their users to better understand how the solver works. Read more

### Significance of Interpolation Schemes and Flux Limiters in Finite Volume Method Saikat Paul · 2019-08-03 06:58:00

OBJECTIVE: To understand the significance of interpolation schemes and fux limiters in Finite Volume Method.  INTERPOLATION SCHEMES AND IT\'S SIGNIFICANCE: A finite volume method discretization is based upon an integral form of PDE equation. The PDE is written s Read more