Skip to content

Commit ed59ca3

Browse files
authored
Updated files via upload
1 parent 1521b66 commit ed59ca3

File tree

4 files changed

+61
-20
lines changed

4 files changed

+61
-20
lines changed
+49-10
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,49 @@
1-
## Quadratic Equation Solver
2-
3-
### Solve quadratic equations with this tool and see the quadratic equation in graphs
4-
> The modules used were ttkbootstrap, tkinter and matplotlib
5-
6-
7-
### Problems with the code
8-
- Closing the window does not close the program
9-
10-
### Enjoy
1+
# Quadratic equation solver
2+
3+
![image](img.png)
4+
5+
## Requirements
6+
```powershell
7+
numpy : 1.24.2
8+
matplotlib : 3.6.3
9+
ttkbootstrap : 1.10.1
10+
tkinter: "inbuilt", 8.6
11+
```
12+
13+
A simple quadratic equation solver with ttkbootstrap as GUI
14+
15+
- A Quadratic class was created to ease GUI use
16+
17+
## `Class Quadratic`
18+
A quadratic class recieves 3 arguments (a,b,c) according to
19+
ax² + bx + c
20+
```python
21+
q1 = Quadratic(a = 2, b = 4, c = 5)
22+
```
23+
## Methods
24+
### The solve quad method solves a quadratic expression assuming the expression is equal to 0
25+
> returns a tuple of two numbers
26+
```python
27+
q1 = Quadratic(a = 1, b = 8, c = 16)
28+
print(q1.solveQuad())
29+
30+
# returns 4, 4
31+
```
32+
> Where the determinant is less than zero, a complex number solution is returned `python3 supports complex numbers`
33+
34+
### The evaluate method replaces the x in ax² + bx + c with an integer or float and returns the calculated value
35+
```python
36+
q1 = Quadratic(a = 1, b = 8, c = 16)
37+
print(q1.evaluate(value = 2))
38+
39+
# returns 36
40+
```
41+
### The draw figure method draws a quadratic equation graph using numpy and matplotlib
42+
> `numpy and matplotlib required` see requirements section above
43+
```python
44+
q1 = Quadratic(a = 1, b = 8, c = 16)
45+
print(q1.drawFigure())
46+
47+
# returns 4, 4
48+
```
49+
> A matplotlib figure is returned and can be added to a matplotlib graph

GUI/Quadratic-Equation-Solver/img.png

35.1 KB
Loading

GUI/Quadratic-Equation-Solver/quad.py

+11-8
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class Quadratic:
66
"""Representing a quadratic expression in the form of ax² + bx + c"""
77

88
def __init__(self,a : float, b : float, c : float) -> None:
9-
# A class is created succesfully if the arguments of the class are either float or int
9+
# A class is created succesfully if the arguments of the class are either of float type or int type
1010
if (type(a) == type(0.1) or type(a) == type(1)) and (type(b) == type(0.1) or type(b) == type(1)) and (type(c) == type(0.1) or type(c) == type(1)):
1111
self.a = a
1212
self.b = b
@@ -15,25 +15,28 @@ def __init__(self,a : float, b : float, c : float) -> None:
1515
raise ValueError("Argument must be of type int or float")
1616

1717
def __repr__(self) -> str:
18+
""" Printing a quadratic class """
1819
return "Quad( {0}x² + {1}x + {2} )".format(self.a,self.b,self.c)
1920

2021
def solveQuad(self) -> tuple[float,float]:
21-
"""Solving the expression assuming it is equal to 0 returns a tuple of 2 values"""
22-
determinant = ((self.b ** 2) - (4 * self.a * self.c)) ** 0.5
22+
"""Solving the expression assuming it is equal to 0.
23+
returns a tuple of 2 values"""
24+
25+
determinant = ((self.b ** 2) - (4 * self.a * self.c)) ** 0.5 # The determinant of a quadratic equation is the root of b² - 4ac
2326
firstSolution = ((-1 * self.b) + determinant) / (2 * self.a)
2427
secondSolution = ((-1 * self.b) - determinant) / (2 * self.a)
2528
return (firstSolution,secondSolution)
2629

27-
def evaluate(self, x):
28-
"""Substitute x for a value and return a string to be called by the eval function"""
29-
solution = ((self.a * (x ** 2)) + (self.b * x) + self.c)
30+
def evaluate(self, value):
31+
"""Evaluate the Quadratic expression. with x in ax² + bx + c as a numeric type"""
32+
solution = ((self.a * (value ** 2)) + (self.b * value) + self.c)
3033
return solution
3134

3235
def drawFigure(self):
33-
"""Draws the quadratic graph and returns a matplotlib figure"""
36+
"""Draws a quadratic graph of the quadratic expression and returns a matplotlib figure"""
3437
x_axis = np.linspace(-10,10,50)
3538
y_axis = self.evaluate(x_axis)
36-
39+
3740
figure, axes = plt.subplots()
3841

3942
axes.plot(x_axis,y_axis, linewidth = 1)

GUI/Quadratic-Equation-Solver/ui.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
# Most variables are named a,b,c according to ax² + bx + c in a quadratic equation
1010

11-
1211
def plot():
1312

1413
# Collect all inputs
@@ -52,7 +51,7 @@ def plot():
5251
# Font data
5352
font = ("Nunito", 12)
5453

55-
# Frame containig the entry for the three arguments
54+
# Frame containing the entry for the three arguments
5655
top_frame = tb.Frame(root)
5756
top_frame.grid(row = 0, column = 0,padx = 10, pady = 20)
5857

0 commit comments

Comments
 (0)