TExcelTAD
Home › Algebra › Solving Quadratics by Graphing

Solving Quadratics by Graphing

The solutions of ax2+bx+c=0ax^2 + bx + c = 0 are exactly the xx-values where the parabola y=ax2+bx+cy = ax^2 + bx + c crosses the xx-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 xx-axis, y=0y = 0. So a point (x,0)(x, 0) is on the graph of y=ax2+bx+cy = ax^2 + bx + c exactly when ax2+bx+c=0ax^2 + bx + c = 0. The solutions of the equation are also called the roots or zeros of the quadratic.

Solve x2−2x−4=0x^2 - 2x - 4 = 0 by graphing:

python · try it yourself
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 xx-axis near x≈−1.2x \approx -1.2 and x≈3.2x \approx 3.2. The exact roots, from the quadratic formula, are 1±5≈−1.2361 \pm \sqrt{5} \approx -1.236 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 b2−4acb^2 - 4ac Example
crosses the xx-axis twice 2 >0> 0 x2−2x−4=0x^2 - 2x - 4 = 0
touches it at the vertex 1 (a double root) =0= 0 x2−6x+9=0x^2 - 6x + 9 = 0
stays above or below it 0 real (2 complex) <0< 0 x2+2x+5=0x^2 + 2x + 5 = 0

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 x2−2x−4=2x^2 - 2x - 4 = 2, either move everything to one side (x2−2x−6=0x^2 - 2x - 6 = 0) and find the xx-intercepts, or keep both sides and look for where the parabola meets the horizontal line y=2y = 2 (the dashed line in the figure). Both views give x=1±7≈−1.65x = 1 \pm \sqrt{7} \approx -1.65 and 3.65. The second view generalises: the solutions of f(x)=g(x)f(x) = g(x) are the xx-coordinates of the points where the graphs of ff and gg 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:

  1. Scan. Evaluate ff at evenly spaced xx-values and look for a sign change: if f(x1)<0<f(x2)f(x_1) < 0 < f(x_2) and ff is continuous, a root lies between them.
  2. 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.
python · try it yourself
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 x3+x=5x^3 + x = 5 or cos⁡x=x\cos x = x. 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 y=x2−x−6y = x^2 - x - 6 crosses the xx-axis at x=−2x = -2 and x=3x = 3. Confirm by factoring.

Answer

x2−x−6=(x−3)(x+2)x^2 - x - 6 = (x - 3)(x + 2), so the roots are 3 and −2.

Solution
look for two numbers with product −6 and sum −1:−3 and 2x2−x−6=(x−3)(x+2)=0→x=3 or x=−2check: 9−3−6=0 ✓4+2−6=0 ✓\begin{aligned} &\text{look for two numbers with product } -6 \text{ and sum } -1\text{:}\quad -3 \text{ and } 2 \\ &x^2 - x - 6 = (x - 3)(x + 2) = 0 \to x = 3 \text{ or } x = -2 \\ &\text{check: } 9 - 3 - 6 = 0\ \checkmark \quad 4 + 2 - 6 = 0\ \checkmark \end{aligned}

Exercise 2: Touching the axis

How many solutions does x2+4x+4=0x^2 + 4x + 4 = 0 have? Describe the graph.

Answer

One (a double root x=−2x = -2). The parabola touches the xx-axis at its vertex (−2,0)(-2, 0) without crossing it.

Solution
x2+4x+4=(x+2)2vertex: h=−42=−2, k=4−8+4=0→the vertex lies on the x-axisdiscriminant: 16−16=0\begin{aligned} &x^2 + 4x + 4 = (x + 2)^2 \\ &\text{vertex: } h = -\tfrac{4}{2} = -2,\ k = 4 - 8 + 4 = 0 \to \text{the vertex lies on the } x\text{-axis} \\ &\text{discriminant: } 16 - 16 = 0 \end{aligned}

Exercise 3: Parabola meets line

Solve x2−4=2x−1x^2 - 4 = 2x - 1 by thinking of it as the intersection of y=x2−4y = x^2 - 4 and y=2x−1y = 2x - 1. Give the intersection points.

Answer

x=−1x = -1 and x=3x = 3; the points are (−1,−3)(-1, -3) and (3,5)(3, 5).

Solution
x2−4=2x−1→x2−2x−3=0→(x−3)(x+1)=0x=3 ⁣:y=2⋅3−1=5(and 9−4=5 ✓)x=−1 ⁣:y=−2−1=−3(and 1−4=−3 ✓)\begin{aligned} &x^2 - 4 = 2x - 1 \to x^2 - 2x - 3 = 0 \to (x - 3)(x + 1) = 0 \\ &x = 3\colon\quad y = 2 \cdot 3 - 1 = 5 && (\text{and } 9 - 4 = 5\ \checkmark) \\ &x = -1\colon\quad y = -2 - 1 = -3 && (\text{and } 1 - 4 = -3\ \checkmark) \end{aligned}

Exercise 4: Find 5\sqrt{5} by bisection

The positive root of x2−5=0x^2 - 5 = 0 is 5\sqrt{5}. Use a scan with step 1 on [0,5][0, 5] and then bisection to find it to six decimals.

Answer

The scan brackets it between 2 and 3; bisection gives 2.236068.

Solution

f(2)=−1<0f(2) = -1 < 0 and f(3)=4>0f(3) = 4 > 0, so the root is in [2,3][2, 3].

python · try it yourself
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 y=ax2+bx+cy = ax^2 + bx + c crosses the xx-axis at x=−4x = -4 and x=1x = 1. What are the solutions of ax2+bx+c=0ax^2 + bx + c = 0?

  1. x=4x = 4 and x=−1x = -1
  2. x=−4x = -4 and x=1x = 1
  3. y=−4y = -4 and y=1y = 1
  4. There are none

An upward-opening parabola has its vertex at (3,2)(3, 2). How many real solutions does ax2+bx+c=0ax^2 + bx + c = 0 have?

  1. Two
  2. One
  3. None
  4. Infinitely many

Why can a sign-change scan miss roots?

  1. Bisection is inaccurate
  2. Two roots inside one step, or a double root, produce no sign change
  3. Polynomials have no roots
  4. Computers cannot compare signs