Advertisement
ivodevweb

Untitled

Jan 17th, 2023
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.98 KB | Software | 0 0
  1. import streamlit as st
  2. import matplotlib.pyplot as plt
  3. import math
  4.  
  5. st.title("Simulação de esfera em queda livre")
  6.  
  7. m = st.slider("mass", 2.0, 3.0, 2.6)
  8. L = st.slider("length", 0.5, 2.0, 1.0)
  9.  
  10. def run_simulation():
  11.    
  12.  R = 0.03
  13. rho = 1.28
  14. g = 9.81
  15. cd = 0.1
  16. A = math.pi * R**2
  17. b = 1/2 * rho * cd * A
  18. theta0 = 0.05
  19. w0 = 0.0
  20. t0 = 0.0
  21. h = 0.1
  22. t = [t0]
  23. theta = [theta0]
  24. w = [w0]
  25. k1x = 0
  26. k1v = 0
  27. k2x = 0
  28. k2v = 0
  29. while t[-1] < 100.0:
  30.  k1x = w[-1]
  31.  k1v = -math.copysign(1, w[-1]) * (((bL)/m) * w[-1]**2) - (g / L) * theta[-1]
  32.  k2x = w[-1] + k1v * h
  33.  k2v = -math.copysign(1, w[-1] + k1v * h) * (((bL)/m )* (w[-1] + k1v * h)**2) - (g / L) * (theta[-1] + k1x * h)
  34. theta.append(theta[-1] + ((k1x + k2x) / 2.0)*h)
  35. w.append(w[-1] + ((k1v + k2v) / 2.0)*h)
  36. t.append(t[-1] + h)
  37. plt.plot(t, theta, 'r')
  38. plt.plot(t, w, 'b')
  39. plt.legend(['Theta', 'w'])
  40. plt.xlabel('time (s)')
  41. plt.ylabel('Theta (rad), w (rad/s)')
  42. st.pyplot()
  43.  
  44. if st.button("Run simulation"):
  45.  
  46.  run_simulation()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement