File size: 1,041 Bytes
797ada8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
39
40
import streamlit as st
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

# Streamlit application
def app():
    st.title("Linear Equation Visualizer")

    # Input fields for the equation y = mx + c
    m = st.number_input("Enter the slope (m):", value=1.0)
    c = st.number_input("Enter the y-intercept (c):", value=0.0)
    x_value = st.number_input("Enter the x value to predict y:", value=0.0)

    # Calculating y based on the input
    y = m * x_value + c

    # Displaying the calculated y
    st.write(f"The calculated y value is: {y}")

    # Generating data for the line
    x = np.linspace(-10, 10, 100)
    y_line = m * x + c

    # Plotting the line
    plt.figure(figsize=(10, 6))
    plt.plot(x, y_line, '-r', label=f'y = {m}x + {c}')
    plt.scatter(x_value, y, color='blue', label='Predicted Point')
    plt.title("Graph of y = mx + c")
    plt.xlabel("x")
    plt.ylabel("y")
    plt.legend()
    plt.grid(True)
    
    # Displaying the plot
    st.pyplot(plt)

if __name__ == "__main__":
    app()