Spaces:
Sleeping
Sleeping
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_str = coef[1].replace('y', '').replace('+', '').replace('-', '').strip() | |
b = float(b_str) if b_str 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() |