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)
- 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
- k1x = [k1x_] * len(t)
- k1v = [k1v_] * len(t)
- k2x = [k2x_] * len(t)
- k2v = [k2v_] * len(t)
- 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)
- #append the new values to the k1x, k1v, k2x, k2v arrays
- k1x.append(k1x_)
- k1v.append(k1v_)
- k2x.append(k2x_)
- k2v.append(k2v_)
- fig, ax = plt.subplots()
- ax.plot(t, theta, 'r')
- ax.plot(t, w, 'b')
- ax.legend(['theta (rad)', 'w (rad/s)'])
- ax.set_xlabel('time (s)')
- ax.set_ylabel('Theta (rad), w (rad/s)')
- # Create a dataframe from the lists t, theta, w, k1x, k1v, k2x, k2v
- df = pd.DataFrame({'t (s)': t, 'theta (rad)': theta, 'w (rad/s)': w, 'k1x': k1x, 'k1v': k1v, 'k2x': k2x, 'k2v': k2v})
- # Show the plot
- st.pyplot(fig)
- # Show the first few rows of the 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