From: Ross on
Are the formulae for findin the roots of cubic equations on Wikipedia
correct? I've been through it over and over, and simply don't get
roots.

I've gone to the original source, which is:
http://planetmath.org/?op=getobj&from=objects&name=CubicFormula

Just looking at the first equation to calculate r1, then if I have the
cubic x^3 -2x^2 -11x + 12, then I get NaNs when I try to find r1.

Specifically, if I set a1=-2, b1=-11, and c1=12, then the value of
which the square root is taken:
(2*a1^3 - 9*a1*b1 + 27*c1)^2 + 4*(-(a1^2)+3*b1)^3

works out to be negative, leading to the NaN result.

Here's a cut and paste from "bc" where I first confirm that my
variables are set properly, then work out the operand of the square
root.

a1
-2
b1
-11
c1
12
(2*a1^3 - 9*a1*b1 + 27*c1)^2 + 4*(-(a1^2)+3*b1)^3
-190512

Negative!

I've also tried the modified form of these equations from the
Wikipedia page, but I get the same result. NaNs.

I've really tried to find the error in my calculations or reasoning,
but I just can't see any. Are these equations correct? Am I misusing
them?

I can successfully use the method in this page: http://www.1728.com/cubic2.htm.
However, I'd still like to know what I'm doing wrong with the
Wikipedia method.

Any hints/help?
From: Hagen on
> Are the formulae for findin the roots of cubic
> equations on Wikipedia
> correct? I've been through it over and over, and
> simply don't get
> roots.
>
> I've gone to the original source, which is:
> http://planetmath.org/?op=getobj&from=objects&name=Cub
> icFormula
>
> Just looking at the first equation to calculate r1,
> then if I have the
> cubic x^3 -2x^2 -11x + 12, then I get NaNs when I try
> to find r1.
>
> Specifically, if I set a1=-2, b1=-11, and c1=12, then
> the value of
> which the square root is taken:
> (2*a1^3 - 9*a1*b1 + 27*c1)^2 + 4*(-(a1^2)+3*b1)^3
>
> works out to be negative, leading to the NaN result.
>
> Here's a cut and paste from "bc" where I first
> confirm that my
> variables are set properly, then work out the operand
> of the square
> root.
>
> a1
> -2
> b1
> -11
> c1
> 12
> (2*a1^3 - 9*a1*b1 + 27*c1)^2 + 4*(-(a1^2)+3*b1)^3
> -190512
>
> Negative!
>
> I've also tried the modified form of these equations
> from the
> Wikipedia page, but I get the same result. NaNs.
>
> I've really tried to find the error in my
> calculations or reasoning,
> but I just can't see any. Are these equations
> correct? Am I misusing
> them?
>
> I can successfully use the method in this page:
> http://www.1728.com/cubic2.htm.
> However, I'd still like to know what I'm doing wrong
> with the
> Wikipedia method.
>
> Any hints/help?

General remark (I did not check your specific example):
a cubic with real coefficients has either one or three
real zeros. In the latter case you nevertheless have
to work with complex numbers to get the real zeros
using the formula given on PlanetMath.
So most likely you did not make a mistake - just
go on calculating with the complex numbers and at
the end everything will turn out nicely.

H
From: José Carlos Santos on
On 13-01-2010 10:14, Hagen wrote:

> General remark (I did not check your specific example):
> a cubic with real coefficients has either one or three
> real zeros.

The cubic x^3 - x^2 has real coefficients and only two zeros, unless
you count them with multiplicities.

Best regards,

Jose Carlos Santos
From: David C. Ullrich on
On Wed, 13 Jan 2010 00:56:36 -0800 (PST), Ross <rossclement(a)gmail.com>
wrote:

>Are the formulae for findin the roots of cubic equations on Wikipedia
>correct? I've been through it over and over, and simply don't get
>roots.
>
>I've gone to the original source, which is:
>http://planetmath.org/?op=getobj&from=objects&name=CubicFormula
>
>Just looking at the first equation to calculate r1, then if I have the
>cubic x^3 -2x^2 -11x + 12, then I get NaNs when I try to find r1.
>
>Specifically, if I set a1=-2, b1=-11, and c1=12, then the value of
>which the square root is taken:
>(2*a1^3 - 9*a1*b1 + 27*c1)^2 + 4*(-(a1^2)+3*b1)^3
>
>works out to be negative, leading to the NaN result.

No, the square root of a negative number is a complex number.
Complex numbers come into the formula even when the roots
of the original cubic turn out to be real.

This has a lot to do with the history of complex numbers.
Way back then nobody was interested in saying that
x^2 = -1 had a solution because it obviously didn't.
But these funny "imaginary" numbers did arise in the
solution to cubics with _real_ roots - hence they couldn't
be just ignored. At first they were just "imaginary"
temporary things that luckily went away when we got the
final answer - people gradually decided they were interesing
in themselves.

>
>Here's a cut and paste from "bc" where I first confirm that my
>variables are set properly, then work out the operand of the square
>root.
>
>a1
>-2
>b1
>-11
>c1
>12
>(2*a1^3 - 9*a1*b1 + 27*c1)^2 + 4*(-(a1^2)+3*b1)^3
>-190512
>
>Negative!
>
>I've also tried the modified form of these equations from the
>Wikipedia page, but I get the same result. NaNs.
>
>I've really tried to find the error in my calculations or reasoning,
>but I just can't see any. Are these equations correct? Am I misusing
>them?
>
>I can successfully use the method in this page: http://www.1728.com/cubic2.htm.
>However, I'd still like to know what I'm doing wrong with the
>Wikipedia method.
>
>Any hints/help?

From: Ross on
On 13 Jan, 10:14, Hagen <k...(a)itwm.fhg.de> wrote:
> General remark (I did not check your specific example):
> a cubic with real coefficients has either one or three
> real zeros. In the latter case you nevertheless have
> to work with complex numbers to get the real zeros
> using the formula given on PlanetMath.
> So most likely you did not make a mistake - just
> go on calculating with the complex numbers and at
> the end everything will turn out nicely.

There are three formulae on PlanetMath to solve for three roots. These
are for solving a quadratic of the form:

x^3 + ax^2 + bx + c

Which I believe (did I get this wrong?) has at least one real root.

The first does not use i, and the second two do. I assumed (probably
unwisely) that the first equation would find the real root that must
exist, and that the second two find the potentially complex roots,
with i simplifying out in the case that these are real.

I was initially attracted to the equations because they appeared to be
closed form. And because my application (Bezier curves with
constrained end and control points) should always have only one real
root. Hence, and easy solution, I thought, and probably less
computationally expensive than the method I currently have working.
But, it looks like things were not as simple as I thought, no free
lunch etc.