Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import streamlit as st
- import matplotlib.pyplot as plt
- import pandas as pd
- import math
- st.set_option('deprecation.showPyplotGlobalUse', False)
- st.header("EfolioB de Fisica")
- st.title("Simulador Grafico de um Pendulo ")
- st.sidebar.title("Valores a Simular:")
- M = st.sidebar.slider("Massa da esfera (g)", 1.0, 10.0, 2.6)
- L = st.sidebar.slider("Comprimento do fio (m)", 0.5, 3.0, 1.0)
- R = st.sidebar.slider("Raio da esfera (cm)", 1.0, 20.0, 30.0)
- # M = st.slider("Massa da esfera (g)", 1.0, 10.0, 2.6)
- # L = st.slider("Comprimento do fio (m)", 0.5, 3.0, 1.0)
- # R = st.slider("Raio da esfera (cm)", 1.0, 20.0, 30.0)
- def run_simulation():
- # constants
- ra = R/100
- cd = 0.1
- rho = 1.28
- g = 9.81
- m = M/1000
- A = math.pi * ra**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]) * (((b*L)/m) * w[-1]**2) - (g / L) * theta[-1]
- k2x = w[-1] + k1v * h
- k2v = -math.copysign(1, w[-1] + k1v * h) * (((b*L)/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)
- fig, ax = plt.subplots()
- ax.plot(t, theta, 'r')
- ax.plot(t, w, 'b')
- ax.legend(['Theta', 'w'])
- ax.set_xlabel('time (s)')
- ax.set_ylabel('Theta (rad), w (rad/s)')
- # Crie um dataframe das listas t, theta e w
- df = pd.DataFrame({'t (s)': t, 'theta (rad)': theta, 'w (rad/s)': w, 'k1x': k1x, 'k1v': k1v, 'k2x': k2x, 'k2v': k2v})
- # Exibir o grafico
- st.pyplot(fig)
- # Exibir as primeiras linhas do dataframe
- st.title("Tabela ")
- st.write(df)
- if st.button("Simular Grafico"):
- run_simulation()
- st.text(" Realizado por: Ivo Baptista ")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement