Spaces:
Runtime error
Runtime error
Create simluation.py
Browse files12345678910111213141516171819202122232425262728293031323334353637383940import streamlit as stimport numpy as npimport matplotlib.pyplot as pltfrom mpl_toolkits.mplot3d import Axes3D
# Define the time variablet = np.linspace(0, 2*np.pi, 100)
# Create a meshgrid for the x and y axesx, y = np.meshgrid(np.linspace(-1, 1, 100), np.linspace(-1, 1, 100))
# Define the amplitudes and frequencies of the wavesamp_e = st.sidebar.slider('Amplitude of Electric Field', min_value=0.0, max_value=1.0, value=0.5, step=0.1)amp_b = st.sidebar.slider('Amplitude of Magnetic Field', min_value=0.0, max_value=1.0, value=0.5, step=0.1)freq = st.sidebar.slider('Frequency of Waves', min_value=1, max_value=10, value=5, step=1)
# Calculate the electric and magnetic fieldse_x = amp_e * np.cos(freq*t)e_y = np.zeros_like(e_x)e_z = np.zeros_like(e_x)
b_x = np.zeros_like(e_x)b_y = amp_b * np.cos(freq*t)b_z = np.zeros_like(e_x)
# Plot the electric and magnetic fieldsfig = plt.figure(figsize=(10, 6))ax = fig.add_subplot(111, projection='3d')ax.quiver(x, y, np.zeros_like(x), e_x, e_y, e_z, length=0.1, color='r')ax.quiver(x, y, np.zeros_like(x), b_x, b_y, b_z, length=0.1, color='b')ax.set_xlim(-1, 1)ax.set_ylim(-1, 1)ax.set_zlim(-1, 1)ax.set_xlabel('X')ax.set_ylabel('Y')ax.set_zlabel('Z')ax.view_init(elev=30, azim=120)
# Display the plot in Streamlitst.pyplot(fig)simluation.pyAdded+40