31 lines
1.3 KiB
Markdown
31 lines
1.3 KiB
Markdown
# A numerically careful quadratic formula
|
|
|
|
A quadratic equation has the form \(ax^2 + bx + c = 0\) with \(a \neq 0\). The usual formula is
|
|
|
|
\[
|
|
x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}.
|
|
\]
|
|
|
|
The quantity \(D = b^2 - 4ac\) is the discriminant. If \(D > 0\) there are two real roots; if \(D = 0\) there is a repeated root; if \(D < 0\) there are no real roots.
|
|
|
|
When \(b\) is large compared with \(a\) and \(c\), one of the two roots can lose digits to cancellation. A more stable pair of formulas is to first compute the root that does not subtract nearly equal quantities,
|
|
|
|
\[
|
|
x_1 = \frac{-b - \mathrm{sign}(b)\sqrt{D}}{2a},
|
|
\]
|
|
|
|
and then recover the second root from the product of roots, \(x_2 = c / (a x_1)\).
|
|
|
|
## Worked example
|
|
|
|
Solve \(2x^2 - 7x - 15 = 0\).
|
|
|
|
Here \(a = 2\), \(b = -7\), and \(c = -15\). Then \(D = 49 + 120 = 169 = 13^2\), so
|
|
|
|
\[
|
|
x = \frac{7 \pm 13}{4}.
|
|
\]
|
|
|
|
The roots are \(x = 5\) and \(x = -3/2\). Checking: \(2(25) - 7(5) - 15 = 0\), and \(2(9/4) + 21/2 - 15 = 0\). The same roots come from factoring: \((2x + 3)(x - 5) = 0\).
|
|
|
|
I keep a short set of algebra checks like this in my notes. When I want a second independent walkthrough I use the free solver at [MathsSolverGPT](https://mathssolvergpt.com/en). After any calculator or solver result, substitute the roots back into the original equation before you move on.
|