Calculator of Alexandria

Quadratic equation solver

Solve ax² + bx + c = 0 for real or complex roots, with the vertex, the discriminant and the quadratic formula derived by completing the square.

Discriminant b² − 4acΔ\Delta
Vertex x = −b/2a
Vertex y (minimum or maximum value)

Formula

x=−b±b2−4ac2ax = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}
How it's derived

The formula

x=−b±b2−4ac2ax = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}

This solves ax2+bx+c=0ax^2 + bx + c = 0 for any a≠0a \neq 0.

Where it comes from

The method is called completing the square. Start with the equation and divide through by aa:

x2+bax=−cax^2 + \frac{b}{a}x = -\frac{c}{a}

The left side is almost a perfect square. (x+b2a)2(x + \frac{b}{2a})^2 expands to x2+bax+b24a2x^2 + \frac{b}{a}x + \frac{b^2}{4a^2}, so add b24a2\frac{b^2}{4a^2} to both sides:

(x+b2a)2=b2−4ac4a2\left(x + \frac{b}{2a}\right)^2 = \frac{b^2 - 4ac}{4a^2}

Take the square root of both sides, remembering it can be positive or negative, then subtract b2a\frac{b}{2a}. That gives the quadratic formula.

The discriminant Δ=b2−4ac\Delta = b^2 - 4ac is the part under the root, and it decides what kind of answer you get:

  • Δ>0\Delta > 0: two real roots. The parabola crosses the x-axis twice.
  • Δ=0\Delta = 0: one repeated root. The parabola just touches the axis.
  • Δ<0\Delta < 0: two complex roots. The parabola never reaches the axis.

The vertex, the parabola’s turning point, sits halfway between the roots, at x=−b/2ax = -b/2a.

Worked example

2x2−3x−5=02x^2 - 3x - 5 = 0, so a=2a = 2, b=−3b = -3, c=−5c = -5:

Δ=9+40=49\Delta = 9 + 40 = 49 x=3±74=2.5 or −1x = \frac{3 \pm 7}{4} = 2.5 \ \text{or}\ -1

Watch out for

  • Signs. −b-b means flip the sign of bb. With b=−3b = -3, −b=3-b = 3.
  • Rounding errors on computers. When b2b^2 is much larger than 4ac4ac, subtracting nearly equal numbers loses precision. This calculator uses the rearranged form from Numerical Recipes to avoid it.

Sources

  • Press, W. H. et al. Numerical Recipes, 3rd edition (2007), section 5.6 "Quadratic and Cubic Equations"

Last checked