import numpy as np
from scipy.integrate import odeint
import matplotlib.pyplot as plt
import math
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,5]
t = np.linspace(0,10,150)
theta = odeint(model,theta_0,t,args = (b,g,l,m))
plt.plot(t,theta[:,0])
plt.plot(t,theta[:,1])
plt.ylabel('plot')
plt.xlabel('time')
plt.legend()
plt.show()
ct = 1
for i in theta[:,0]:
x0 = 0
y0 = 0
x3 = -1.5
y3 = 0
x4 = 1.5
y4 = 0
x1 = l*math.sin(i)
y1 = -l*math.cos(i)
filename = str(ct)+'.png'
ct = ct +1
plt.figure()
plt.plot([x3,x4],[y3,y4])
plt.plot([x0,x1],[y0,y1],x1,y1,'o',markersize=20,color='red')
plt.xlim([-2,2])
plt.ylim([-2,2])
plt.title('oscillating pendulum')
plt.savefig(filename)