Week 3 - Solving second order ODEs
REPORT ON TRASIENT BEHAVIOR OF SIMPLE PANDULUM
Created by Shahbaaz khan Deoda
On 17 may 2020
AIM: - To simulate the transient behavior of pendulum.
GOVERNING EQUATION: -
Simple harmonic motion is followed by pendulum oscillation of second order.
OBJECTIVE: - To draw the animation and code the program.
PROGRAM BODY: -
import numpy as np
from scipy.integrate import odeint
import matplotlib.pyplot as plt
import math
# function that return the the value of thata array
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.05
g = 9.81
l = 1
m = 0.1
#initial condition
theta_0 = [0,3]
#time array
t = np.linspace(0,20,300)
#solve ode
theta = odeint(model,theta_0,t,args = (b,g,l,m))
"""
#plot results
plt.plot(t,theta[:,0],'b-',label=r'displacement')
plt.plot(t,theta[:,1],'r--',label=r'velocity')
plt.ylabel('plot')
plt.xlabel('time')
plt.legend()
plt.show()"""
#animation
x0 = 0
y0 = 0
ct = 1
for i in range(0,300):
s = theta[i,0]
x1 = l*math.sin(s)
y1 = -l*math.cos(s)
filename = str(ct) + '.png'
ct = ct + 1
# plot
plt.figure()
plt.plot([x0,x1],[y0,y1],color='b',lw=3)
plt.plot([-0.6,0.6],[y0,y0],color='g',lw=3)
plt.plot([x1],[y1],'o',markersize=20,color='r')
plt.xlim([-1.2,1])
plt.ylim([-1.2,0.2])
plt.savefig(filename)
plt.show()
CONCLUSION: - we have successfully coded the program.