Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +54 -39
src/streamlit_app.py
CHANGED
|
@@ -1,40 +1,55 @@
|
|
| 1 |
-
import altair as alt
|
| 2 |
-
import numpy as np
|
| 3 |
-
import pandas as pd
|
| 4 |
import streamlit as st
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import numpy as np
|
| 3 |
+
import matplotlib.pyplot as plt
|
| 4 |
+
|
| 5 |
+
# Sidebar inputs
|
| 6 |
+
st.sidebar.header("Function Parameters")
|
| 7 |
+
a_0 = st.sidebar.slider("Amplitude of Sine (a₀)", -5.0, 5.0, 1.0, 0.1)
|
| 8 |
+
omega = st.sidebar.slider("Frequency of Sine (ω)", 0.1, 10.0, 1.0, 0.1)
|
| 9 |
+
b_0 = st.sidebar.slider("Initial value of Exp (b₀)", -5.0, 5.0, 1.0, 0.1)
|
| 10 |
+
alpha = st.sidebar.slider("Exponent Coefficient (α)", -5.0, 5.0, 0.5, 0.1)
|
| 11 |
+
|
| 12 |
+
# Main title
|
| 13 |
+
st.title("Damped/undamped vibration characteristic visualiser")
|
| 14 |
+
|
| 15 |
+
# Time vector
|
| 16 |
+
t = np.linspace(0, 10, 1000)
|
| 17 |
+
|
| 18 |
+
# Functions
|
| 19 |
+
y_sin = a_0 * np.sin(omega * t)
|
| 20 |
+
y_exp = b_0 * np.exp(alpha * t)
|
| 21 |
+
y_combined = y_sin * y_exp
|
| 22 |
+
|
| 23 |
+
# Plotting setup
|
| 24 |
+
fig1, ax1 = plt.subplots()
|
| 25 |
+
ax1.plot(t, y_sin, label=r'$a_0 \sin(\omega t)$', color='tab:blue')
|
| 26 |
+
ax1.set_title("Sine Function", fontsize=14)
|
| 27 |
+
ax1.set_xlabel("Time (t)", fontsize=12)
|
| 28 |
+
ax1.set_ylabel("Amplitude", fontsize=12)
|
| 29 |
+
ax1.grid(True)
|
| 30 |
+
ax1.legend()
|
| 31 |
+
|
| 32 |
+
fig2, ax2 = plt.subplots()
|
| 33 |
+
ax2.plot(t, y_exp, label=r'$b_0 e^{\alpha t}$', color='tab:green')
|
| 34 |
+
ax2.set_title("Exponential Function", fontsize=14)
|
| 35 |
+
ax2.set_xlabel("Time (t)", fontsize=12)
|
| 36 |
+
ax2.set_ylabel("Amplitude", fontsize=12)
|
| 37 |
+
ax2.grid(True)
|
| 38 |
+
ax2.legend()
|
| 39 |
+
|
| 40 |
+
fig3, ax3 = plt.subplots()
|
| 41 |
+
ax3.plot(t, y_combined, label=r'$a_0 \sin(\omega t) \cdot b_0 e^{\alpha t}$', color='tab:red')
|
| 42 |
+
ax3.set_title("Combined Function: Sine × Exponential", fontsize=14)
|
| 43 |
+
ax3.set_xlabel("Time (t)", fontsize=12)
|
| 44 |
+
ax3.set_ylabel("Amplitude", fontsize=12)
|
| 45 |
+
ax3.grid(True)
|
| 46 |
+
ax3.legend()
|
| 47 |
+
|
| 48 |
+
# Display plots in layout
|
| 49 |
+
col1, col2 = st.columns(2)
|
| 50 |
+
with col1:
|
| 51 |
+
st.pyplot(fig1)
|
| 52 |
+
with col2:
|
| 53 |
+
st.pyplot(fig2)
|
| 54 |
+
|
| 55 |
+
st.pyplot(fig3)
|