Advertisement
Artashes

Modeling1

Mar 8th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.47 KB | None | 0 0
  1. import matplotlib.pyplot as plt
  2. ans = 0
  3. h = 0.001
  4. g = 9.8
  5. k = 0.001
  6. v0 = 800
  7.  
  8.  
  9. def f(v):
  10.     return v - (g + k * v * v) * h
  11.  
  12.  
  13. t = [0]
  14. v = [v0]
  15.  
  16. while abs(v[-1]) > 0.005:
  17.     ans += v[-1] * h
  18.     t.append(t[-1] + h)
  19.     v.append(f(v[-1]))
  20.  
  21. tans = t[-1]
  22.  
  23. print("Высота: ", ans)
  24. print("Время:", tans)
  25.  
  26. fig, ax = plt.subplots(figsize=(5, 3))
  27. ax.plot(t, v, "g", linestyle='solid')
  28. ax.set_xlim(left=t[0], right=t[-1])
  29. fig.tight_layout()
  30. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement