Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.54 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Wed Oct 16 09:26:54 2019
  4.  
  5. @author: student
  6. """
  7.  
  8. import numpy as np
  9. import matplotlib.pyplot as plt
  10. from scipy.integrate import odeint
  11. from matplotlib.animation import FuncAnimation
  12.  
  13. m1 = 100
  14. m2 = 100
  15. k01 = 50
  16. k12 = 50
  17. k23 = 50
  18. def F1(t):
  19.     return 10*np.sin(t)
  20. def F2(t):
  21.     return 10*np.cos(t)
  22. def D(X, t):
  23.     D1 = X [2]
  24.     D2 = X[3]
  25.     D3 = (1/m1)* (F1(t) - k01*X[0] - k12*(X[0] - X[1]))
  26.     D4 = (1/m2)* (F2(t) - k12*(X[1] - X[0]) - k23*X[1])
  27.     return np.array ([D1, D2, D3, D4])
  28. X0 = [0, 0,0,0]
  29. tstop = 20
  30. nt = 500
  31. T = np.linspace (0, tstop, nt)
  32. R = odeint (D, X0, T)
  33.  
  34. X1 = R[:,0]
  35. X2 = R[:,1]
  36. V1 = R[:,2]
  37. V2 = R[:,3]
  38.  
  39. plt.plot (T, X1, label ='pomak m1')
  40. plt.plot (T, X2, label ='pomak m2')
  41. plt.legend()
  42. plt.xlabel ('t[s]')
  43. plt.ylabel ('x[m]')
  44. plt.title ('rješenje')
  45.  
  46. plt.figure ()
  47. plt.plot (X1, V1, label = 'm1')
  48. plt.plot (X2, V2, label ='m2')
  49. plt.legend()
  50. plt.xlabel ('x[m]')
  51. plt.ylabel ('v[m/s]')
  52.  
  53. sl = plt.figure ()
  54. l01 = 100/k01
  55. l12 = 100/k12
  56. l23 = 100/k23
  57. def scena (i):
  58.     sl.clf()
  59.     x0 = 0
  60.     x1 = x0 + l01 + X1 [i]
  61.     x2 = x1 + l12 + X2[i]
  62.     x3 = l01 + l12 + l23
  63.     plt.plot ([x0,x1,x2,x3],
  64.               np.zeros(4), 'o-',ms=10)
  65.     plt.arrow (x1, 0, 0.1*F1(T[i]), 0,
  66.               width = 0.02)
  67.    
  68.     plt.arrow (x2, 0, 0.1*F2(T[i]), 0,
  69.               width = 0.02, overhang = 10)
  70.     plt.xlim([x0,x3])
  71.     plt.title(f't = {np.round(T[i], 2)}s')
  72. a = FuncAnimation (sl, scena, frames=np.size(T))
  73. a.save ('sustavmk.avi', fps =nt/tstop)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement