MuhammadHananKhan123 commited on
Commit
c61721b
·
verified ·
1 Parent(s): dc5a4f0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -31
app.py CHANGED
@@ -1,31 +1,49 @@
1
- # app.py
2
- import streamlit as st
3
- from sympy import symbols, diff, integrate, sympify
4
-
5
- # Page Configuration
6
- st.set_page_config(page_title="Derivation & Integration Solver", page_icon="🔢")
7
- st.title("Derivation & Integration Solver")
8
-
9
- # Input Section
10
- st.header("Input Equation")
11
- equation = st.text_input("Enter the equation (e.g., x**2 + 3*x + 5):", "")
12
- variable = st.text_input("Enter the variable (e.g., x):", "x")
13
-
14
- if equation and variable:
15
- try:
16
- # Convert input to sympy objects
17
- var = symbols(variable)
18
- expr = sympify(equation)
19
-
20
- # Derivative Section
21
- st.header("Derivative")
22
- derivative = diff(expr, var)
23
- st.latex(f"\\frac{{d}}{{d{variable}}}({equation}) = {derivative}")
24
-
25
- # Integration Section
26
- st.header("Integral")
27
- integral = integrate(expr, var)
28
- st.latex(f"\\int ({equation})\,d{variable} = {integral} + C")
29
-
30
- except Exception as e:
31
- st.error(f"An error occurred: {e}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()