File size: 1,848 Bytes
4f10448
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import sympy as sp
import numpy as np

st.title("Advanced AI-Powered Calculator")

# User input: Mathematical expression
expr = st.text_input("Enter a mathematical expression (e.g., x^2 + 2*x + 1):")

# Operation selection
operation = st.selectbox("Choose operation", ["Evaluate", "Derivative", "Integral", "Solve Equation", "Matrix Operations"])

# Define symbol
x = sp.symbols('x')

# Process based on operation
result = None

if operation == "Evaluate":
    try:
        result = sp.sympify(expr).evalf()
    except Exception as e:
        result = f"Error: {e}"

elif operation == "Derivative":
    try:
        result = sp.diff(sp.sympify(expr), x)
    except Exception as e:
        result = f"Error: {e}"

elif operation == "Integral":
    try:
        result = sp.integrate(sp.sympify(expr), x)
    except Exception as e:
        result = f"Error: {e}"

elif operation == "Solve Equation":
    try:
        equation = sp.sympify(expr)
        result = sp.solve(equation, x)
    except Exception as e:
        result = f"Error: {e}"

elif operation == "Matrix Operations":
    try:
        # Convert input into matrix
        matrix_data = [[int(num) for num in row.split()] for row in expr.split(";")]
        matrix = sp.Matrix(matrix_data)

        # Show options for matrix calculations
        matrix_operation = st.selectbox("Choose matrix operation", ["Determinant", "Inverse", "Transpose"])
        
        if matrix_operation == "Determinant":
            result = matrix.det()
        elif matrix_operation == "Inverse":
            result = matrix.inv() if matrix.det() != 0 else "Matrix is singular (no inverse)."
        elif matrix_operation == "Transpose":
            result = matrix.T
    except Exception as e:
        result = f"Error: {e}"

# Display result
st.write("Result:")
st.success(result)