Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
1932 views
ubuntu2004
1
import numpy as np
2
import matplotlib.pyplot as plt
3
from scipy.integrate import odeint
4
5
M=5
6
m=2
7
g=9.81
8
9
def Atwood(y,t,M,m,g):
10
11
#theta'(t)=omega(t)
12
#radius'(t)=Rho(t)
13
14
#omega'(t)=(1/radius(t))(-g*sin(theta(t))-2(Rho(t)*omega(t))
15
#Rho'(t)=(1/(M+m))(m*radius(t)*(omega(t)^2)-M*g+m*g*cos(theta(t)))
16
17
theta, omega, radius, Rho = y
18
19
dydt = [omega, (1/radius)*(-g*(np.sin(theta))-2*(Rho*omega)), Rho, (1/(M+m))*(m*radius*(omega**2)-M*g+m*g*(np.cos(theta)))]
20
21
return dydt
22
23
#y0=[theta, change in theta, radius, change in radius]
24
y0 = [0 ,2 ,1 ,1]
25
#time points
26
t = np.linspace(0,10,101)
27
#Solving the ODE
28
sul = odeint(Atwood, y0, t, args=(M,m,g))
29
30
plt.plot(sul[:,0], sul[:,1], 'r', label='theta (x) vs theta dot (y)') #Phase plot
31
plt.legend(loc='best')
32
plt.grid()
33
plt.show()
34