-
Notifications
You must be signed in to change notification settings - Fork 0
/
Calculus.py
116 lines (73 loc) · 4.24 KB
/
Calculus.py
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import tkinter as tk
from sympy import symbols, integrate, diff, simplify, sympify, SympifyError, log, sin, cos, tan, asin, acos, atan, exp
x = symbols('x')
def parse_expression(expression):
try:
return simplify(sympify(expression, {"exp": exp, "sin": sin, "cos": cos, "tan": tan, "asin": asin, "acos": acos, "atan": atan, "log": log}))
except SympifyError:
replaced_expression = expression.replace('e', 'exp')
replaced_expression = replaced_expression.replace('sin', 'sin')
replaced_expression = replaced_expression.replace('cos', 'cos')
replaced_expression = replaced_expression.replace('tan', 'tan')
replaced_expression = replaced_expression.replace('asin', 'asin')
replaced_expression = replaced_expression.replace('acos', 'acos')
replaced_expression = replaced_expression.replace('atan', 'atan')
replaced_expression = replaced_expression.replace('log', 'log')
return simplify(sympify(replaced_expression, {"exp": exp, "sin": sin, "cos": cos, "tan": tan, "asin": asin, "acos": acos, "atan": atan, "log": log}))
def solve_integral(expression):
integral = integrate(expression, x)
return integral
def solve_derivative(expression):
derivative = diff(expression, x)
return derivative
def button1_click():
user_input = input_entry.get()
try:
parsed_expression = parse_expression(user_input)
print("Parsed Expression:", parsed_expression)
integral = solve_integral(parsed_expression)
print("Integral Result:", integral)
print("Result Label Text:", "Integral: " + str(integral) if integral is not None else "Invalid input. Please enter a valid input")
result_label.config(text="Integral: " + str(integral) if integral is not None else "Invalid input. Please enter a valid input")
except (SympifyError, ValueError):
result_label.config(text="Invalid input. Please enter a valid input")
def button2_click():
user_input = input_entry.get()
try:
parsed_expression = parse_expression(user_input)
print("Parsed Expression:", parsed_expression)
derivative = solve_derivative(parsed_expression)
print("Derivative Result:", derivative)
print("Result Label Text:", "Derivative: " + str(derivative) if derivative is not None else "Invalid input. Please enter a valid input")
result_label.config(text="Derivative: " + str(derivative) if derivative is not None else "Invalid input. Please enter a valid input")
except (SympifyError, ValueError):
result_label.config(text="Invalid input. Please enter a valid input")
win = tk.Tk()
win.title("FuncSol")
win.state("zoomed")
win.config(bg="black", cursor="arrow")
label1 = tk.Label(win, text = "Calculus")
label2 = tk.Label(win, text= "Reached a point of confusion and inflexion? We've got you covered!")
label3 = tk.Label(win, text = "Enter the problem here:-")
button1 = tk.Button(win, text = "> Integrate", command=button1_click)
button2 = tk.Button(win, text = "> Differentiate", command=button2_click)
back = tk.Button(win, text = "> Exit", command=win.destroy)
label1.config(font = ("Times", 40), bg = "black", fg = "white")
label2.config(font = ("Helvicta", 20), bg = "white", fg = "black")
label3.config(font = ("Arial", 20), bg = "white", fg = "black")
button1.config(font=("Arial", 12, "bold"), bg = "gold", fg = "maroon")
button2.config(font=("Arial", 12, "bold", ), bg = "gold", fg = "maroon")
back.config(font = ("Arial", 12, "bold"), bg = "grey", fg ="black")
label1.grid(row = 0, column = 0, columnspan = 3, pady = 20, sticky = "n ")
label2.grid(row = 1, column = 0, columnspan = 3, pady = 10)
label3.grid(row = 4, column = 0, pady = 10, padx = 1, sticky = "w")
button1.grid(row= 10, pady = 20, stick ="w")
button2.grid(row = 20, pady= 20, stick = "w")
back.grid(row= 30, pady=19, stick = "w")
win.columnconfigure(0, weight =1)
input_entry = tk.Entry(win, width = 50, text="here", font = ('Arial', 18))
input_entry.grid(row = 5, pady = 10, sticky = "w")
result_label = tk.Label(win, text = "", font=("Arial", 16, "bold"), height = 2, width=50)
result_label.config(bg = "white")
result_label.grid(row=25, column = 0, pady = 10, sticky = "w")
win.mainloop()