MathsAlgebra

Cubic Equation
solver.

Every cubic has three roots, real or complex, and the curve shows you the real ones.

How it's worked out

The method first moves the curve sideways so the x2x^2 term vanishes. The substitution leaves a simpler cubic in t, called the depressed cubic, with two numbers that carry all the shape.

x\displaystyle x=t−b3a\displaystyle {}= t - \frac{b}{3a}
t3+pt+q\displaystyle t^3 + pt + q=0\displaystyle {}= 0
p\displaystyle p=3ac−b23a2\displaystyle {}= \frac{3ac - b^2}{3a^2}
q\displaystyle q=2b3−9abc+27a2d27a3\displaystyle {}= \frac{2b^3 - 9abc + 27a^2d}{27a^3}

A single number then says which kind of roots you have. It is the discriminant, written Δ.

Δ\displaystyle \Delta=18abcd−4b3d+b2c2\displaystyle {}= 18abcd - 4b^3d + b^2c^2
−4ac3−27a2d2- 4ac^3 - 27a^2d^2

The sign of Δ sorts the cases. Above 0, there are three different real roots. At 0, all are real and at least two match. Below 0, there is one real root and a complex pair.

Each case has its own route. With three real roots, this tool uses cosines and avoids complex numbers on the way. With one real root, Cardano's formula takes cube roots of two real numbers, and dividing out that root leaves a quadratic for the pair. Each real root is then refined with a few steps of Newton's method.

Exact forms use the rational zero theorem: with whole coefficients, any fraction root has a top dividing d and a bottom dividing a. When one exists, dividing it out leaves a quadratic that can be solved exactly.

Worked examples

Ines tries a puzzle from the 1500s

Ines is reading about x3=15x+4x^3 = 15x + 4. MacTutor's history says Cardano's formula led to the square root of −121 here, though x = 4 was known to work. Moved to one side, Δ is 13,068, so all three roots should be real.

The roots are 4 and −2±3-2 \pm \sqrt{3}, or about −3.7321, −0.2679, 4. Bombelli later showed that working through the complex numbers in such a formula still leads to correct real answers.

Open this example in the tool

Ben finds the complex pair of a cubic

Ben's worksheet has x3+6x=20x^3 + 6x = 20. Trying the factors of 20, he finds x = 2 works. Δ is −11,664, so the other two roots cannot be real.

Dividing out that root leaves a quadratic, which gives −1 + 3i and −1 − 3i. As a check, the three roots multiply to 20 and add to 0, which match −da-\frac{d}{a} and −ba-\frac{b}{a}. The factored form is (x − 2)(x² + 2x + 10).

Open this example in the tool

Rosa sizes an open box from a sheet

Rosa cuts squares of side x from the corners of a 10 by 12 sheet and folds up the sides. The volume is x(10−2x)(12−2x)x(10 - 2x)(12 - 2x), which is 4x3−44x2+120x4x^3 - 44x^2 + 120x. She wants a volume of 48, so she needs 4x3−44x2+120x−48=04x^3 - 44x^2 + 120x - 48 = 0.

The roots are about 0.48, 3.61, 6.91. A cut has to be above 0 and less than half the short side, so only 0.48 and 3.61 give a real box. The root at 6.91 is correct as algebra but cuts past the middle of the sheet.

Open this example in the tool

Reading your result

A cubic crosses the axis at least once. With real coefficients, one end of the curve goes up and the other goes down. Complex roots come in conjugate pairs, so the count of real roots is one or three, with repeats counted.

A double root looks like a touch. The curve meets the axis and turns back without crossing. For x3−3x2+4=0x^3 - 3x^2 + 4 = 0, the roots are −1 and 2, with 2 counted twice. That graph has a low point sitting right on the axis.

Turning points come from the slope. They sit where 3ax2+2bx+c=03ax^2 + 2bx + c = 0. When 4b2−12ac4b^2 - 12ac is below 0 there are none, and the curve only climbs or only falls. The curve changes its bend at x=−b3ax = -\frac{b}{3a}, and it is symmetric about that point.

Calculations carry about 15 significant digits. Roots very close together are sensitive, as a near-double pair can only be pinned down to about half of those digits. Coefficients above 106010^{60} are rejected, since cubing them would overflow.

A few cubics and their roots
CubicΔRoots
x³ − 8−1,7282, −1 + 1.732i, −1 − 1.732i
x³ − 3x² + 3x − 101 (×3)
x³ − 7x + 6400−3, 1, 2
x³ + x² + x + 1−16−1, i, −i

Common mistakes

  • Stopping at the first root. A root you can guess is only a start. Divide it out, then solve the quadratic that remains, or the complex pair goes missing.
  • Reading a double root as two different roots. (x − 1)(x − 2)(x − 3) has three separate factors, while a squared factor counts one root twice. The table of roots shows which is which.
  • Thinking the sum check proves everything. For x³ − 6x² + 11x − 6 the roots add to 6, which matches, but three wrong numbers can share that sum. Put each root back as well.
  • Leaving a at 0. Without the x3x^3 term, the equation is a quadratic, and these formulas divide by a. The quadratic solver is the right tool for it.

Questions people ask

Its two ends head in opposite directions, one up and one down, and the curve has no breaks. So it has to pass through 0 somewhere. A curve of even degree, such as a parabola, can stay above the axis, which is why this argument needs an odd degree.

Sources