Kvikontent commited on
Commit
be1aee8
·
verified ·
1 Parent(s): 83110a3

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -0
app.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import numpy as np
3
+ import matplotlib.pyplot as plt
4
+
5
+ st.title('Решение системы линейных уравнений')
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
+ 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 = float(coef[1].replace('y', '').replace('+', '').replace('-', '').strip()) if 'y' in coef[1] else 0
17
+ c = float(parts[1])
18
+ return a, b, c
19
+
20
+ a1, b1, c1 = parse_equation(equation1)
21
+ a2, b2, c2 = parse_equation(equation2)
22
+
23
+ intersection = np.linalg.solve([[a1, b1], [a2, b2]], [c1, c2])
24
+
25
+ st.write(f'Координаты точки пересечения прямых: ({intersection[0]}, {intersection[1]})')
26
+
27
+ x = np.linspace(-10, 10, 400)
28
+ y1 = (c1 - a1*x) / b1
29
+ y2 = (c2 - a2*x) / b2
30
+
31
+ plt.figure()
32
+ plt.plot(x, y1, label='Equation 1')
33
+ plt.plot(x, y2, label='Equation 2')
34
+ plt.scatter(intersection[0], intersection[1], color='red', label='Intersection')
35
+ plt.xlabel('x')
36
+ plt.ylabel('y')
37
+ plt.legend()
38
+ st.pyplot()