Week 3 - Solving second order ODEs
Aim:
The aim is to solve the simple pendullum, with the following criteria,
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.
Procedure:
In this L = length,
m = mass in kg,
b = damping coefficient,
g = gravity,
import math
import numpy as n1
import matplotlib.pyplot as plt
from scipy.integrate import odeint
def model(initial,t,b,l,g,m):
t1 = initial[0]
t2 = initial[1]
dt1=t2
dt2=(-b* t2/m)-(g * math.sin(t1)/l)
dt=[dt1,dt2]
return dt
b = 0.05
l = 1
g = 9.81
m = 1
initial=[0,3]
t = n1.linspace(0, 20, 200)
disvelo=odeint(model, initial,t,args=(b,1,g,m))
plt.plot(t,disvelo [:,0],'-', label='displacement')
plt.plot(t,disvelo[:,1], '--', label='velocity')
plt.legend()
plt.xlabel('time')
plt.ylabel('displacement velocity')
plt.show()
y=disvelo [:,0]
ct = 1
for ang in y:
x1 = 0; y1 = 0
x2=l * math.sin(ang)
y2=l * math.cos(ang)
file='test\%o5d.png'%ct
plt.figure()
plt.plot ([-1.5, 1.5], [0,0], linewidth = 8)
plt.plot([x1,x2], [y1,y2], linewidth=3)
plt.plot(x2,y2, 'o',markersize=15)
plt.xlim([-1.5,1.5])
plt.ylim([-1.5,1.5])
plt.savefig(file)
ct = ct + 1


Result :
The code has been completed successfully and the result has been added, the video has been uploaded in the assest.
