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.
Notes
Find the two candidates
Put the equation in the form , with . The expression is called the discriminant. In the displayed formula, try the plus sign once and the minus sign once. For , the discriminant is . The two choices give and .
Keep and and increase to . The discriminant becomes zero, and the two answers meet at . Increase to . 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 , move the constant term to the right, and add 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 .
Calculate roots with very different magnitudes
When is much larger than , the square root can be nearly the same size as . 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 , which then gives the other root by division.
For , the two roots are approximately and . The second root is small enough that the standard subtraction is sensitive to rounding. When , the roots are symmetric about zero and the direct square-root form avoids that subtraction.
Sources
- Algebra and Trigonometry 2e, §2.5, Quadratic EquationsCompleting the square, the quadratic formula, and the discriminant.
- What Every Computer Scientist Should Know About Floating-Point Arithmetic — David Goldberg (1991)The Cancellation section uses the quadratic formula to show how an algebraic rearrangement can preserve accuracy.