@@ -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)
0 commit comments