VIATEUR-AI commited on
Commit
62a0351
·
verified ·
1 Parent(s): 1686f97

import streamlit as st import numpy as np import sympy as sp import matplotlib.pyplot as plt from sympy.plotting import plot from sympy import symbols, sin, cos, tan st.set_page_config(page_title="VMathLab Ultimate", layout="wide") st.title("VMathLab Ultimate 2.0: Complete Interactive Math Lab") # Sidebar: Module selection module = st.sidebar.selectbox("Hitamo Module:", [ "Algebra", "Calculus", "Trigonometry", "Linear Algebra", "Statistics", "Differential Equations", "Graphing", "Number Theory" ]) x = symbols('x') # --------------------- Algebra --------------------- if module == "Algebra": st.header("Algebra Module") eq_input = st.text_input("Shyiramo equation (urugero: x**2 - 5*x + 6):") if eq_input: try: expr = sp.sympify(eq_input) solutions = sp.solve(expr, x) st.write(f"Solutions: {solutions}") except: st.error("Error: Enter a valid algebraic expression.") # --------------------- Calculus --------------------- elif module == "Calculus": st.header("Calculus Module") func_input = st.text_input("Shyiramo function (urugero: x**3 - 2*x + 1):") if func_input: try: func = sp.sympify(func_input) st.write(f"Derivative: {sp.diff(func, x)}") st.write(f"Integral: {sp.integrate(func, x)} + C") except: st.error("Error: Enter a valid function.") # --------------------- Trigonometry --------------------- elif module == "Trigonometry": st.header("Trigonometry Module") trig_func = st.selectbox("Hitamo function:", ["sin(x)", "cos(x)", "tan(x)"]) x_vals = np.linspace(-2*np.pi, 2*np.pi, 400) if trig_func == "sin(x)": y_vals = np.sin(x_vals) elif trig_func == "cos(x)": y_vals = np.cos(x_vals) else: y_vals = np.tan(x_vals) fig, ax = plt.subplots() ax.plot(x_vals, y_vals, label=trig_func) ax.set_title(f"{trig_func} plot") ax.grid(True) st.pyplot(fig) # --------------------- Linear Algebra --------------------- elif module == "Linear Algebra": st.header("Linear Algebra Module") st.write("Matrix Calculator") matrix_input = st.text_area("Shyiramo matrix (urugero: [[1,2],[3,4]]):") if matrix_input: try: mat = np.array(eval(matrix_input)) st.write("Determinant:", np.linalg.det(mat)) st.write("Inverse (if exists):", np.linalg.inv(mat)) except: st.error("Invalid matrix input.") # --------------------- Statistics --------------------- elif module == "Statistics": st.header("Statistics Module") data_input = st.text_area("Shyiramo data (urugero: 1,2,3,4,5):") if data_input: try: data = np.array([float(i) for i in data_input.split(",")]) st.write("Mean:", np.mean(data)) st.write("Median:", np.median(data)) st.write("Variance:", np.var(data)) except: st.error("Invalid data input.") # --------------------- Differential Equations --------------------- elif module == "Differential Equations": st.header("Differential Equations Module") de_input = st.text_input("Shyiramo DE (urugero: f(x).diff(x) - f(x) = 0):") f = sp.Function('f') if de_input: try: de = eval(de_input) sol = sp.dsolve(de) st.write("Solution:", sol) except: st.error("Invalid differential equation.") # --------------------- Graphing --------------------- elif module == "Graphing": st.header("Graphing Module") func_input = st.text_input("Shyiramo function y(x):") x_min = st.number_input("X min", value=-10.0) x_max = st.number_input("X max", value=10.0) color = st.color_picker("Graph Color", "#FF0000") if func_input: try: x_vals = np.linspace(x_min, x_max, 400) f = sp.lambdify(x, sp.sympify(func_input), "numpy") y_vals = f(x_vals) fig, ax = plt.subplots() ax.plot(x_vals, y_vals, color=color, label=func_input) ax.axhline(0, color='black', linewidth=0.7) ax.axvline(0, color='black', linewidth=0.7) ax.grid(True) ax.legend() st.pyplot(fig) except: st.error("Enter a valid function.") # --------------------- Number Theory --------------------- elif module == "Number Theory": st.header("Number Theory Module") num = st.number_input("Shyiramo integer:", step=1) if num: try: def is_prime(n): if n < 2: return False for i in range(2,int(n**0.5)+1): if n % i == 0: return False return True st.write(f"Prime: {is_prime(num)}") st.write("Factors:", [i for i in range(1,num+1) if num % i == 0]) except: st.error("Invalid input.")

Browse files
Files changed (1) hide show
  1. app.py +135 -0
app.py CHANGED
@@ -0,0 +1,135 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import numpy as np
3
+ import sympy as sp
4
+ import matplotlib.pyplot as plt
5
+ from sympy.plotting import plot
6
+ from sympy import symbols, sin, cos, tan
7
+
8
+ st.set_page_config(page_title="VMathLab Ultimate", layout="wide")
9
+ st.title("VMathLab Ultimate 2.0: Complete Interactive Math Lab")
10
+
11
+ # Sidebar: Module selection
12
+ module = st.sidebar.selectbox("Hitamo Module:", [
13
+ "Algebra", "Calculus", "Trigonometry",
14
+ "Linear Algebra", "Statistics", "Differential Equations", "Graphing", "Number Theory"
15
+ ])
16
+
17
+ x = symbols('x')
18
+
19
+ # --------------------- Algebra ---------------------
20
+ if module == "Algebra":
21
+ st.header("Algebra Module")
22
+ eq_input = st.text_input("Shyiramo equation (urugero: x**2 - 5*x + 6):")
23
+ if eq_input:
24
+ try:
25
+ expr = sp.sympify(eq_input)
26
+ solutions = sp.solve(expr, x)
27
+ st.write(f"Solutions: {solutions}")
28
+ except:
29
+ st.error("Error: Enter a valid algebraic expression.")
30
+
31
+ # --------------------- Calculus ---------------------
32
+ elif module == "Calculus":
33
+ st.header("Calculus Module")
34
+ func_input = st.text_input("Shyiramo function (urugero: x**3 - 2*x + 1):")
35
+ if func_input:
36
+ try:
37
+ func = sp.sympify(func_input)
38
+ st.write(f"Derivative: {sp.diff(func, x)}")
39
+ st.write(f"Integral: {sp.integrate(func, x)} + C")
40
+ except:
41
+ st.error("Error: Enter a valid function.")
42
+
43
+ # --------------------- Trigonometry ---------------------
44
+ elif module == "Trigonometry":
45
+ st.header("Trigonometry Module")
46
+ trig_func = st.selectbox("Hitamo function:", ["sin(x)", "cos(x)", "tan(x)"])
47
+ x_vals = np.linspace(-2*np.pi, 2*np.pi, 400)
48
+ if trig_func == "sin(x)":
49
+ y_vals = np.sin(x_vals)
50
+ elif trig_func == "cos(x)":
51
+ y_vals = np.cos(x_vals)
52
+ else:
53
+ y_vals = np.tan(x_vals)
54
+ fig, ax = plt.subplots()
55
+ ax.plot(x_vals, y_vals, label=trig_func)
56
+ ax.set_title(f"{trig_func} plot")
57
+ ax.grid(True)
58
+ st.pyplot(fig)
59
+
60
+ # --------------------- Linear Algebra ---------------------
61
+ elif module == "Linear Algebra":
62
+ st.header("Linear Algebra Module")
63
+ st.write("Matrix Calculator")
64
+ matrix_input = st.text_area("Shyiramo matrix (urugero: [[1,2],[3,4]]):")
65
+ if matrix_input:
66
+ try:
67
+ mat = np.array(eval(matrix_input))
68
+ st.write("Determinant:", np.linalg.det(mat))
69
+ st.write("Inverse (if exists):", np.linalg.inv(mat))
70
+ except:
71
+ st.error("Invalid matrix input.")
72
+
73
+ # --------------------- Statistics ---------------------
74
+ elif module == "Statistics":
75
+ st.header("Statistics Module")
76
+ data_input = st.text_area("Shyiramo data (urugero: 1,2,3,4,5):")
77
+ if data_input:
78
+ try:
79
+ data = np.array([float(i) for i in data_input.split(",")])
80
+ st.write("Mean:", np.mean(data))
81
+ st.write("Median:", np.median(data))
82
+ st.write("Variance:", np.var(data))
83
+ except:
84
+ st.error("Invalid data input.")
85
+
86
+ # --------------------- Differential Equations ---------------------
87
+ elif module == "Differential Equations":
88
+ st.header("Differential Equations Module")
89
+ de_input = st.text_input("Shyiramo DE (urugero: f(x).diff(x) - f(x) = 0):")
90
+ f = sp.Function('f')
91
+ if de_input:
92
+ try:
93
+ de = eval(de_input)
94
+ sol = sp.dsolve(de)
95
+ st.write("Solution:", sol)
96
+ except:
97
+ st.error("Invalid differential equation.")
98
+
99
+ # --------------------- Graphing ---------------------
100
+ elif module == "Graphing":
101
+ st.header("Graphing Module")
102
+ func_input = st.text_input("Shyiramo function y(x):")
103
+ x_min = st.number_input("X min", value=-10.0)
104
+ x_max = st.number_input("X max", value=10.0)
105
+ color = st.color_picker("Graph Color", "#FF0000")
106
+ if func_input:
107
+ try:
108
+ x_vals = np.linspace(x_min, x_max, 400)
109
+ f = sp.lambdify(x, sp.sympify(func_input), "numpy")
110
+ y_vals = f(x_vals)
111
+ fig, ax = plt.subplots()
112
+ ax.plot(x_vals, y_vals, color=color, label=func_input)
113
+ ax.axhline(0, color='black', linewidth=0.7)
114
+ ax.axvline(0, color='black', linewidth=0.7)
115
+ ax.grid(True)
116
+ ax.legend()
117
+ st.pyplot(fig)
118
+ except:
119
+ st.error("Enter a valid function.")
120
+
121
+ # --------------------- Number Theory ---------------------
122
+ elif module == "Number Theory":
123
+ st.header("Number Theory Module")
124
+ num = st.number_input("Shyiramo integer:", step=1)
125
+ if num:
126
+ try:
127
+ def is_prime(n):
128
+ if n < 2: return False
129
+ for i in range(2,int(n**0.5)+1):
130
+ if n % i == 0: return False
131
+ return True
132
+ st.write(f"Prime: {is_prime(num)}")
133
+ st.write("Factors:", [i for i in range(1,num+1) if num % i == 0])
134
+ except:
135
+ st.error("Invalid input.")