5
$\begingroup$

Well the formula for solving a Quadratic equation is :

$$\text{If }\space ax^2+bx+c=0$$

then

$$x=\dfrac{-b \pm \sqrt{b^2 -4ac} }{2a}$$

But looking at this : [Wolfram Mathworld] (And also in other places)

They give An Alternate Formula:

$$x=\dfrac{2c}{-b \pm \sqrt{b^2 -4ac}}$$

How does one get this?

Also in the first formula (the one we know) , $a \neq 0$ ... but here is it still the case?

Please help, Thanks!

$\endgroup$
5
  • 1
    $\begingroup$ consider multiplying the numerator and denominator by the conjugate of the numerator (that is -b /mp sqrt(b^2-4ac)) $\endgroup$
    – Winston
    Commented Jun 26, 2015 at 15:49
  • $\begingroup$ @Winston Edit your $\LaTeX$ and ... Thanks! $\endgroup$
    – NeilRoy
    Commented Jun 26, 2015 at 15:51
  • $\begingroup$ Something seems wrong with the new formula. If $c=0$, we get one valid root, and another with denominator $0$.?? $\endgroup$ Commented Jun 26, 2015 at 15:55
  • $\begingroup$ In the new formula, you have the two restrictions $a \neq 0$, $c \neq 0$, because otherwise the denominator is $0$. $\endgroup$
    – Théophile
    Commented Jun 26, 2015 at 15:57
  • $\begingroup$ @ghosts_in_the_code Haha I know...that's why i am asking the validity of this formula! $\endgroup$
    – NeilRoy
    Commented Jun 26, 2015 at 15:57

5 Answers 5

3
$\begingroup$

The alternate form can be very useful to improve numeric precision or stability in some cases; for instance, if $a$ is much smaller in magnitude than $b$ and $c$, the formula is very close to being linear. In such cases, one root is much smaller in magnitude than the other, and in practical cases, that's often the one of interest. But, in the conventional formula, that 'near' root is found by taking the difference of two values which are very close in magnitude, which can result in loss of precision.

Consider an example which arises in optics: given a sphere radius $R$ centred at $(0,0,R)$ we want to find where it intersects a line described parametrically as $\mathbf{x} = \mathbf{x}_0 + s\mathbf{d}$; and (relative to $R$) we know the ray is reasonably close to, and roughly parallel to, the $z$ axis, and we are interested in the intersection closer to the $z=0$ plane. It's assumed that $\mathbf{x}_0$ is close to this plane, too, so this will be the solution with a smaller magnitude of $s$.

Solved by plugging the parametric line into ${x_x}^2 + {x_y}^2 + (x_z-R)^2=R^2$, and expanding; this leads to a quadratic in $s$ : $$\begin{align} as^2 + bs + c & = 0 \\ a & = \mathbf{d} \cdot \mathbf{d} \\ b & =2(\mathbf{x}_0 \cdot \mathbf{d} - R d_z) \\ c & =\mathbf{x}_0 \cdot \mathbf{x}_0 - 2 R {x_0}_z \end{align}$$

In some cases $R$ can be very large (for a barely curved lens); or large and negative (concave vs convex); and we may want to explore the effect of changing from a slighly convex to slighly concave surface, including the intermediate 'flat' situation. And it's much better if the calculations are continuous through that space. So, we can define 'curvature' $C=1/R$, and then divide all three coefficients by $R$:

$$\begin{align} a & = C\mathbf{d} \cdot \mathbf{d} \\ b & = 2(C \mathbf{x}_0 \cdot \mathbf{d} - d_z) \\ c & = C \mathbf{x}_0 \cdot \mathbf{x}_0 - 2 {x_0}_z \end{align}$$

Now we have a situation where $a$ becomes small as $C$ tends to zero; and it's essential to use the 'alternate' form to find $s$; the quadratic equation we are solving tends to linear as $a$ tends to zero; at which point the solution is just $s=-c/b$; and the 'alternate' formula clearly gives this result at that limit (with proper choice of the sign of the radical) while the 'conventional' form tends to 0/0. So $C=0$ is no longer a special case, it's continuous with slightly negative and slightly positive $C$ (and we can, for instance, evaluate an analytic derivative for $\frac{ds}{dC}$ even at $C=0$, if needed for non-linear optimization).

For small $C$, the sign of $b$ is determined by the sign of the $z$ component of $\mathbf{d}$ -- is the ray going up or down? -- something which is known to the solving framework, and the 'near' root is the one obtained when the radical has the same sign as $d_z$, even as $C$ changes sign.

$\endgroup$
2
$\begingroup$

Consider the quadratic $ax^2 + bx + c$. If $a = 0$, then finding the root is easy and boring, so we only look at the case when $a \neq 0$.

One way to get at the original quadratic formula is to complete the square. That is, note that $$\begin{align} ax^2 + bx + c &= a\left(x^2 + \frac{b}{a} x + \frac{c}{a}\right) \\ &= a \left(x^2 + \frac{b}{a} x + \frac{b^2}{4a^2} - \frac{b^2}{4a^2} + \frac{c}{a} \right) \\ &= a \left( \left( x + \frac{b}{2a} \right)^2 + \frac{4ac - b^2}{4a^2} \right). \end{align}$$ So when looking for solutions to $ax^2 + bx + c = 0$, we are looking at solutions to $$ 0 = a \left( \left( x + \frac{b}{2a} \right)^2 + \frac{4ac - b^2}{4a^2} \right) = a\left( x + \frac{b}{2a}\right)^2 + a\frac{4ac - b^2}{4a^2},$$ or equivalently $$ \left(x + \frac{b}{2a} \right)^2 = \frac{b^2 - 4ac}{4a^2}.$$ Taking square roots and solving for $x$ gives the original quadratic formula.

Now let us derive the alternate form. Notice that if $c = 0$ then $x = 0$ is a root and $x = -b/a$ is the other root. So let us now consider $c \neq 0$. We now know that $x = 0$ is not a root. This means that if $r$ is a root of $ax^2 + bx + c = 0$, then $\frac{1}{r}$ will be a root of $a \frac{1}{x^2} + b \frac{1}{x} + c = 0$. Multiplying through by $x^2$ (which makes sense because we are not interested in $x = 0$), we are interested in reciprocals of the roots of $$ a + bx + cx^2 = 0.$$ The original quadratic formula applies, and we know the roots are $$ x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2c}.$$ Since we are interested in the reciprocals, we find the roots to be $$ x = \frac{2c}{-b \pm \sqrt{b^2 - 4ac}}.$$

This isn't necessarily the best derivation, but I like it. $\diamondsuit$

$\endgroup$
6
  • $\begingroup$ Thanks man! : But three more proofs [goo.gl/F36dd8 , goo.gl/r8kGVQ , goo.gl/4C3k6Q] ... !!! $\endgroup$
    – NeilRoy
    Commented Jun 26, 2015 at 16:39
  • $\begingroup$ But what about my $2^{\text{nd}}$ question? That is what if $a=0$ and $c=0$ ? $\endgroup$
    – NeilRoy
    Commented Jun 26, 2015 at 16:41
  • $\begingroup$ Then you're looking at $bx = 0$, which is a linear polynomial with solution $x = 0$. $\endgroup$
    – davidlowryduda
    Commented Jun 26, 2015 at 16:42
  • $\begingroup$ No what i meant was if $c=0$ then by the new formula $x=0$ which is not the case with the familiar formula. Also in the familiar formula if $a=0$ then $x$ is undefined but that does not seem to be the case in the new one...So..??? $\endgroup$
    – NeilRoy
    Commented Jun 26, 2015 at 16:44
  • 1
    $\begingroup$ I stated explicitly what assumptions were necessary where. You do not use any quadratic formula if $a = 0$ because you do not have a quadratic. If $c = 0$, then read the paragraph including Notice that if $c = 0$... $\endgroup$
    – davidlowryduda
    Commented Jun 26, 2015 at 16:46
2
$\begingroup$

I would like to add some point to answer posted user @mixedmath.

For equation $$ ax^2 + bx + c = 0 $$

roots are

$$ x = \frac {-b\ \pm \ \sqrt {b^2 - 4ac} }{2a} $$

Lets put $$ y = \frac {1}{x} $$

Then we get converted equation as, $$ cy^2 + by + a = 0 $$

Equivalent roots are, $$ y = \frac {-b\ \mp \ \sqrt {b^2 - 4ac} }{2c} $$

And thus if you invert to get values of $x$ then those are,

$$ x = \frac{1}{y} = \frac{2c}{-b \mp \sqrt{b^2 -4ac}} $$

Do note the difference between the signs $\pm$ and $\mp$.

You can verify that by trying to equate both sides as follows:

$$ \frac{-b \pm \sqrt{b^2 - 4ac}}{2a} = \frac{2c}{-b \mp \sqrt{b^2 - 4ac}} $$

Lets take one sign at a time. Lets choose $+$ from left side, this $-$ from right. It becomes,

$$ \frac{-b + \sqrt{b^2 - 4ac}}{2a} = \frac{2c}{-b - \sqrt{b^2 - 4ac}} $$ $$ (-b)^2 - (\sqrt{b^2 -4ac})^2 = 4ac $$ $$ b^2 - b^2 + 4ac = 4ac $$ $$ 4ac = 4ac $$

Thus things are in correct place.

Lets verify with one quick example.

Consider a quadratic equation as follows,

$$ f(x) = (x-3)(2x-5) = 2x^2 - 11 x + 15 = 0 $$

According to first formula we get values as follows, $$ x = \frac{11 \pm 1}{4} $$

$$ \{x_+, x_-\} = \{3, \frac{5}{2}\} $$

And with second formula we get, $$ x = \frac{30}{11 \mp 1} $$ $$ \{x_+, x_-\} = \{\frac{5}{2}, 3\} $$

$\endgroup$
2
$\begingroup$

\begin{align} \dfrac{-b \pm \sqrt{b^2 -4ac} }{2a} &= \dfrac{-b \pm \sqrt{b^2 -4ac} }{2a} \cdot \frac{-b \mp \sqrt{b^2 -4ac}}{-b \mp \sqrt{b^2 -4ac}} \\ &= \dfrac{b^2-(b^2-4ac)}{2a(-b \mp \sqrt{b^2 -4ac})} \\ &= \dfrac{4ac}{2a(-b \mp \sqrt{b^2 -4ac})} \\ &= \dfrac{2c}{-b \pm \sqrt{b^2 -4ac}} \\ \end{align}

Note that, in order to take the last step, we must have $a \ne 0$.

$\endgroup$
0
$\begingroup$

The alternative formula can be obtained from the conventional formula quite easily...

(This assumes $a$,$c$ both non-zero...)

The quadratic with roots $\alpha,\beta$: $$ a x^2 + b x + c = 0 $$ can also be written in terms of $a$ and its roots: $$ a (x-\alpha)(x-\beta) = 0 $$ Expanding... $$ ax^2 - a(\alpha+\beta)x + a\alpha\beta = 0 $$

And so $c = a\alpha\beta$, since this is an identity in $x$;

Thus if one root is $\alpha$, the other is $$\beta = \dfrac {c} {a \alpha} $$

And if

$$\alpha=\dfrac{-b \pm \sqrt{b^2 -4ac} }{2a}$$

Then

$$ \beta = \dfrac {c} {a} \dfrac{2a} {-b \pm \sqrt{b^2 -4ac} } \\ = \dfrac{2c} {-b \pm \sqrt{b^2 -4ac} } $$

... which is the 'alternative formula', giving the other root. Change $\pm$ to $\mp$ to get the corresponding root.

As alluded to in my other answer, in a floating point calculation, you can choose the radical with the opposite sign from $b$ when evaluating $-b \pm \sqrt{b^2 -4ac}$, and then use that to obtain one root from each of the two formulae; this can reduce numerical precision issues when $\lvert {ac}\rvert$ is much smaller than $b^2$.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .