Update app.py
Browse files
app.py
CHANGED
@@ -1,31 +1,49 @@
|
|
1 |
-
|
2 |
-
import
|
3 |
-
from sympy import
|
4 |
-
|
5 |
-
|
6 |
-
st.
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from sympy import symbols, diff, integrate, simplify, sin, cos, tan, exp, log, pi
|
3 |
+
from sympy.parsing.sympy_parser import parse_expr
|
4 |
+
|
5 |
+
def main():
|
6 |
+
st.title("Math Solver: Derivatives, Integrals, and Trigonometry")
|
7 |
+
|
8 |
+
st.sidebar.header("Choose an Operation")
|
9 |
+
option = st.sidebar.radio("Select:", ("Derivative", "Integral", "Simplify Expression", "Trigonometric Evaluation"))
|
10 |
+
|
11 |
+
st.write("### Input your mathematical expression below")
|
12 |
+
|
13 |
+
user_input = st.text_input("Expression", "e.g., x**2 + 3*x + sin(x)")
|
14 |
+
variable = st.text_input("Variable (default is x)", "x")
|
15 |
+
|
16 |
+
if user_input:
|
17 |
+
try:
|
18 |
+
# Parse the user input
|
19 |
+
var = symbols(variable)
|
20 |
+
expression = parse_expr(user_input)
|
21 |
+
|
22 |
+
if option == "Derivative":
|
23 |
+
result = diff(expression, var)
|
24 |
+
st.write(f"The derivative of {expression} with respect to {variable} is:")
|
25 |
+
st.latex(f"{result}")
|
26 |
+
|
27 |
+
elif option == "Integral":
|
28 |
+
result = integrate(expression, var)
|
29 |
+
st.write(f"The integral of {expression} with respect to {variable} is:")
|
30 |
+
st.latex(f"{result}")
|
31 |
+
|
32 |
+
elif option == "Simplify Expression":
|
33 |
+
result = simplify(expression)
|
34 |
+
st.write(f"The simplified form of {expression} is:")
|
35 |
+
st.latex(f"{result}")
|
36 |
+
|
37 |
+
elif option == "Trigonometric Evaluation":
|
38 |
+
st.write("### Provide a value for the variable")
|
39 |
+
value = st.number_input(f"Value of {variable}")
|
40 |
+
|
41 |
+
evaluated_result = expression.subs(var, value)
|
42 |
+
st.write(f"The result of {expression} when {variable} = {value} is:")
|
43 |
+
st.latex(f"{evaluated_result}")
|
44 |
+
|
45 |
+
except Exception as e:
|
46 |
+
st.error(f"Error in processing the expression: {e}")
|
47 |
+
|
48 |
+
if __name__ == "__main__":
|
49 |
+
main()
|