Plain English first
A quadratic equation is any equation with an x² in it: ax² + bx + c = 0. Its graph is a parabola — a U-shape (or upside-down U). The solutions are wherever that parabola crosses the x-axis (where y = 0).
Sometimes a parabola crosses the x-axis twice (two solutions). Sometimes it just touches it once (one solution). Sometimes it doesn't reach the x-axis at all (no real solutions). The quadratic formula tells you which case you're in and what the answers are — without graphing anything.
The formula looks intimidating but it's just completing the square: rearranging the equation until one side is a perfect square, then taking the square root of both sides.
Standard math notation
For ax² + bx + c = 0:
−b ± √(b² − 4ac)
x = ——————————————————
2a
The discriminant b² − 4ac tells you how many real solutions exist:
b² − 4ac > 0 : two real solutions (parabola crosses x-axis twice)
b² − 4ac = 0 : one real solution (parabola just touches x-axis)
b² − 4ac < 0 : no real solutions (parabola doesn't reach x-axis)
The ± means you compute two answers:
x₁ = (−b + √(b²−4ac)) / (2a)
x₂ = (−b − √(b²−4ac)) / (2a)
Verbose Python with descriptive names
def solve_quadratic_equation(
coefficient_of_x_squared,
coefficient_of_x,
constant_term
):
"""
Find x values where ax² + bx + c = 0.
These are the x-axis crossings of the parabola y = ax² + bx + c.
The discriminant = b² - 4ac tells us how many real solutions exist.
Formula: x = (-b ± √discriminant) / (2a)
"""
a = coefficient_of_x_squared
b = coefficient_of_x
c = constant_term
discriminant = b**2 - 4 * a * c
if discriminant > 0:
square_root_of_discriminant = discriminant ** 0.5
first_solution = (-b + square_root_of_discriminant) / (2 * a)
second_solution = (-b - square_root_of_discriminant) / (2 * a)
return [first_solution, second_solution]
elif discriminant == 0:
only_solution = -b / (2 * a)
return [only_solution]
else: # discriminant < 0
return [] # no real solutions — parabola never reaches x-axis
# x² - 5x + 6 = 0 → factors as (x-2)(x-3) → x=2 or x=3
solutions = solve_quadratic_equation(
coefficient_of_x_squared=1,
coefficient_of_x=-5,
constant_term=6
)
print(f"Solutions: {solutions}") # [3.0, 2.0]
# x² + 1 = 0 → no real solutions
solutions = solve_quadratic_equation(1, 0, 1)
print(f"Solutions: {solutions}") # []
# x² - 4x + 4 = 0 → (x-2)² = 0 → x=2 (double root)
solutions = solve_quadratic_equation(1, -4, 4)
print(f"Solutions: {solutions}") # [2.0]
Where the formula comes from — completing the square
# ax² + bx + c = 0
# x² + (b/a)x = -c/a (divide by a, move c)
# x² + (b/a)x + (b/2a)² = -c/a + (b/2a)² (add same thing to both sides)
# (x + b/2a)² = (b² - 4ac) / 4a² (left side is now a perfect square)
# x + b/2a = ± √(b² - 4ac) / 2a (take square root of both sides)
# x = (-b ± √(b² - 4ac)) / 2a (solve for x)
#
# Every step is algebra — the formula is not magic, it's rearrangement.
Vertex of the parabola
def compute_parabola_vertex(a, b, c):
"""
The vertex (tip of the parabola) is halfway between the two roots.
x-coordinate of vertex = -b / (2a)
y-coordinate = plug that x back in.
"""
x_of_vertex = -b / (2 * a)
y_of_vertex = a * x_of_vertex**2 + b * x_of_vertex + c
return x_of_vertex, y_of_vertex
Opmerkingen
Nog geen opmerkingen. Wees de eerste!