Last active
May 27, 2023 08:17
-
-
Save ozmos/49e75173fd13f4b730007230f3d40cae to your computer and use it in GitHub Desktop.
Quadratic Helper Class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Quadratic: | |
def __init__(self,a,b,c): | |
self.a = a | |
self.b = b | |
self.c = c | |
self.x_vertex = self.find_x_of_vertex() | |
self.y_vertex = self.find_y_of_vertex() | |
self.vertex = (self.x_vertex,self.y_vertex) | |
self.parabola_direction = self.find_parabola_direction() | |
self.vertex_form = self.find_vertex_form() | |
def y_given_x(self,x): | |
return (self.a * (x)**2) + (self.b * (x)) + self.c | |
def test_x_inequality(self,x,sign): | |
res = self.y_given_x(x) | |
print(res) | |
return eval(f"{res} {sign} 0") | |
def find_x_of_vertex(self): | |
return -1 * self.b/(2*self.a) | |
def find_y_of_vertex(self): | |
return self.y_given_x(self.x_vertex) | |
def find_parabola_direction(self): | |
if self.a > 0: | |
return 'upwards' | |
elif self.a < 0: | |
return 'downwards' | |
else: | |
return 'a = 0' | |
def find_vertex_form(self): | |
h_operator = '+' if self.x_vertex < 0 else '-' | |
k_operator = '+' if self.y_vertex > 0 else '-' | |
return f"y = {self.a}(x {h_operator} {int(abs(self.x_vertex))})^2 {k_operator} {int(abs(self.y_vertex))}" | |
def find_discriminant(self): | |
return self.b ** 2 - 4 * self.a * self.c |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment