DrTech commited on
Commit
24d6c12
·
verified ·
1 Parent(s): 3725e2a

Upload app3.py

Browse files
Files changed (1) hide show
  1. app3.py +65 -0
app3.py ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import numpy as np
3
+ from scipy.integrate import odeint
4
+ import plotly.graph_objects as go
5
+ import time
6
+ import pandas as pd
7
+
8
+ # Define the Lorenz system
9
+ def lorenz_system(current_state, t, sigma, rho, beta):
10
+ x, y, z = current_state
11
+ dx_dt = sigma * (y - x)
12
+ dy_dt = x * (rho - z) - y
13
+ dz_dt = x * y - beta * z
14
+ return [dx_dt, dy_dt, dz_dt]
15
+
16
+ # Set up the sidebar
17
+ st.sidebar.title('Lorenz System Parameters')
18
+ sigma = st.sidebar.slider('Sigma', 0.0, 50.0, 10.0)
19
+ rho = st.sidebar.slider('Rho', 0.0, 50.0, 28.0)
20
+ beta = st.sidebar.slider('Beta', 0.0, 50.0, 2.67)
21
+
22
+ x0_1 = st.sidebar.number_input('Initial x for 1st system', value=1.0)
23
+ y0_1 = st.sidebar.number_input('Initial y for 1st system', value=1.0)
24
+ z0_1 = st.sidebar.number_input('Initial z for 1st system', value=1.0)
25
+
26
+ x0_2 = st.sidebar.number_input('Initial x for 2nd system', value=1.0)
27
+ y0_2 = st.sidebar.number_input('Initial y for 2nd system', value=1.0)
28
+ z0_2 = st.sidebar.number_input('Initial z for 2nd system', value=1.0)
29
+
30
+ # Define the time points for the simulation
31
+ t = np.linspace(0, 4, 1000)
32
+
33
+ # Solve the Lorenz system
34
+ solution_1 = odeint(lorenz_system, (x0_1, y0_1, z0_1), t, args=(sigma, rho, beta))
35
+ solution_2 = odeint(lorenz_system, (x0_2, y0_2, z0_2), t, args=(sigma, rho, beta))
36
+
37
+ # Create a 3D plot of the solutions
38
+ plot_slot = st.empty()
39
+
40
+ stop = st.checkbox('Stop')
41
+
42
+ i = 0
43
+ while i < len(t) and not stop:
44
+ fig = go.Figure(data=[
45
+ go.Scatter3d(x=solution_1[:i, 0], y=solution_1[:i, 1], z=solution_1[:i, 2], mode='lines', line=dict(color='red'), name='System 1'),
46
+ go.Scatter3d(x=solution_2[:i, 0], y=solution_2[:i, 1], z=solution_2[:i, 2], mode='lines', line=dict(color='blue'), name='System 2')
47
+ ])
48
+
49
+ fig.update_layout(scene=dict(xaxis=dict(range=[min(min(solution_1[:, 0]), min(solution_2[:, 0])), max(max(solution_1[:, 0]), max(solution_2[:, 0]))]),
50
+ yaxis=dict(range=[min(min(solution_1[:, 1]), min(solution_2[:, 1])), max(max(solution_1[:, 1]), max(solution_2[:, 1]))]),
51
+ zaxis=dict(range=[min(min(solution_1[:, 2]), min(solution_2[:, 2])), max(max(solution_1[:, 2]), max(solution_2[:, 2]))]),
52
+ camera=dict(eye=dict(x=2*np.cos(i/10), y=2*np.sin(i/10), z=0.1))),
53
+ width=800, height=600)
54
+
55
+ plot_slot.plotly_chart(fig)
56
+
57
+ i += 1
58
+ time.sleep(0.2)
59
+
60
+ if st.button('Export Data'):
61
+ df_1 = pd.DataFrame(solution_1, columns=['x_1', 'y_1', 'z_1'])
62
+ df_2 = pd.DataFrame(solution_2, columns=['x_2', 'y_2', 'z_2'])
63
+ df_1.to_csv('lorenz_data_1.csv')
64
+ df_2.to_csv('lorenz_data_2.csv')
65
+ st.write('Data exported successfully!')