Advertisement
Andrey239

Untitled

Dec 12th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.70 KB | None | 0 0
  1. import numpy as np
  2. from scipy import integrate
  3. import math
  4. import matplotlib.pyplot as plt
  5. g = 9.81
  6. m = 1
  7. M = 10
  8. l = 10
  9.  
  10.  
  11. def u(t):
  12.     return 10
  13.  
  14.  
  15. def equation(y0, t):
  16.     r, theta, q, w = y0
  17.     return [q, w, r * w ** 2 - g * math.sin(theta),
  18.              (u(t) - 2 * m * r * q * w - m * g * r * math.cos(theta)) / (2 * M * l ** 2 + m * r ** 2)]
  19.  
  20.  
  21. y0 = [1, 0, 0, 0]
  22. t = np.linspace(0, 10, 10000)
  23. sol = integrate.odeint(equation, y0, t)
  24. plt.plot(t, sol[:, 0], 'b', label='r(t)')
  25. plt.plot(t, sol[:, 1], 'g', label='theta(t)')
  26. plt.plot(t, sol[:, 2], 'red', label='r_pr(t)')
  27. plt.plot(t, sol[:, 3], 'yellow', label='theta_pr(t)')
  28. plt.legend(loc='best')
  29. plt.xlabel('t')
  30. plt.grid()
  31. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement