Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
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 |
-
|
41 |
-
ax.
|
42 |
-
ax.
|
43 |
-
|
44 |
-
ax.
|
45 |
-
|
|
|
|
|
|
|
|
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)
|