-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
793 lines (662 loc) · 42.6 KB
/
main.py
File metadata and controls
793 lines (662 loc) · 42.6 KB
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
# main.py
import tkinter as tk
from tkinter import ttk, messagebox
from sympy import pi, E, I, oo
from functions import evaluate_function, find_domain
from equations import solve_single_equation, solve_system_of_equations
from expressions import expand_expression, factor_expression, simplify_expression, perform_rational_op, \
simplify_trigonometric, expand_trigonometric
from inequalities import solve_inequality
from complex_numbers import complex_add, complex_subtract, complex_multiply, complex_divide, complex_magnitude
from matrices import matrix_add, matrix_subtract, matrix_multiply, matrix_determinant, matrix_inverse, matrix_eigen
from calculus import calculate_limit, calculate_derivative, calculate_indefinite_integral, calculate_definite_integral, \
solve_ode_func, calculate_series
from plotting import plot_functions, plot_3d_function # UPDATED import for 3D
from statistics import calculate_basic_statistics
from utils import show_error, show_info
class AdvancedMathCalculator:
def __init__(self, root):
self.root = root
self.root.title("Boring")
self.root.geometry("900x750") # Increased height for new sections
self.root.resizable(False, False)
self.style = ttk.Style()
# 전체 배경색
self.style.configure("TFrame", background="#282c34") # Dark background for a sleek look
self.style.configure("TLabel", background="#282c34", foreground="#abb2bf",
font=('Arial', 10)) # Light text for contrast
# 버튼 디자인
self.style.configure("TButton",
font=('Arial', 10, 'bold'),
background="#61afef", # Blueish button color
foreground="#ffffff", # White text
relief="flat", # Flat design
borderwidth=0, # No border
padding=(10, 5)) # Padding for better click area
self.style.map("TButton",
background=[('active', '#528bff'), ('disabled', '#4a4e56')],
# Darker blue on hover, gray when disabled
foreground=[('active', '#ffffff'), ('disabled', '#81868e')])
# 탭 디자인
self.style.configure("TNotebook", background="#282c34", borderwidth=0)
self.style.configure("TNotebook.Tab",
font=('Arial', 10, 'bold'),
background="#3e4451", # Darker tab background
foreground="#abb2bf", # Light text
padding=(10, 5))
self.style.map("TNotebook.Tab",
background=[('selected', '#282c34')], # Selected tab matches frame background
foreground=[('selected', '#61afef')]) # Selected tab text is blue
# 결과 라벨 디자인 (검은 배경에 초록 글씨)
self.result_style = ttk.Style()
self.result_style.configure("Result.TLabel", background="black", foreground="lime",
font=('Monospace', 11, 'bold'), padding=5)
self.result_style.map("Result.TLabel",
background=[('active', 'black')]) # Keep background black even when active
self.notebook = ttk.Notebook(root)
self.notebook.pack(pady=10, expand=True, fill="both")
self.create_function_tab()
self.create_equation_tab()
self.create_expression_tab()
self.create_inequality_tab()
self.create_complex_numbers_tab()
self.create_matrices_tab()
self.create_calculus_tab()
self.create_graphing_tab() # UPDATED tab
self.create_statistics_tab()
self.add_constant_buttons()
def add_constant_buttons(self):
constant_frame = ttk.Frame(self.root, padding="10")
constant_frame.pack(side=tk.BOTTOM, fill=tk.X, padx=10, pady=5)
ttk.Label(constant_frame, text="Insert Constants:", font=('Arial', 9, 'bold'), background="#282c34",
foreground="#abb2bf").pack(side=tk.LEFT, padx=(0, 10))
buttons_info = [
("π", str(pi)),
("e", str(E)),
("I", str(I)),
("∞ (inf)", str(oo))
]
def get_focused_entry():
focused_widget = self.root.focus_get()
# Iterate through all notebook tabs and their children
for tab_id in self.notebook.tabs():
tab_frame = self.notebook.nametowidget(self.notebook.tab(tab_id, "text"))
for child in tab_frame.winfo_children():
if isinstance(child, ttk.Entry) and child == focused_widget:
return child
return None
for text, value in buttons_info:
btn = ttk.Button(constant_frame, text=text,
command=lambda val=value: self.insert_constant(val, get_focused_entry()))
btn.pack(side=tk.LEFT, padx=3)
def insert_constant(self, value, target_entry):
if target_entry:
try:
cursor_pos = target_entry.index(tk.INSERT)
target_entry.insert(cursor_pos, value)
except tk.TclError: # Handle cases where entry might not be ready for insertion
target_entry.insert(tk.END, value) # Insert at end if cursor not set
else:
show_info("Click on an input field first to insert the constant.")
def create_function_tab(self):
frame = ttk.Frame(self.notebook, padding="15 15 15 15")
self.notebook.add(frame, text="Functions")
ttk.Label(frame, text="Function Evaluation: f(x) and substitute x value").grid(row=0, column=0, columnspan=3,
pady=5, sticky="w")
ttk.Label(frame, text="Example: x**2 + 2*x + 1, sin(x), log(x, 10), 2**x").grid(row=1, column=0, columnspan=3,
sticky="w", padx=10)
ttk.Label(frame, text="Function f(x):").grid(row=2, column=0, sticky="w", pady=5)
self.func_entry = ttk.Entry(frame, width=40)
self.func_entry.grid(row=2, column=1, sticky="ew", pady=5)
ttk.Label(frame, text="Variable (e.g., x):").grid(row=2, column=2, sticky="w", padx=5)
self.func_var_name_entry = ttk.Entry(frame, width=10)
self.func_var_name_entry.insert(0, "x")
self.func_var_name_entry.grid(row=2, column=3, sticky="w", pady=5)
ttk.Label(frame, text="Variable Value:").grid(row=3, column=0, sticky="w", pady=5)
self.func_var_value_entry = ttk.Entry(frame, width=20)
self.func_var_value_entry.grid(row=3, column=1, sticky="ew", pady=5)
eval_button = ttk.Button(frame, text="Evaluate Function", command=self.calculate_function)
eval_button.grid(row=4, column=0, columnspan=4, pady=10)
self.func_result_label = ttk.Label(frame, text="Result:", style="Result.TLabel")
self.func_result_label.grid(row=5, column=0, columnspan=4, sticky="w", pady=5)
ttk.Separator(frame, orient="horizontal").grid(row=6, column=0, columnspan=4, sticky="ew", pady=10)
ttk.Label(frame, text="Domain Calculation: Enter function f(x)").grid(row=7, column=0, columnspan=3, pady=5,
sticky="w")
ttk.Label(frame, text="Example: 1/x, sqrt(x), tan(x)").grid(row=8, column=0, columnspan=3, sticky="w", padx=10)
ttk.Label(frame, text="Function f(x) for Domain:").grid(row=9, column=0, sticky="w", pady=5)
self.domain_func_entry = ttk.Entry(frame, width=40)
self.domain_func_entry.grid(row=9, column=1, sticky="ew", pady=5)
ttk.Label(frame, text="Variable (e.g., x):").grid(row=9, column=2, sticky="w", padx=5)
self.domain_var_name_entry = ttk.Entry(frame, width=10)
self.domain_var_name_entry.insert(0, "x")
self.domain_var_name_entry.grid(row=9, column=3, sticky="w", pady=5)
domain_button = ttk.Button(frame, text="Find Domain", command=self.find_func_domain)
domain_button.grid(row=10, column=0, columnspan=4, pady=10)
self.domain_result_label = ttk.Label(frame, text="Domain:", style="Result.TLabel")
self.domain_result_label.grid(row=11, column=0, columnspan=4, sticky="w", pady=5)
frame.columnconfigure(1, weight=1)
def calculate_function(self):
func_str = self.func_entry.get()
var_name = self.func_var_name_entry.get()
var_value = self.func_var_value_entry.get()
result = evaluate_function(func_str, var_name, var_value)
if result is not None:
self.func_result_label.config(text=f"Result: {result}")
def find_func_domain(self):
func_str = self.domain_func_entry.get()
var_name = self.domain_var_name_entry.get()
result = find_domain(func_str, var_name)
if result is not None:
self.domain_result_label.config(text=f"Domain: {result}")
def create_equation_tab(self):
frame = ttk.Frame(self.notebook, padding="15 15 15 15")
self.notebook.add(frame, text="Equations")
ttk.Label(frame,
text="Single Equation Solver: Left_Side=Right_Side (e.g., x**2 - 4 = 0, abs(x)=5, sin(x)=1, 2**x=8)").grid(
row=0, column=0, columnspan=2, pady=5, sticky="w")
ttk.Label(frame, text="Or just Left_Side if Right_Side is 0 (e.g., x**2 - 4)").grid(row=1, column=0,
columnspan=2, sticky="w",
padx=10)
ttk.Label(frame, text="Equation:").grid(row=2, column=0, sticky="w", pady=5)
self.single_eq_entry = ttk.Entry(frame, width=40)
self.single_eq_entry.grid(row=2, column=1, sticky="ew", pady=5)
ttk.Label(frame, text="Variable:").grid(row=2, column=2, sticky="w", padx=5)
self.single_eq_var_name_entry = ttk.Entry(frame, width=10)
self.single_eq_var_name_entry.insert(0, "x")
self.single_eq_var_name_entry.grid(row=2, column=3, sticky="w", pady=5)
solve_single_button = ttk.Button(frame, text="Solve Single Equation", command=self.solve_single_equation)
solve_single_button.grid(row=3, column=0, columnspan=4, pady=10)
self.single_eq_result_label = ttk.Label(frame, text="Result:", style="Result.TLabel")
self.single_eq_result_label.grid(row=4, column=0, columnspan=4, sticky="w", pady=5)
ttk.Separator(frame, orient="horizontal").grid(row=5, column=0, columnspan=4, sticky="ew", pady=10)
ttk.Label(frame, text="System of Equations Solver: Separate equations with ';'").grid(row=6, column=0,
columnspan=2, pady=5,
sticky="w")
ttk.Label(frame, text="Example: x+y=5; x-y=1 (for linear systems)").grid(row=7, column=0, columnspan=2,
sticky="w", padx=10)
ttk.Label(frame, text="Equations:").grid(row=8, column=0, sticky="w", pady=5)
self.system_eq_entry = ttk.Entry(frame, width=40)
self.system_eq_entry.grid(row=8, column=1, sticky="ew", pady=5)
ttk.Label(frame, text="Variables (x,y):").grid(row=8, column=2, sticky="w", padx=5)
self.system_eq_vars_entry = ttk.Entry(frame, width=10)
self.system_eq_vars_entry.insert(0, "x y")
self.system_eq_vars_entry.grid(row=8, column=3, sticky="w", pady=5)
solve_system_button = ttk.Button(frame, text="Solve System", command=self.solve_system_equations)
solve_system_button.grid(row=9, column=0, columnspan=4, pady=10)
self.system_eq_result_label = ttk.Label(frame, text="Result:", style="Result.TLabel")
self.system_eq_result_label.grid(row=10, column=0, columnspan=4, sticky="w", pady=5)
frame.columnconfigure(1, weight=1)
def solve_single_equation(self):
equation_str = self.single_eq_entry.get()
var_name = self.single_eq_var_name_entry.get()
result = solve_single_equation(equation_str, var_name)
if result is not None:
self.single_eq_result_label.config(text=f"Result: {result}")
def solve_system_equations(self):
equations_str = self.system_eq_entry.get()
var_names_str = self.system_eq_vars_entry.get()
result = solve_system_of_equations(equations_str, var_names_str)
if result is not None:
self.system_eq_result_label.config(text=f"Result: {result}")
def create_expression_tab(self):
frame = ttk.Frame(self.notebook, padding="15 15 15 15")
self.notebook.add(frame, text="Expressions")
ttk.Label(frame, text="Polynomial/Trig/Log Manipulation: Expand, Factor, Simplify").grid(row=0, column=0,
columnspan=3, pady=5,
sticky="w")
ttk.Label(frame,
text="Examples: (x + 1)**2, x**2 - 4, (x**2 - 1)/(x - 1), sin(x)**2 + cos(x)**2, sin(2*x)").grid(
row=1, column=0, columnspan=3, sticky="w", padx=10)
ttk.Label(frame, text="Expression:").grid(row=2, column=0, sticky="w", pady=5)
self.expr_entry = ttk.Entry(frame, width=40)
self.expr_entry.grid(row=2, column=1, sticky="ew", pady=5)
ttk.Label(frame, text="Variable (e.g., x):").grid(row=2, column=2, sticky="w", padx=5)
self.expr_var_name_entry = ttk.Entry(frame, width=10)
self.expr_var_name_entry.insert(0, "x")
self.expr_var_name_entry.grid(row=2, column=3, sticky="w", pady=5)
expand_button = ttk.Button(frame, text="Expand", command=self.expand_expression)
expand_button.grid(row=3, column=0, pady=10, padx=5, sticky="e")
factor_button = ttk.Button(frame, text="Factor", command=self.factor_expression)
factor_button.grid(row=3, column=1, pady=10, padx=5, sticky="w")
simplify_button = ttk.Button(frame, text="Simplify", command=self.simplify_expression)
simplify_button.grid(row=3, column=2, pady=10, padx=5, sticky="e")
simplify_trig_button = ttk.Button(frame, text="Simplify Trig", command=self.simplify_trigonometric_expression)
simplify_trig_button.grid(row=3, column=3, pady=10, padx=5, sticky="w")
expand_trig_button = ttk.Button(frame, text="Expand Trig", command=self.expand_trigonometric_expression)
expand_trig_button.grid(row=4, column=0, pady=10, padx=5, sticky="e")
self.expr_result_label = ttk.Label(frame, text="Result:", style="Result.TLabel")
self.expr_result_label.grid(row=5, column=0, columnspan=4, sticky="w", pady=5)
ttk.Separator(frame, orient="horizontal").grid(row=6, column=0, columnspan=4, sticky="ew", pady=10)
ttk.Label(frame, text="Rational Expression Operations: E1 Op E2 (e.g., (x+1)/x + 1/(x-1))").grid(row=7,
column=0,
columnspan=3,
pady=5,
sticky="w")
ttk.Label(frame, text="Expression 1:").grid(row=8, column=0, sticky="w", pady=5)
self.rational_expr1_entry = ttk.Entry(frame, width=25)
self.rational_expr1_entry.grid(row=8, column=1, sticky="ew", pady=5)
ttk.Label(frame, text="Operation (+ - * /):").grid(row=8, column=2, sticky="w", padx=5)
self.rational_op_entry = ttk.Entry(frame, width=5)
self.rational_op_entry.grid(row=8, column=3, sticky="w", pady=5)
ttk.Label(frame, text="Expression 2:").grid(row=9, column=0, sticky="w", pady=5)
self.rational_expr2_entry = ttk.Entry(frame, width=25)
self.rational_expr2_entry.grid(row=9, column=1, sticky="ew", pady=5)
ttk.Label(frame, text="Variable (e.g., x):").grid(row=9, column=2, sticky="w", padx=5)
self.rational_var_name_entry = ttk.Entry(frame, width=10)
self.rational_var_name_entry.insert(0, "x")
self.rational_var_name_entry.grid(row=9, column=3, sticky="w", pady=5)
rational_op_button = ttk.Button(frame, text="Perform Operation", command=self.perform_rational_operation)
rational_op_button.grid(row=10, column=0, columnspan=4, pady=10)
self.rational_result_label = ttk.Label(frame, text="Result:", style="Result.TLabel")
self.rational_result_label.grid(row=11, column=0, columnspan=4, sticky="w", pady=5)
frame.columnconfigure(1, weight=1)
def expand_expression(self):
expr_str = self.expr_entry.get()
var_name = self.expr_var_name_entry.get()
result = expand_expression(expr_str, var_name)
if result is not None:
self.expr_result_label.config(text=f"Result: {result}")
def factor_expression(self):
expr_str = self.expr_entry.get()
var_name = self.expr_var_name_entry.get()
result = factor_expression(expr_str, var_name)
if result is not None:
self.expr_result_label.config(text=f"Result: {result}")
def simplify_expression(self):
expr_str = self.expr_entry.get()
var_name = self.expr_var_name_entry.get()
result = simplify_expression(expr_str, var_name)
if result is not None:
self.expr_result_label.config(text=f"Result: {result}")
def simplify_trigonometric_expression(self):
expr_str = self.expr_entry.get()
var_name = self.expr_var_name_entry.get()
result = simplify_trigonometric(expr_str, var_name)
if result is not None:
self.expr_result_label.config(text=f"Result: {result}")
def expand_trigonometric_expression(self):
expr_str = self.expr_entry.get()
var_name = self.expr_var_name_entry.get()
result = expand_trigonometric(expr_str, var_name)
if result is not None:
self.expr_result_label.config(text=f"Result: {result}")
def perform_rational_operation(self):
expr1_str = self.rational_expr1_entry.get()
op = self.rational_op_entry.get()
expr2_str = self.rational_expr2_entry.get()
var_name = self.rational_var_name_entry.get()
result = perform_rational_op(expr1_str, op, expr2_str, var_name)
if result is not None:
self.rational_result_label.config(text=f"Result: {result}")
def create_inequality_tab(self):
frame = ttk.Frame(self.notebook, padding="15 15 15 15")
self.notebook.add(frame, text="Inequalities")
ttk.Label(frame, text="Inequality Solver: (e.g., x > 5, x**2 - 4 <= 0, abs(x-2) < 3)").grid(row=0, column=0,
columnspan=2,
pady=10, sticky="w")
ttk.Label(frame, text="Inequality:").grid(row=1, column=0, sticky="w", pady=5)
self.ineq_entry = ttk.Entry(frame, width=40)
self.ineq_entry.grid(row=1, column=1, sticky="ew", pady=5)
ttk.Label(frame, text="Variable (e.g., x):").grid(row=1, column=2, sticky="w", padx=5)
self.ineq_var_name_entry = ttk.Entry(frame, width=10)
self.ineq_var_name_entry.insert(0, "x")
self.ineq_var_name_entry.grid(row=1, column=3, sticky="w", pady=5)
solve_ineq_button = ttk.Button(frame, text="Solve Inequality", command=self.solve_inequality)
solve_ineq_button.grid(row=2, column=0, columnspan=4, pady=15)
self.ineq_result_label = ttk.Label(frame, text="Result:", style="Result.TLabel")
self.ineq_result_label.grid(row=3, column=0, columnspan=4, sticky="w", pady=5)
frame.columnconfigure(1, weight=1)
def solve_inequality(self):
ineq_str = self.ineq_entry.get()
var_name = self.ineq_var_name_entry.get()
result = solve_inequality(ineq_str, var_name)
if result is not None:
self.ineq_result_label.config(text=f"Result: {result}")
def create_complex_numbers_tab(self):
frame = ttk.Frame(self.notebook, padding="15 15 15 15")
self.notebook.add(frame, text="Complex Numbers")
ttk.Label(frame, text="Complex Number Operations: (a+b*I), where 'I' is sqrt(-1)").grid(row=0, column=0,
columnspan=2, pady=5,
sticky="w")
ttk.Label(frame, text="Examples: 2+3*I, 5-I, 7").grid(row=1, column=0, columnspan=2, sticky="w", padx=10)
ttk.Label(frame, text="Complex Number 1:").grid(row=2, column=0, sticky="w", pady=5)
self.cn_z1_entry = ttk.Entry(frame, width=30)
self.cn_z1_entry.grid(row=2, column=1, sticky="ew", pady=5)
ttk.Label(frame, text="Complex Number 2:").grid(row=3, column=0, sticky="w", pady=5)
self.cn_z2_entry = ttk.Entry(frame, width=30)
self.cn_z2_entry.grid(row=3, column=1, sticky="ew", pady=5)
add_button = ttk.Button(frame, text="Add (+)", command=self.complex_add_op)
add_button.grid(row=4, column=0, pady=10, padx=5, sticky="e")
subtract_button = ttk.Button(frame, text="Subtract (-)", command=self.complex_subtract_op)
subtract_button.grid(row=4, column=1, pady=10, padx=5, sticky="w")
multiply_button = ttk.Button(frame, text="Multiply (*)", command=self.complex_multiply_op)
multiply_button.grid(row=5, column=0, pady=10, padx=5, sticky="e")
divide_button = ttk.Button(frame, text="Divide (/)", command=self.complex_divide_op)
divide_button.grid(row=5, column=1, pady=10, padx=5, sticky="w")
ttk.Separator(frame, orient="horizontal").grid(row=6, column=0, columnspan=2, sticky="ew", pady=10)
ttk.Label(frame, text="Magnitude of Z1:").grid(row=7, column=0, sticky="w", pady=5)
magnitude_button = ttk.Button(frame, text="Calculate Magnitude", command=self.complex_magnitude_op)
magnitude_button.grid(row=7, column=1, pady=10, padx=5, sticky="w")
self.cn_result_label = ttk.Label(frame, text="Result:", style="Result.TLabel")
self.cn_result_label.grid(row=8, column=0, columnspan=2, sticky="w", pady=5)
frame.columnconfigure(1, weight=1)
def complex_add_op(self):
z1_str = self.cn_z1_entry.get()
z2_str = self.cn_z2_entry.get()
result = complex_add(z1_str, z2_str)
if result is not None:
self.cn_result_label.config(text=f"Result: {result}")
def complex_subtract_op(self):
z1_str = self.cn_z1_entry.get()
z2_str = self.cn_z2_entry.get()
result = complex_subtract(z1_str, z2_str)
if result is not None:
self.cn_result_label.config(text=f"Result: {result}")
def complex_multiply_op(self):
z1_str = self.cn_z1_entry.get()
z2_str = self.cn_z2_entry.get()
result = complex_multiply(z1_str, z2_str)
if result is not None:
self.cn_result_label.config(text=f"Result: {result}")
def complex_divide_op(self):
z1_str = self.cn_z1_entry.get()
z2_str = self.cn_z2_entry.get()
result = complex_divide(z1_str, z2_str)
if result is not None:
self.cn_result_label.config(text=f"Result: {result}")
def complex_magnitude_op(self):
z1_str = self.cn_z1_entry.get()
result = complex_magnitude(z1_str)
if result is not None:
self.cn_result_label.config(text=f"Result: {result}")
def create_matrices_tab(self):
frame = ttk.Frame(self.notebook, padding="15 15 15 15")
self.notebook.add(frame, text="Matrices")
ttk.Label(frame,
text="Matrix Operations: Enter matrices as comma-separated rows; rows separated by semicolon").grid(
row=0, column=0, columnspan=3, pady=5, sticky="w")
ttk.Label(frame, text="Example: [[1,2];[3,4]]").grid(row=1, column=0, columnspan=3, sticky="w", padx=10)
ttk.Label(frame, text="Matrix A:").grid(row=2, column=0, sticky="w", pady=5)
self.matrix_a_entry = ttk.Entry(frame, width=40)
self.matrix_a_entry.grid(row=2, column=1, sticky="ew", pady=5)
ttk.Label(frame, text="Matrix B:").grid(row=3, column=0, sticky="w", pady=5)
self.matrix_b_entry = ttk.Entry(frame, width=40)
self.matrix_b_entry.grid(row=3, column=1, sticky="ew", pady=5)
add_button = ttk.Button(frame, text="Add (A+B)", command=self.matrix_add_op)
add_button.grid(row=4, column=0, pady=10, padx=5, sticky="e")
subtract_button = ttk.Button(frame, text="Subtract (A-B)", command=self.matrix_subtract_op)
subtract_button.grid(row=4, column=1, pady=10, padx=5, sticky="w")
multiply_button = ttk.Button(frame, text="Multiply (A*B)", command=self.matrix_multiply_op)
multiply_button.grid(row=5, column=0, pady=10, padx=5, sticky="e")
ttk.Separator(frame, orient="horizontal").grid(row=6, column=0, columnspan=2, sticky="ew", pady=10)
ttk.Label(frame, text="Single Matrix Operations (for Matrix A):").grid(row=7, column=0, columnspan=2, pady=5,
sticky="w")
determinant_button = ttk.Button(frame, text="Determinant", command=self.matrix_determinant_op)
determinant_button.grid(row=8, column=0, pady=10, padx=5, sticky="e")
inverse_button = ttk.Button(frame, text="Inverse", command=self.matrix_inverse_op)
inverse_button.grid(row=8, column=1, pady=10, padx=5, sticky="w")
eigen_button = ttk.Button(frame, text="Eigenvalues/vectors", command=self.matrix_eigen_op)
eigen_button.grid(row=9, column=0, columnspan=2, pady=10, padx=5)
self.matrix_result_label = ttk.Label(frame, text="Result:", style="Result.TLabel")
self.matrix_result_label.grid(row=10, column=0, columnspan=2, sticky="w", pady=5)
frame.columnconfigure(1, weight=1)
def matrix_add_op(self):
matrix_a_str = self.matrix_a_entry.get()
matrix_b_str = self.matrix_b_entry.get()
result = matrix_add(matrix_a_str, matrix_b_str)
if result is not None:
self.matrix_result_label.config(text=f"Result: {result}")
def matrix_subtract_op(self):
matrix_a_str = self.matrix_a_entry.get()
matrix_b_str = self.matrix_b_entry.get()
result = matrix_subtract(matrix_a_str, matrix_b_str)
if result is not None:
self.matrix_result_label.config(text=f"Result: {result}")
def matrix_multiply_op(self):
matrix_a_str = self.matrix_a_entry.get()
matrix_b_str = self.matrix_b_entry.get()
result = matrix_multiply(matrix_a_str, matrix_b_str)
if result is not None:
self.matrix_result_label.config(text=f"Result: {result}")
def matrix_determinant_op(self):
matrix_a_str = self.matrix_a_entry.get()
result = matrix_determinant(matrix_a_str)
if result is not None:
self.matrix_result_label.config(text=f"Result: {result}")
def matrix_inverse_op(self):
matrix_a_str = self.matrix_a_entry.get()
result = matrix_inverse(matrix_a_str)
if result is not None:
self.matrix_result_label.config(text=f"Result: {result}")
def matrix_eigen_op(self):
matrix_a_str = self.matrix_a_entry.get()
result = matrix_eigen(matrix_a_str)
if result is not None:
self.matrix_result_label.config(text=f"Result: {result}")
def create_calculus_tab(self):
frame = ttk.Frame(self.notebook, padding="15 15 15 15")
self.notebook.add(frame, text="Calculus")
# Limit Calculation
ttk.Label(frame, text="Limit Calculation:").grid(row=0, column=0, columnspan=4, pady=5, sticky="w")
ttk.Label(frame, text="Function:").grid(row=1, column=0, sticky="w", pady=2)
self.limit_func_entry = ttk.Entry(frame, width=30)
self.limit_func_entry.grid(row=1, column=1, sticky="ew", pady=2)
ttk.Label(frame, text="Variable:").grid(row=1, column=2, sticky="w", padx=5)
self.limit_var_entry = ttk.Entry(frame, width=10)
self.limit_var_entry.insert(0, "x")
self.limit_var_entry.grid(row=1, column=3, sticky="w", pady=2)
ttk.Label(frame, text="Point (e.g., 0, oo, -oo):").grid(row=2, column=0, sticky="w", pady=2)
self.limit_point_entry = ttk.Entry(frame, width=15)
self.limit_point_entry.grid(row=2, column=1, sticky="ew", pady=2)
limit_button = ttk.Button(frame, text="Calculate Limit", command=self.calculate_limit_op)
limit_button.grid(row=3, column=0, columnspan=4, pady=5)
self.limit_result_label = ttk.Label(frame, text="Limit:", style="Result.TLabel")
self.limit_result_label.grid(row=4, column=0, columnspan=4, sticky="w", pady=2)
ttk.Separator(frame, orient="horizontal").grid(row=5, column=0, columnspan=4, sticky="ew", pady=5)
# Derivative Calculation
ttk.Label(frame, text="Derivative Calculation:").grid(row=6, column=0, columnspan=4, pady=5, sticky="w")
ttk.Label(frame, text="Function:").grid(row=7, column=0, sticky="w", pady=2)
self.deriv_func_entry = ttk.Entry(frame, width=30)
self.deriv_func_entry.grid(row=7, column=1, sticky="ew", pady=2)
ttk.Label(frame, text="Variable:").grid(row=7, column=2, sticky="w", padx=5)
self.deriv_var_entry = ttk.Entry(frame, width=10)
self.deriv_var_entry.insert(0, "x")
self.deriv_var_entry.grid(row=7, column=3, sticky="w", pady=2)
ttk.Label(frame, text="Order (e.g., 1, 2):").grid(row=8, column=0, sticky="w", pady=2)
self.deriv_order_entry = ttk.Entry(frame, width=10)
self.deriv_order_entry.insert(0, "1")
self.deriv_order_entry.grid(row=8, column=1, sticky="ew", pady=2)
deriv_button = ttk.Button(frame, text="Calculate Derivative", command=self.calculate_derivative_op)
deriv_button.grid(row=9, column=0, columnspan=4, pady=5)
self.deriv_result_label = ttk.Label(frame, text="Derivative:", style="Result.TLabel")
self.deriv_result_label.grid(row=10, column=0, columnspan=4, sticky="w", pady=2)
ttk.Separator(frame, orient="horizontal").grid(row=11, column=0, columnspan=4, sticky="ew", pady=5)
# Integral Calculation
ttk.Label(frame, text="Integral Calculation:").grid(row=12, column=0, columnspan=4, pady=5, sticky="w")
ttk.Label(frame, text="Function:").grid(row=13, column=0, sticky="w", pady=2)
self.integral_func_entry = ttk.Entry(frame, width=30)
self.integral_func_entry.grid(row=13, column=1, sticky="ew", pady=2)
ttk.Label(frame, text="Variable:").grid(row=13, column=2, sticky="w", padx=5)
self.integral_var_entry = ttk.Entry(frame, width=10)
self.integral_var_entry.insert(0, "x")
self.integral_var_entry.grid(row=13, column=3, sticky="w", pady=2)
ttk.Label(frame, text="Lower Bound (Optional):").grid(row=14, column=0, sticky="w", pady=2)
self.integral_lower_entry = ttk.Entry(frame, width=15)
self.integral_lower_entry.grid(row=14, column=1, sticky="ew", pady=2)
ttk.Label(frame, text="Upper Bound (Optional):").grid(row=14, column=2, sticky="w", padx=5)
self.integral_upper_entry = ttk.Entry(frame, width=15)
self.integral_upper_entry.grid(row=14, column=3, sticky="ew", pady=2)
integral_button = ttk.Button(frame, text="Calculate Integral", command=self.calculate_integral_op)
integral_button.grid(row=15, column=0, columnspan=4, pady=5)
self.integral_result_label = ttk.Label(frame, text="Integral:", style="Result.TLabel")
self.integral_result_label.grid(row=16, column=0, columnspan=4, sticky="w", pady=2)
ttk.Separator(frame, orient="horizontal").grid(row=17, column=0, columnspan=4, sticky="ew", pady=5)
# ODE Solver
ttk.Label(frame, text="Ordinary Differential Equation (ODE) Solver:").grid(row=18, column=0, columnspan=4,
pady=5, sticky="w")
ttk.Label(frame, text="Equation (e.g., Eq(f(x).diff(x, 2) + f(x), 0)):").grid(row=19, column=0, sticky="w",
pady=2)
self.ode_eq_entry = ttk.Entry(frame, width=40)
self.ode_eq_entry.grid(row=19, column=1, columnspan=3, sticky="ew", pady=2)
ttk.Label(frame, text="Function (e.g., f(x)):").grid(row=20, column=0, sticky="w", pady=2)
self.ode_func_entry = ttk.Entry(frame, width=15)
self.ode_func_entry.insert(0, "f(x)")
self.ode_func_entry.grid(row=20, column=1, sticky="ew", pady=2)
ttk.Label(frame, text="Variable (e.g., x):").grid(row=20, column=2, sticky="w", padx=5)
self.ode_var_entry = ttk.Entry(frame, width=10)
self.ode_var_entry.insert(0, "x")
self.ode_var_entry.grid(row=20, column=3, sticky="w", pady=2)
ode_button = ttk.Button(frame, text="Solve ODE", command=self.solve_ode_op)
ode_button.grid(row=21, column=0, columnspan=4, pady=5)
self.ode_result_label = ttk.Label(frame, text="ODE Solution:", style="Result.TLabel")
self.ode_result_label.grid(row=22, column=0, columnspan=4, sticky="w", pady=2)
ttk.Separator(frame, orient="horizontal").grid(row=23, column=0, columnspan=4, sticky="ew", pady=5)
# Series Expansion
ttk.Label(frame, text="Series Expansion (Taylor/Maclaurin):").grid(row=24, column=0, columnspan=4, pady=5,
sticky="w")
ttk.Label(frame, text="Function:").grid(row=25, column=0, sticky="w", pady=2)
self.series_func_entry = ttk.Entry(frame, width=30)
self.series_func_entry.grid(row=25, column=1, sticky="ew", pady=2)
ttk.Label(frame, text="Variable:").grid(row=25, column=2, sticky="w", padx=5)
self.series_var_entry = ttk.Entry(frame, width=10)
self.series_var_entry.insert(0, "x")
self.series_var_entry.grid(row=25, column=3, sticky="w", pady=2)
ttk.Label(frame, text="Point (e.g., 0):").grid(row=26, column=0, sticky="w", pady=2)
self.series_point_entry = ttk.Entry(frame, width=15)
self.series_point_entry.insert(0, "0")
self.series_point_entry.grid(row=26, column=1, sticky="ew", pady=2)
ttk.Label(frame, text="Order (e.g., 5):").grid(row=26, column=2, sticky="w", padx=5)
self.series_order_entry = ttk.Entry(frame, width=10)
self.series_order_entry.insert(0, "5")
self.series_order_entry.grid(row=26, column=3, sticky="w", pady=2)
series_button = ttk.Button(frame, text="Calculate Series", command=self.calculate_series_op)
series_button.grid(row=27, column=0, columnspan=4, pady=5)
self.series_result_label = ttk.Label(frame, text="Series:", style="Result.TLabel")
self.series_result_label.grid(row=28, column=0, columnspan=4, sticky="w", pady=2)
frame.columnconfigure(1, weight=1)
frame.columnconfigure(3, weight=1)
def calculate_limit_op(self):
func_str = self.limit_func_entry.get()
var_str = self.limit_var_entry.get()
point_str = self.limit_point_entry.get()
result = calculate_limit(func_str, var_str, point_str)
if result is not None:
self.limit_result_label.config(text=f"Limit: {result}")
def calculate_derivative_op(self):
func_str = self.deriv_func_entry.get()
var_str = self.deriv_var_entry.get()
order_str = self.deriv_order_entry.get()
result = calculate_derivative(func_str, var_str, order_str)
if result is not None:
self.deriv_result_label.config(text=f"Derivative: {result}")
def calculate_integral_op(self):
func_str = self.integral_func_entry.get()
var_str = self.integral_var_entry.get()
lower_str = self.integral_lower_entry.get()
upper_str = self.integral_upper_entry.get()
if lower_str and upper_str:
result = calculate_definite_integral(func_str, var_str, lower_str, upper_str)
else:
result = calculate_indefinite_integral(func_str, var_str)
if result is not None:
self.integral_result_label.config(text=f"Integral: {result}")
def solve_ode_op(self):
eq_str = self.ode_eq_entry.get()
func_str = self.ode_func_entry.get()
var_str = self.ode_var_entry.get()
result = solve_ode_func(eq_str, func_str, var_str)
if result is not None:
self.ode_result_label.config(text=f"ODE Solution: {result}")
def calculate_series_op(self):
func_str = self.series_func_entry.get()
var_str = self.series_var_entry.get()
point_str = self.series_point_entry.get()
order_str = self.series_order_entry.get()
result = calculate_series(func_str, var_str, point_str, order_str)
if result is not None:
self.series_result_label.config(text=f"Series: {result}")
def create_graphing_tab(self):
frame = ttk.Frame(self.notebook, padding="15 15 15 15")
self.notebook.add(frame, text="Graphing")
# 2D Plotting
ttk.Label(frame, text="2D Plot Function: y = f(x)").grid(row=0, column=0, columnspan=4, pady=5, sticky="w")
ttk.Label(frame, text="Functions (separate with ';'):").grid(row=1, column=0, sticky="w", pady=2)
self.plot2d_func_entry = ttk.Entry(frame, width=40)
self.plot2d_func_entry.grid(row=1, column=1, columnspan=3, sticky="ew", pady=2)
ttk.Label(frame, text="Variable:").grid(row=2, column=0, sticky="w", pady=2)
self.plot2d_var_entry = ttk.Entry(frame, width=10)
self.plot2d_var_entry.insert(0, "x")
self.plot2d_var_entry.grid(row=2, column=1, sticky="ew", pady=2)
ttk.Label(frame, text="X-Range (start,end):").grid(row=2, column=2, sticky="w", padx=5)
self.plot2d_xrange_entry = ttk.Entry(frame, width=15)
self.plot2d_xrange_entry.insert(0, "-10,10")
self.plot2d_xrange_entry.grid(row=2, column=3, sticky="ew", pady=2)
plot2d_button = ttk.Button(frame, text="Plot 2D Graph", command=self.plot_2d_graph)
plot2d_button.grid(row=3, column=0, columnspan=4, pady=5)
ttk.Separator(frame, orient="horizontal").grid(row=4, column=0, columnspan=4, sticky="ew", pady=10)
# 3D Plotting
ttk.Label(frame, text="3D Plot Function: z = f(x, y)").grid(row=5, column=0, columnspan=4, pady=5, sticky="w")
ttk.Label(frame, text="Function:").grid(row=6, column=0, sticky="w", pady=2)
self.plot3d_func_entry = ttk.Entry(frame, width=40)
self.plot3d_func_entry.grid(row=6, column=1, columnspan=3, sticky="ew", pady=2)
ttk.Label(frame, text="X-Variable Name:").grid(row=7, column=0, sticky="w", pady=2)
self.plot3d_xvar_entry = ttk.Entry(frame, width=10)
self.plot3d_xvar_entry.insert(0, "x")
self.plot3d_xvar_entry.grid(row=7, column=1, sticky="ew", pady=2)
ttk.Label(frame, text="Y-Variable Name:").grid(row=7, column=2, sticky="w", padx=5)
self.plot3d_yvar_entry = ttk.Entry(frame, width=10)
self.plot3d_yvar_entry.insert(0, "y")
self.plot3d_yvar_entry.grid(row=7, column=3, sticky="ew", pady=2)
ttk.Label(frame, text="X-Range (start,end):").grid(row=8, column=0, sticky="w", pady=2)
self.plot3d_xrange_entry = ttk.Entry(frame, width=15)
self.plot3d_xrange_entry.insert(0, "-5,5")
self.plot3d_xrange_entry.grid(row=8, column=1, sticky="ew", pady=2)
ttk.Label(frame, text="Y-Range (start,end):").grid(row=8, column=2, sticky="w", padx=5)
self.plot3d_yrange_entry = ttk.Entry(frame, width=15)
self.plot3d_yrange_entry.insert(0, "-5,5")
self.plot3d_yrange_entry.grid(row=8, column=3, sticky="ew", pady=2)
ttk.Label(frame, text="Colormap (e.g., viridis, plasma, jet):").grid(row=9, column=0, sticky="w", pady=2)
self.plot3d_cmap_entry = ttk.Entry(frame, width=15)
self.plot3d_cmap_entry.insert(0, "viridis")
self.plot3d_cmap_entry.grid(row=9, column=1, sticky="ew", pady=2)
plot3d_button = ttk.Button(frame, text="Plot 3D Graph", command=self.plot_3d_graph)
plot3d_button.grid(row=10, column=0, columnspan=4, pady=5)
frame.columnconfigure(1, weight=1)
frame.columnconfigure(3, weight=1)
def plot_2d_graph(self):
func_str = self.plot2d_func_entry.get()
var_str = self.plot2d_var_entry.get()
x_range_str = self.plot2d_xrange_entry.get()
plot_functions(func_str, var_str, x_range_str)
def plot_3d_graph(self):
func_str = self.plot3d_func_entry.get()
x_var_str = self.plot3d_xvar_entry.get()
y_var_str = self.plot3d_yvar_entry.get()
x_range_str = self.plot3d_xrange_entry.get()
y_range_str = self.plot3d_yrange_entry.get()
cmap = self.plot3d_cmap_entry.get()
plot_3d_function(func_str, x_var_str, y_var_str, x_range_str, y_range_str, cmap)
def create_statistics_tab(self):
frame = ttk.Frame(self.notebook, padding="15 15 15 15")
self.notebook.add(frame, text="Statistics")
ttk.Label(frame, text="Basic Statistics: Enter numbers separated by commas").grid(row=0, column=0, columnspan=2,
pady=10, sticky="w")
ttk.Label(frame, text="Example: 1,2,3,4,5").grid(row=1, column=0, columnspan=2, sticky="w", padx=10)
ttk.Label(frame, text="Data:").grid(row=2, column=0, sticky="w", pady=5)
self.stats_data_entry = ttk.Entry(frame, width=50)
self.stats_data_entry.grid(row=2, column=1, sticky="ew", pady=5)
calculate_stats_button = ttk.Button(frame, text="Calculate Statistics",
command=self.calculate_basic_statistics_op)
calculate_stats_button.grid(row=3, column=0, columnspan=2, pady=15)
self.stats_result_label = ttk.Label(frame, text="Results:", style="Result.TLabel")
self.stats_result_label.grid(row=4, column=0, columnspan=2, sticky="w", pady=5)
frame.columnconfigure(1, weight=1)
def calculate_basic_statistics_op(self):
data_str = self.stats_data_entry.get()
result = calculate_basic_statistics(data_str)
if result is not None:
self.stats_result_label.config(text=f"Results: {result}")
if __name__ == "__main__":
root = tk.Tk()
app = AdvancedMathCalculator(root)
root.mainloop()