Equationpedia

Quadratic Formula

The quadratic formula finds the values that make a quadratic polynomial zero. The discriminant inside the square root tells you whether a polynomial with real coefficients has two real roots, a repeated real root, or a complex conjugate pair.

Choose the same sign
Compute the first root
Recover the other root
q=−b+sgn⁡(b)Δ2,x1=qa,x2=cq\htmlData{region=stable-numerator}{\htmlData{term=intermediate}{q}=-\frac{\htmlData{term=linear-coefficient}{b}+\htmlData{term=sign}{\operatorname{sgn}}(\htmlData{term=linear-coefficient}{b})\sqrt{\htmlData{term=discriminant}{\Delta}}}{2}},\qquad \htmlData{region=first-root}{\htmlData{term=root}{x}_1=\frac{\htmlData{term=intermediate}{q}}{\htmlData{term=quadratic-coefficient}{a}}},\quad \htmlData{region=second-root}{\htmlData{term=root}{x}_2=\frac{\htmlData{term=constant-coefficient}{c}}{\htmlData{term=intermediate}{q}}}

Notes

Find the two candidates

Put the equation in the form ax2+bx+c=0ax^2+bx+c=0, with a≠0a\ne0. The expression b2−4acb^2-4ac is called the discriminant. In the displayed formula, try the plus sign once and the minus sign once. For x2−5x+6=0x^2-5x+6=0, the discriminant is 25−24=125-24=1. The two choices give (5+1)/2=3(5+1)/2=3 and (5−1)/2=2(5-1)/2=2.

Keep a=1a=1 and b=−5b=-5 and increase cc to 25/425/4. The discriminant becomes zero, and the two answers meet at x=5/2x=5/2. Increase cc to 77. Now the discriminant is negative, and the square root contributes an imaginary part.

See where the square root comes from

Switch to Completed-square form. Divide the original equation by aa, move the constant term to the right, and add (b/(2a))2(b/(2a))^2 to both sides. The left side is now the square of a single shifted variable. Taking both square roots and rearranging produces the standard formula. The midpoint of the two roots is −b/(2a)-b/(2a).

Calculate roots with very different magnitudes

When b2b^2 is much larger than ∣4ac∣|4ac|, the square root can be nearly the same size as ∣b∣|b|. Subtracting those nearly equal numbers can lose digits of the smaller root in floating-point arithmetic. The Real roots with less cancellation form first computes the root whose numerator adds magnitudes. The product of both roots is c/ac/a, which then gives the other root by division.

For x2+108x+1=0x^2+10^8x+1=0, the two roots are approximately −108-10^8 and −10−8-10^{-8}. The second root is small enough that the standard subtraction is sensitive to rounding. When b=0b=0, the roots are symmetric about zero and the direct square-root form avoids that subtraction.

Sources

Quadratic Formula (Real roots with less cancellation) merch