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:') equation2 = st.text_input('Уравнение 2:') solve_button = st.button('Решить') if solve_button: 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 = None if np.linalg.det([[a1, b1], [a2, b2]]) != 0: intersection = np.linalg.solve([[a1, b1], [a2, b2]], [c1, c2]) else: st.write('Система уравнений вырожденная, решений бесконечно много или их нет') if intersection is not None: st.write(f'Координаты точки пересечения прямых: ({intersection[0]}, {intersection[1]})') x = np.linspace(-10, 10, 400) y1 = (c1 - a1 * x) / b1 y2 = (c2 - a2 * x) / b2 fig, ax = plt.subplots() ax.plot(x, y1, label='Уравнение 1') ax.plot(x, y2, label='Уравнение 2') if intersection is not None: ax.scatter(intersection[0], intersection[1], color='red', label='Пересечение') ax.set_xlabel('x') ax.set_ylabel('y') ax.legend() st.pyplot(fig)