Kvikontent commited on
Commit
94391f0
·
verified ·
1 Parent(s): 1ad1c73

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -37
app.py CHANGED
@@ -6,40 +6,43 @@ st.title('Решение системы линейных уравнений')
6
 
7
  st.write('Введите уравнения в формате ax + by = c')
8
 
9
- equation1 = st.text_input('Уравнение 1:')
10
- equation2 = st.text_input('Уравнение 2:')
11
-
12
- def parse_equation(equation):
13
- parts = equation.split('=')
14
- coef = parts[0].split('x')
15
- a = float(coef[0]) if coef[0] else 1
16
- b_str = coef[1].replace('y', '').replace('+', '').replace('-', '').strip()
17
- b = float(b_str) if b_str else 0
18
- c = float(parts[1])
19
- return a, b, c
20
-
21
- a1, b1, c1 = parse_equation(equation1)
22
- a2, b2, c2 = parse_equation(equation2)
23
-
24
- intersection = None
25
- if np.linalg.det([[a1, b1], [a2, b2]]) != 0:
26
- intersection = np.linalg.solve([[a1, b1], [a2, b2]], [c1, c2])
27
- else:
28
- st.write('Система уравнений вырожденная, решений бесконечно много или их нет')
29
-
30
- if intersection is not None:
31
- st.write(f'Координаты точки пересечения прямых: ({intersection[0]}, {intersection[1]})')
32
-
33
- x = np.linspace(-10, 10, 400)
34
- y1 = (c1 - a1*x) / b1
35
- y2 = (c2 - a2*x) / b2
36
-
37
- fig, ax = plt.subplots()
38
- ax.plot(x, y1, label='Уравнение 1')
39
- ax.plot(x, y2, label='Уравнение 2')
40
- if intersection is not None:
41
- ax.scatter(intersection[0], intersection[1], color='red', label='Пересечение')
42
- ax.set_xlabel('x')
43
- ax.set_ylabel('y')
44
- ax.legend()
45
- st.pyplot(fig)
 
 
 
 
6
 
7
  st.write('Введите уравнения в формате ax + by = c')
8
 
9
+ equation1 = st.text_input('Уравнение 1:', '2x + y = 4')
10
+ equation2 = st.text_input('Уравнение 2:', 'x - y = 1')
11
+
12
+ solve_button = st.button('Решить')
13
+
14
+ if solve_button:
15
+ def parse_equation(equation):
16
+ parts = equation.split('=')
17
+ coef = parts[0].split('x')
18
+ a = float(coef[0]) if coef[0] else 1
19
+ b_str = coef[1].replace('y', '').replace('+', '').replace('-', '').strip()
20
+ b = float(b_str) if b_str else 0
21
+ c = float(parts[1])
22
+ return a, b, c
23
+
24
+ a1, b1, c1 = parse_equation(equation1)
25
+ a2, b2, c2 = parse_equation(equation2)
26
+
27
+ intersection = None
28
+ if np.linalg.det([[a1, b1], [a2, b2]]) != 0:
29
+ intersection = np.linalg.solve([[a1, b1], [a2, b2]], [c1, c2])
30
+ else:
31
+ st.write('Система уравнений вырожденная, решений бесконечно много или их нет')
32
+
33
+ if intersection is not None:
34
+ st.write(f'Координаты точки пересечения прямых: ({intersection[0]}, {intersection[1]})')
35
+
36
+ x = np.linspace(-10, 10, 400)
37
+ y1 = (c1 - a1 * x) / b1
38
+ y2 = (c2 - a2 * x) / b2
39
+
40
+ fig, ax = plt.subplots()
41
+ ax.plot(x, y1, label='Уравнение 1')
42
+ ax.plot(x, y2, label='Уравнение 2')
43
+ if intersection is not None:
44
+ ax.scatter(intersection[0], intersection[1], color='red', label='Пересечение')
45
+ ax.set_xlabel('x')
46
+ ax.set_ylabel('y')
47
+ ax.legend()
48
+ st.pyplot(fig)