Solving Quadratics by Graphing
The solutions of are exactly the -values where the parabola crosses the -axis. Reading them off a graph gives a quick estimate, shows at a glance how many solutions exist, and is the starting point of the numerical root finders computers use for equations no formula can solve.
Roots are x-intercepts
On the -axis, . So a point is on the graph of exactly when . The solutions of the equation are also called the roots or zeros of the quadratic.
Solve by graphing:
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(-3, 5, 400)
y = x**2 - 2 * x - 4
plt.figure(figsize=(6, 4))
plt.plot(x, y, label="y = x² − 2x − 4")
plt.axhline(0, color="black", linewidth=0.8)
plt.axhline(2, color="tab:orange", linestyle="--", label="y = 2")
crossings = x[:-1][np.sign(y[:-1]) != np.sign(y[1:])] # where y changes sign
plt.plot(crossings, [0] * len(crossings), "o", color="tab:red", label="roots")
plt.grid(True, alpha=0.3); plt.legend()
plt.show()
print("sign changes near x =", [round(float(c), 2) for c in crossings])sign changes near x = [-1.26, 3.24]
The graph crosses the -axis near and . The exact roots, from the quadratic formula, are and 3.236. A graph gives estimates whose accuracy depends on the scale and the sampling step; the formula gives exact values. The estimate is still useful: it tells you how many roots to expect and roughly where, which is a good check on algebra.
How many solutions?
The picture makes the three cases obvious:
| Graph | Number of real solutions | Discriminant | Example |
|---|---|---|---|
| crosses the -axis twice | 2 | ||
| touches it at the vertex | 1 (a double root) | ||
| stays above or below it | 0 real (2 complex) |
You can predict the case from the vertex: if the parabola opens upward and the vertex is below the axis, it must cross twice; if the vertex is above the axis, it never does. The discriminant tells the same story with arithmetic alone.
Equations that are not "= 0"
To solve , either move everything to one side () and find the -intercepts, or keep both sides and look for where the parabola meets the horizontal line (the dashed line in the figure). Both views give and 3.65. The second view generalises: the solutions of are the -coordinates of the points where the graphs of and meet, which is the idea behind Solving Systems by Graphing.
In software: from graph to root finder
A computer "solves by graphing" without drawing anything:
- Scan. Evaluate at evenly spaced -values and look for a sign change: if and is continuous, a root lies between them.
- Refine by bisection. Halve the interval, keep the half where the sign still changes, repeat. Each step halves the error, so 20 steps shrink it by a factor of about a million.
def f(x):
return x * x - 2 * x - 4
def scan(f, lo, hi, step):
brackets, x = [], lo
while x < hi:
if f(x) * f(x + step) < 0:
brackets.append((x, x + step))
x += step
return brackets
def bisect(f, a, b, tol=1e-9):
while b - a > tol:
m = (a + b) / 2
if f(a) * f(m) <= 0:
b = m # sign change in the left half
else:
a = m
return (a + b) / 2
for a, b in scan(f, -5, 5, 1):
print(f"root between {a} and {b}: {bisect(f, a, b):.6f}")
print("exact 1 ± √5:", round(1 - 5**0.5, 6), round(1 + 5**0.5, 6))root between -2 and -1: -1.236068
root between 3 and 4: 3.236068
exact 1 ± √5: -1.236068 3.236068
This is how calculators' "solve" buttons, spreadsheet Goal Seek and functions like SciPy's brentq work in spirit: bracket, then narrow down. They need no formula, so they also solve equations like or . The catch is visible in the table above: a scan can miss two roots that lie inside one step (no sign change), or a double root where the graph only touches the axis. Faster refinements such as Newton's method are covered in calculus, and Solving Equations in Code compares the approaches.
Exercises
Exercise 1: Read and confirm
The graph of crosses the -axis at and . Confirm by factoring.
Answer
, so the roots are 3 and −2.
Solution
Exercise 2: Touching the axis
How many solutions does have? Describe the graph.
Answer
One (a double root ). The parabola touches the -axis at its vertex without crossing it.
Solution
Exercise 3: Parabola meets line
Solve by thinking of it as the intersection of and . Give the intersection points.
Answer
and ; the points are and .
Solution
Exercise 4: Find by bisection
The positive root of is . Use a scan with step 1 on and then bisection to find it to six decimals.
Answer
The scan brackets it between 2 and 3; bisection gives 2.236068.
Solution
and , so the root is in .
def f(x):
return x * x - 5
lo, hi = 0, 5
bracket = next((x, x + 1) for x in range(lo, hi) if f(x) * f(x + 1) < 0)
a, b = bracket
while b - a > 1e-9:
m = (a + b) / 2
if f(a) * f(m) <= 0:
b = m
else:
a = m
print(bracket, f"{(a + b) / 2:.6f}", f"{5 ** 0.5:.6f}")(2, 3) 2.236068 2.236068
Test yourself
The graph of crosses the -axis at and . What are the solutions of ?
- and
- and
- and
- There are none
An upward-opening parabola has its vertex at . How many real solutions does have?
- Two
- One
- None
- Infinitely many
Why can a sign-change scan miss roots?
- Bisection is inaccurate
- Two roots inside one step, or a double root, produce no sign change
- Polynomials have no roots
- Computers cannot compare signs