Advertisement
ivodevweb

Untitled

Jan 18th, 2023
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.97 KB | None | 0 0
  1. import streamlit as st
  2. import matplotlib.pyplot as plt
  3. import pandas as pd
  4. import math
  5.  
  6. st.set_option('deprecation.showPyplotGlobalUse', False)
  7. st.header("EfolioB de Fisica")
  8. st.title("Simulador Grafico de um Pendulo ")
  9.  
  10. st.sidebar.title("Valores a Simular:")
  11. M = st.sidebar.slider("Massa da esfera (g)", 1.0, 10.0, 2.6)
  12. L = st.sidebar.slider("Comprimento do fio (m)", 0.5, 3.0, 1.0)
  13. R = st.sidebar.slider("Raio da esfera (cm)", 1.0, 20.0, 30.0)
  14.  
  15. # M = st.slider("Massa da esfera (g)", 1.0, 10.0, 2.6)
  16. # L = st.slider("Comprimento do fio (m)", 0.5, 3.0, 1.0)
  17. # R = st.slider("Raio da esfera (cm)", 1.0, 20.0, 30.0)
  18.  
  19. def run_simulation():
  20.     # constants
  21.     ra = R/100
  22.     cd = 0.1
  23.     rho = 1.28
  24.     g = 9.81
  25.     m = M/1000
  26.  
  27.     A = math.pi * ra**2
  28.     b = 1/2 * rho * cd * A
  29.    
  30.     theta0 = 0.05
  31.     w0 = 0.0
  32.     t0 = 0.0
  33.     h = 0.1
  34.     t = [t0]
  35.     theta = [theta0]
  36.     w = [w0]
  37.     k1x = 0
  38.     k1v = 0
  39.     k2x = 0
  40.     k2v = 0
  41.     while t[-1] < 100.0:
  42.         k1x = w[-1]
  43.         k1v = -math.copysign(1, w[-1]) * (((b*L)/m) * w[-1]**2) - (g / L) * theta[-1]
  44.         k2x = w[-1] + k1v * h
  45.         k2v = -math.copysign(1, w[-1] + k1v * h) * (((b*L)/m )* (w[-1] + k1v * h)**2) - (g / L) * (theta[-1] + k1x * h)
  46.         theta.append(theta[-1] + ((k1x + k2x) / 2.0)*h)
  47.         w.append(w[-1] + ((k1v + k2v) / 2.0)*h)
  48.         t.append(t[-1] + h)
  49.     fig, ax = plt.subplots()
  50.     ax.plot(t, theta, 'r')
  51.     ax.plot(t, w, 'b')
  52.     ax.legend(['Theta', 'w'])
  53.     ax.set_xlabel('time (s)')
  54.     ax.set_ylabel('Theta (rad), w (rad/s)')
  55.    
  56.     # Crie um dataframe das listas t, theta e w
  57.     df = pd.DataFrame({'t (s)': t, 'theta (rad)': theta, 'w (rad/s)': w, 'k1x': k1x, 'k1v': k1v, 'k2x': k2x, 'k2v': k2v})
  58.  
  59.     # Exibir o grafico
  60.     st.pyplot(fig)
  61.    
  62.     # Exibir as primeiras linhas do dataframe
  63.     st.title("Tabela ")
  64.     st.write(df)
  65. if st.button("Simular Grafico"):
  66.     run_simulation()
  67.    
  68.     st.text(" Realizado por: Ivo Baptista  ")
  69.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement