vibrations-1 / src /streamlit_app.py
bhajay's picture
Update src/streamlit_app.py
acd6674 verified
import streamlit as st
import numpy as np
import matplotlib.pyplot as plt
# Sidebar inputs
st.sidebar.header("Function Parameters")
a_0 = st.sidebar.slider("Amplitude of Sine (a₀)", -5.0, 5.0, 1.0, 0.1)
omega = st.sidebar.slider("Frequency of Sine (ω)", 0.1, 10.0, 1.0, 0.1)
b_0 = st.sidebar.slider("Initial value of Exp (b₀)", -5.0, 5.0, 1.0, 0.1)
alpha = st.sidebar.slider("Exponent Coefficient (α)", -5.0, 5.0, 0.5, 0.1)
# Main title
st.title("Damped/undamped vibration characteristic visualiser")
# Time vector
t = np.linspace(0, 10, 1000)
# Functions
y_sin = a_0 * np.sin(omega * t)
y_exp = b_0 * np.exp(alpha * t)
y_combined = y_sin * y_exp
# Plotting setup
fig1, ax1 = plt.subplots()
ax1.plot(t, y_sin, label=r'$a_0 \sin(\omega t)$', color='tab:blue')
ax1.set_title("Sine Function", fontsize=14)
ax1.set_xlabel("Time (t)", fontsize=12)
ax1.set_ylabel("Amplitude", fontsize=12)
ax1.grid(True)
ax1.legend()
fig2, ax2 = plt.subplots()
ax2.plot(t, y_exp, label=r'$b_0 e^{\alpha t}$', color='tab:green')
ax2.set_title("Exponential Function", fontsize=14)
ax2.set_xlabel("Time (t)", fontsize=12)
ax2.set_ylabel("Amplitude", fontsize=12)
ax2.grid(True)
ax2.legend()
fig3, ax3 = plt.subplots()
ax3.plot(t, y_combined, label=r'$a_0 \sin(\omega t) \cdot b_0 e^{\alpha t}$', color='tab:red')
ax3.set_title("Combined Function: Sine × Exponential", fontsize=14)
ax3.set_xlabel("Time (t)", fontsize=12)
ax3.set_ylabel("Amplitude", fontsize=12)
ax3.grid(True)
ax3.legend()
# Display plots in layout
col1, col2 = st.columns(2)
with col1:
st.pyplot(fig1)
with col2:
st.pyplot(fig2)
st.pyplot(fig3)