Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,40 +1,34 @@
|
|
1 |
import streamlit as st
|
2 |
import numpy as np
|
3 |
-
import
|
4 |
-
from mpl_toolkits.mplot3d import Axes3D
|
5 |
|
6 |
-
|
7 |
-
t = np.linspace(0, 2*np.pi, 100)
|
8 |
|
9 |
-
#
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
|
|
|
|
16 |
|
17 |
# Calculate the electric and magnetic fields
|
18 |
-
|
19 |
-
|
20 |
-
e_z = np.zeros_like(e_x)
|
21 |
-
|
22 |
-
b_x = np.zeros_like(e_x)
|
23 |
-
b_y = amp_b * np.cos(freq*t)
|
24 |
-
b_z = np.zeros_like(e_x)
|
25 |
|
26 |
-
#
|
27 |
-
fig =
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
ax.view_init(elev=30, azim=120)
|
38 |
|
39 |
-
# Display the plot
|
40 |
-
st.
|
|
|
1 |
import streamlit as st
|
2 |
import numpy as np
|
3 |
+
import plotly.graph_objs as go
|
|
|
4 |
|
5 |
+
st.title("Electromagnetic Wave Simulation")
|
|
|
6 |
|
7 |
+
# Set up initial values
|
8 |
+
c = 3e8 # Speed of light (m/s)
|
9 |
+
lambda_ = 1e-9 # Wavelength (m)
|
10 |
+
omega = 2 * np.pi * c / lambda_ # Angular frequency
|
11 |
+
k = omega / c # Wave number
|
12 |
+
E0 = 1 # Amplitude of electric field
|
13 |
+
B0 = E0 / c # Amplitude of magnetic field
|
14 |
+
t = np.linspace(0, 1e-14, 1000) # Time (s)
|
15 |
+
z = np.linspace(0, 1e-6, 100) # Position (m)
|
16 |
|
17 |
# Calculate the electric and magnetic fields
|
18 |
+
E = E0 * np.sin(k * z - omega * t[:, np.newaxis])
|
19 |
+
B = B0 * np.sin(k * z - omega * t[:, np.newaxis])
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
+
# Create a 3D surface plot
|
22 |
+
fig = go.Figure(
|
23 |
+
go.Surface(x=z, y=t, z=E.T, colorscale='Blues', showscale=False, name="Electric Field"),
|
24 |
+
go.Surface(x=z, y=t, z=B.T, colorscale='Reds', showscale=False, name="Magnetic Field"),
|
25 |
+
)
|
26 |
+
fig.update_layout(
|
27 |
+
title="Electromagnetic Wave Simulation",
|
28 |
+
scene=dict(xaxis_title="Position (m)", yaxis_title="Time (s)", zaxis_title="Field Strength"),
|
29 |
+
margin=dict(l=0, r=0, b=0, t=40),
|
30 |
+
height=700,
|
31 |
+
)
|
|
|
32 |
|
33 |
+
# Display the plot
|
34 |
+
st.plotly_chart(fig, use_container_width=True)
|