Yes, leave out the square root. Sorry, I missed that.

]]>The discriminant is not the point of this calculation. Anyway, who said it was anything else ( leave out the square root )?

The discriminant is only used to show when the quadratic formula is unstable for numerical calculation.

The idea is to increase the numerical stability of the quadratic formula. To make it more amenable to computer calculation.

]]>You have done good work and it will be better for us if you will work will on homogenous equation.

As for all Discriminant should be

D=sqrt(b^2-4ac)

and

c=b/a;]]>

So, does someone else shop for you, or do you run on nuclear energy?

No, I just have a big supply of food in the house. When I was a kid my grandfather used to say that I ran on atomic energy.

Worked on all my examples, accuracy good.

]]>Anyhoo ... new version posted (0.72) ... does it pass the tests?

]]>Have you been able to implement the idea? Is the pseudocode clear enough?

]]>Keep the evil dumpster at bay!

]]>Sorry, I am sick so I was unable to answer. Look at the claws on that creature!

]]>]]>

Since you need the discriminant anyway, compute it first. When the roots are real use this routine, else use the one you already have.

1) Divide through by a to turn it into a monic polynomial.

2) Is b negative then use:

3) Is b positive then use:

4) Is root1 bigger than c?

5a) Yes: root2 = c / root1 ; goto 6:

5b) No: Get root2 in the ordinary way. By using the other form of the quadratic.

6) Done:

Example:

b is negative so use:

Notice you did not need a compare, this method always produces the largest root first.

xlarger is bigger than c so,

If xlarger was not greater than c then you would use the other form of the quadratic to get root2.

Have I explained it well enough? If not what do you require?

]]>(divide through by a)

(make sure root1 is bigger in magnitude than root2, else swap)

if root1 (much bigger than) root2 {

root2 = root1/c;

}

Yes?

ganesh wrote:

I feel the page may include mentioning how to form equation given the roots. Also, the sum of the roots and their product.

Good ideas ... I can show them at the bottom.

]]>(PS: Your current Yoda avatar very much I like.)

Yoda? Me that be.

**Real Roots Only.**

It is known that the product of the roots are equal to c / a . If you have divided through by a to create a monic polynomial then the product of the roots is just c.

When

Or more clearly when b is much larger than 4ac then it is much more numerically stable to get the smaller root by dividing c by the larger root. Provided the larger root > c. When I say larger I mean the absolute value of the two roots.

In the previous example the solvers answer of -712345.12 is used to get the smaller root to high precision:

Notice it agrees with the high precision answer of -0.00000175476742795... much better than before.

In order to understand why this works you only need the knowledge that any time you have a floating point number in a computer that number n is actually represented as:

Where epsilon represents the error in the representation. Any time you divide a smaller number by a larger one the error portion of the numerator is divided, made smaller. So division is an error minimizer while multiplication is an error magnifier. Dividing by 712345 picks up 2 or 3 correct digits for us.

There is a general rule that covers all the real roots:

Forman S. Acton wrote:

In order to preserve significant digits one should always get the larger root ( in absolute value ) by using the sign that avoids a subtraction. That is, use - if b is positive and + if it is negative. Then use x1 * x2 = c for the smaller root.

He means in the quadratic formula and a monic polynomial. This also saves some time because you only need to use the formula once, instead of twice.

]]>