File size: 3,507 Bytes
57f9e0b
8cb5e63
 
57f9e0b
 
8cb5e63
 
 
 
 
 
 
93b92dd
 
8cb5e63
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93b92dd
 
 
8cb5e63
93b92dd
 
 
 
 
 
8cb5e63
 
 
 
 
 
 
 
93b92dd
 
 
 
 
 
 
 
 
 
 
 
 
8cb5e63
93b92dd
 
 
57f9e0b
8cb5e63
 
 
 
 
 
93b92dd
 
 
 
 
8cb5e63
93b92dd
 
 
8cb5e63
57f9e0b
 
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import streamlit as st
import math
import sympy as sp

def main():
    st.title("Advanced Calculator")

    option = st.sidebar.selectbox("Select Calculation Type", 
                                  ["Basic Arithmetic", "Algebra", "Trigonometry", "Equation Solver"])

    if option == "Basic Arithmetic":
        st.header("Basic Arithmetic")
        num1 = st.number_input("Enter first number", value=0.0, format="%.6f")
        num2 = st.number_input("Enter second number", value=0.0, format="%.6f")
        operation = st.selectbox("Choose an operation", ["Addition", "Subtraction", "Multiplication", "Division"])

        if operation == "Addition":
            result = num1 + num2
        elif operation == "Subtraction":
            result = num1 - num2
        elif operation == "Multiplication":
            result = num1 * num2
        elif operation == "Division":
            result = num1 / num2 if num2 != 0 else "Error: Division by zero"

        st.write(f"### Result: {result}")

    elif option == "Algebra":
        st.header("Algebraic Operations")
        expr = st.text_input("Enter an algebraic expression (e.g., x**2 + 3*x - 2)")
        variable = st.text_input("Enter the variable (default: x)", value="x")

        if expr:
            try:
                x = sp.symbols(variable)
                expr_sympy = sp.sympify(expr)

                st.write("**Simplified Expression:**", sp.simplify(expr_sympy))
                st.write("**Expanded Expression:**", sp.expand(expr_sympy))
                st.write("**Derivative:**", sp.diff(expr_sympy, x))
                st.write("**Integral:**", sp.integrate(expr_sympy, x))
            except Exception as e:
                st.error(f"Error in algebraic computation: {e}")

    elif option == "Trigonometry":
        st.header("Trigonometric Functions")
        angle = st.number_input("Enter angle in degrees", value=0.0)
        trig_function = st.selectbox("Choose a function", 
                                     ["sin", "cos", "tan", "cot", "sec", "csc"])

        rad = math.radians(angle)
        try:
            if trig_function == "sin":
                result = math.sin(rad)
            elif trig_function == "cos":
                result = math.cos(rad)
            elif trig_function == "tan":
                result = math.tan(rad)
            elif trig_function == "cot":
                result = 1 / math.tan(rad) if math.tan(rad) != 0 else "Undefined"
            elif trig_function == "sec":
                result = 1 / math.cos(rad) if math.cos(rad) != 0 else "Undefined"
            elif trig_function == "csc":
                result = 1 / math.sin(rad) if math.sin(rad) != 0 else "Undefined"

            st.write(f"### Result: {result}")
        except Exception as e:
            st.error(f"Error in trigonometric computation: {e}")

    elif option == "Equation Solver":
        st.header("Equation Solver")
        equation = st.text_input("Enter an equation (e.g., x**2 - 4 = 0)")
        variable = st.text_input("Enter the variable (default: x)", value="x")

        if equation:
            try:
                x = sp.symbols(variable)
                lhs, rhs = equation.split("=")
                eq = sp.Eq(sp.sympify(lhs.strip()), sp.sympify(rhs.strip()))
                solutions = sp.solve(eq, x)

                st.write("### Solutions:", solutions)
            except Exception as e:
                st.error(f"Error in solving equation: {e}")

if __name__ == "__main__":
    main()