File size: 1,208 Bytes
be1aee8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
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
import streamlit as st
import numpy as np
import matplotlib.pyplot as plt

st.title('Решение системы линейных уравнений')

st.write('Введите уравнения в формате ax + by = c')

equation1 = st.text_input('Уравнение 1:', '2x + y = 4')
equation2 = st.text_input('Уравнение 2:', 'x - y = 1')

def parse_equation(equation):
    parts = equation.split('=')
    coef = parts[0].split('x')
    a = float(coef[0]) if coef[0] else 1
    b = float(coef[1].replace('y', '').replace('+', '').replace('-', '').strip()) if 'y' in coef[1] else 0
    c = float(parts[1])
    return a, b, c

a1, b1, c1 = parse_equation(equation1)
a2, b2, c2 = parse_equation(equation2)

intersection = np.linalg.solve([[a1, b1], [a2, b2]], [c1, c2])

st.write(f'Координаты точки пересечения прямых: ({intersection[0]}, {intersection[1]})')

x = np.linspace(-10, 10, 400)
y1 = (c1 - a1*x) / b1
y2 = (c2 - a2*x) / b2

plt.figure()
plt.plot(x, y1, label='Equation 1')
plt.plot(x, y2, label='Equation 2')
plt.scatter(intersection[0], intersection[1], color='red', label='Intersection')
plt.xlabel('x')
plt.ylabel('y')
plt.legend()
st.pyplot()