Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import streamlit as st
- import matplotlib.pyplot as plt
- import math
- st.title("Simulação de esfera em queda livre")
- m = st.slider("mass", 2.0, 3.0, 2.6)
- L = st.slider("length", 0.5, 2.0, 1.0)
- def run_simulation():
- R = 0.03
- rho = 1.28
- g = 9.81
- cd = 0.1
- A = math.pi * R**2
- b = 1/2 * rho * cd * A
- theta0 = 0.05
- w0 = 0.0
- t0 = 0.0
- h = 0.1
- t = [t0]
- theta = [theta0]
- w = [w0]
- k1x = 0
- k1v = 0
- k2x = 0
- k2v = 0
- while t[-1] < 100.0:
- k1x = w[-1]
- k1v = -math.copysign(1, w[-1]) * (((bL)/m) * w[-1]**2) - (g / L) * theta[-1]
- k2x = w[-1] + k1v * h
- k2v = -math.copysign(1, w[-1] + k1v * h) * (((bL)/m )* (w[-1] + k1v * h)**2) - (g / L) * (theta[-1] + k1x * h)
- theta.append(theta[-1] + ((k1x + k2x) / 2.0)*h)
- w.append(w[-1] + ((k1v + k2v) / 2.0)*h)
- t.append(t[-1] + h)
- plt.plot(t, theta, 'r')
- plt.plot(t, w, 'b')
- plt.legend(['Theta', 'w'])
- plt.xlabel('time (s)')
- plt.ylabel('Theta (rad), w (rad/s)')
- st.pyplot()
- if st.button("Run simulation"):
- run_simulation()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement