## Simulation of Transient behaviour of a Simple Pendulum

OBJECTIVE – To write a program to simulate the transient behaviour of a simple pendulum and to create an animation of its motion.

PROCEDURE –

In Engineering, ODE is used to describe the transient behavior of a system. A simple example is a pendulum

The way the pendulum moves depends on the Newtons second law. When this law is written down, we get a second order Ordinary Differential Equation that describes the position of the "ball" w.r.t time.

This ODE represents the equation of motion of a simple pendulum with damping

ASSUPTIONS-

In the above equation,

g = gravity in m/s2,

L = length of the pendulum in m,

m = mass of the ball in kg,

b=damping coefficient.

L=1 metre,

m=1 kg,

b=0.05.

g=9.81 m/s2.

PROGRAM AND EXPLANATION –

• The required modules like numpy, matplotlib.pyplot and scipy modules are imported.
• The governing equation of motion for the simple pendulum are utilized to create the state variable and defined under a function.
• Input variables like length of string, damping coefficient ,acceleration due to gravity, mass of ball are initiated.
• The initial conditioned and time span are defined.
• Odeint command is called and inputs are specified.
• A plot of angular displacement and angular velocity are created as functions of time.
• For loop which iterates through the values of angular displacement and angular velocity is defined.
• Vector decomposition is used to determine the location of the moving pendulum.
• Counter is setup in the loop,a filename is devised to take on the name of the count for ever subsequent o=plot of the pendulum position that is generated.
• The plt.savefig() command is used to save the plots in series under the filename and corresponding count.
• The plot images are stitched together using ImageMagick to generate an animation of the simple pendulum.
#code for simulation of a simple pendulum

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

def pendulum(theta, t, b, g, l, m):
theta2 = theta[0]
omega =theta[1]
theta_dot = [omega, -(b/m)*omega -(g/l)*math.sin(theta2)]
return(theta_dot)

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

IC = [0,3]

t = np.linspace(0,20,250)

theta = odeint(pendulum,IC,t,args =(b,g,l,m))
theta1 = theta[:,0]
omega1 = theta[:,1]

plt.plot(t,theta1,'b-',Label='Angular Displacement')
plt.plot(t,omega1,'r--',Label='Angular Velocity')
plt.ylabel('Anugular Variables')
plt.xlabel('Time')
plt.legend(loc='best')
plt.show()

ct = 1
for angle in theta1:
x0 = 0
y0 = 0
x1 = l*math.sin(angle)
y1 = -l*math.cos(angle)
filename = 'swing%05d.png'%ct
ct = ct + 1
#plots
plt.figure()
plt.plot([-1.5,-1.5],[0,0],linewidth = 7)
plt.plot([x0,x1],[y0,y1],linewidth = 1)
plt.plot(x1,y1,'o',markersize = 20)
plt.xlim([-2,2])
plt.ylim([-1.5,1.5])
plt.show()
plt.savefig(filename)

OUTPUT GRAPH-

CONCLUSION – Thus the program is written to simulate the transient behaviour of a simple pendulum and animation file is created.

### Pipe Flow simulation using Solidworks Habishek Umapathy · 2019-10-23 12:06:35

AIM – To run a pipe flow simulation with an inlet Reynolds number of 100, 1000 and 10000. For each of these cases do the following Place the line probes at 95%, 90%, 85%of the pipe length. Compare the normalized velocity profile at each of these locations. N Read more

### Data Analysis using Python Habishek Umapathy · 2019-08-13 15:39:11

OBJECTIVE – We have to write the script which should take column numbers as the input and plot the respective columns as separate images. The plot labels should be extracted from the file. If there is a request for a plot between column 1(crank angle) and column 8 Read more

### Curve Fitting using Python Habishek Umapathy · 2019-08-01 06:59:25

OBJECTIVE – To write a program to perform curve fitting.   Curve Fitting is the process of constructing a curve or mathematical functions, which possess the closest proximity to the real series of data. By curve fitting, we can mathematically constr Read more

### Breaking Ice with Air cushion Vehicle - Find minimum pressure with Newton-Raphson method Habishek Umapathy · 2019-07-29 18:24:30

The Newton Raphson method is an iterative technique that is used to find out the roots of a real valued function. It uses the idea that a continuous and differentiable function can be approximated by a straight-line tangent to it. In this case Newton Raphson method is Read more

### Otto Cycle using Python Habishek Umapathy · 2019-07-08 04:43:31

OBJECTIVE - To write a code for P_V diagram of an Otto cycle and calculate thermal efficiency

PROCEDURE –

ASSUMPTIONS

• Initially state variables p1,t1,t3 and gamma a Read more

### Parsing NASA Thermodynamic file Using MATLAB Habishek Umapathy · 2019-06-12 15:23:18

OBJECTIVE - 1. Write a function that extracts the 14 co-efficient and calculates the enthalpy, entropy and specific heats for all the species in the data file. Calculate the molecular weight of each species and display it in the command window. Plot the Cp, Ent Read more

### Genetic Algorithm Using MATLAB Habishek Umapathy · 2019-06-06 16:17:05

OBJECTIVE - Write a code in MATLAB to optimise the stalagmite function and find the global maxima of the function. PROCEDURE- The genetic algorithm is a method for solving both constrained and unconstrained optimization problems that is based on natural sele Read more

### Curve Fitting Using MATLAB Habishek Umapathy · 2019-06-04 07:59:31

OBJECTIVE – To write code to fit a linear and cubic polynomial for the Cp data and plot the linear and cubic fit curves along with the raw data points.   PROCEDURE – Curve Fitting is the process of constructing a curve or mathematical functions, whic Read more