Project

SIMULATION OF TRANSIENT BEHAVIOR OF SIMPLE PENDULUM

OBJECTIVE:

To script a code for the simulation of transient behaviour of simple pendulum and to create animation of its motion

FORMULAE:

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

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.

Simulate the motion between 0-20 sec, for angular displacement=0,angular velocity=3 rad/sec at time t=0

CODE FOR SIMULATION OF TRANSIENT BEHAVIOUR OF SIMPLE PENDULUM:

#solving 2nd order ode using python
import matplotlib.pyplot as plt
import math 
import numpy as np
from scipy.integrate import odeint
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
b =0.02
g =9.81
l =1
m =0.1
theta_0 = [0,3]
t= np.linspace(0,20,150)
theta = odeint(model,theta_0,t, args=(b,g,l,m))
ct=1
for theta in theta[:,0]:
	x0=0
	y0=0
	x1=l*math.sin(theta)
	y1 =-l*math.cos(theta)
	plt.figure()
	plt.xlim([-1.5,1.5])
	plt.ylim([-1.5,1.5])
	plt.plot([-0.5,0.5],[0,0])
	plt.plot([0,x1],[0,y1])
	plt.plot(x1,y1,marker=\'o\',markersize=30)
	plt.savefig(str(ct)+\'.png\')
	ct=ct+1
	

EXPLANATION OF CODE:

  • import all the required libraries using import function
  • Goto command prompt window and type \"python -m pip install scipy\"then it install a module that is required to solve ODE using odeint
  • Use numpy module to assign huge number of values within limits
  • define a function using def and assign the values to the function
  • theta[0] and theta[1] are values assosiated with angular displacement and angular velocity
  • split the given 2nd order ODE to two single order ODE
  • Return the value
  • Assign values to the theta_0 and also assign values to the time
  • Using for loop claculate the values of displacement for every interval and make a plot
  • Set the limits for x_axis and y-axis to get visible display of motion
  • Locate the positions of start and end of pendulum and make a ball at the end of pendulum of size 20mm
  • Set the number to the images and save it in png mode

COMMANDS USED IN CODE:

matplotlib -> matplotlib is an amazing visualization library in python for 2D plots of arrays.This command is used to plot graphs using the code
plt.figure() -> This command is used to display the multiple graphs at a time side by side to compare results
plt.plot() -> This command is used to draw graphs according to their assigned values
plt.label() -> This command is used to label the axis to differentiate the values on the curves
plt.show() -> This command is used to display the results graphs on the screen as output
plt.savefig() -> This command is used to save the output images in particular folder
plt.lim() -> This command is used to set the limits of rotation of arm and manipulator
math -> This library is uesd when we use the trigonometric functions
str() -> This command is used to convert specified value to a string

numpy() -> This function is used to assign values of same common difference between two vaues

odeint() -> This function is used to slove for ODE

scipy -> This library supports for ODE
OUTPUT:

ANIMATION OF OSCILLATION OF PENDULUM

CONCLUSION:

  • Scripting a code for simulation of transient behaviour of simple pendulum
  • scripting is done to obtain colour for graph and getting mathematical equations
  • Identifying errors and rectify is done successfully
Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.