gizmobench

Cubic Equation Solver

Type a, b, c and d and all three roots appear at once, with the discriminant that decides how many of them are real. x³ - 6x² + 11x - 6 comes back as 1, 2, 3, exactly, because a rational root is recovered as a whole number or a fraction rather than printed as 1.9999999996. (x - 1)³ is reported as 1 with multiplicity 3 instead of three roots that look nearly equal, and x³ + x² + x + 1 as -1, i and -i, with a complex pair kept in surd form: x³ - 1 gives -1/2 + (√3/2)i. When the three roots are real and irrational, which is the one case Cardano's formula cannot reach in real arithmetic, the trigonometric form is used instead, so x³ - 3x + 1 comes back as -1.879385242, 0.3472963553 and 1.532088886 rather than as digits that drifted. Every root is then polished and substituted back into your own equation, and the residual it leaves is printed beside it, so you can see how exact the answer is instead of trusting the digits. The sum and the product of the roots are checked against the coefficients as a second test. It runs in your browser, with no account and nothing uploaded.

a 1 b -6 c 11 d -6Three real, distinctExact roots
x^3 - 6x^2 + 11x - 6 = 0

root 1   x = 1           residual 0
root 2   x = 2           residual 0
root 3   x = 3           residual 0

discriminant 4 > 0, so three distinct real roots
sum of roots 6 = -b/a      product 6 = -d/a
a
b
c
d
Digits
Roots
1, 2, 3
Type
Three real, distinct
Discriminant
4
Max residual
0

Three real, distinct: 1, 2, 3. Largest residual 0.

Coefficients read whole numbers, decimals, fractions like 3/4 and powers of ten like 2.5e9. Set a to 0 and the page solves the quadratic that is left, and says so.

How this one was solved

  1. The coefficients are read as exact rationals: a = 1, b = -6, c = 11, d = -6.
  2. The discriminant 18abcd - 4b³d + b²c² - 4ac³ - 27a²d² is 4, worked out in exact integer arithmetic, so its sign is a fact and not a comparison against a tolerance.
  3. All three roots are real, which is the case Cardano's formula cannot reach in real arithmetic, so the trigonometric form 2*sqrt(-p/3)*cos(acos(3q/(2p)*sqrt(-3/p))/3 - 2*pi*k/3) is used instead, on a depressed cubic scaled by a power of two.
  4. The largest root is polished with Newton's method against your own coefficients and divided out, which is the stable direction, and the remaining quadratic gives the other two.
  5. The rational root theorem recovers 1 exactly, because any rational root has a denominator dividing a: dividing it out leaves a quadratic that is then solved in exact arithmetic.

Each root, put back into your equation

A root is only a root if it makes the left-hand side zero. Each root is substituted back at the full precision it was found to, not at the digits shown above, and the residual is what the left-hand side came to. A residual of a few times ten to the minus sixteen is the last bits of double arithmetic, not a second answer.

  • root 1, x = 1, leaves exactly 0.
  • root 2, x = 2, leaves exactly 0.
  • root 3, x = 3, leaves exactly 0.

Three cubics worth trying

One of each shape a real cubic can have. Loading one keeps the precision you chose.

  • x³ - 6x² + 11x - 6discriminant 4
    1, 2 and 3
  • (x - 1)³discriminant 0
    1 with multiplicity 3
  • x³ + x² + x + 1one real, one complex pair
    -1, i and -i
Accuracy. Roots are found numerically and then substituted back, and each residual is printed beside its root so you can see how close the answer really is rather than trust the digits. Exact integer and rational roots come back exact, and the sum and product are checked against the coefficients as a second test. A cubic whose leading coefficient is zero is solved as a quadratic and the page says that it did.

Common questions

How do you solve a cubic equation?
The equation is divided through by a and the square term is removed by substituting x = t - b/(3a), which leaves the depressed cubic t³ + pt + q. Its discriminant then says what kind of answer to expect. This page computes that discriminant in exact integer arithmetic, so the choice is a fact rather than a comparison against a tolerance, and it then uses the trigonometric form when all three roots are real and Cardano's formula, arranged so that no two nearly equal cube roots are subtracted, when only one is. The largest root is polished with Newton's method against your own coefficients and divided out, and the quadratic that is left gives the other two.
What does the discriminant of a cubic tell you?
The discriminant is 18abcd - 4b³d + b²c² - 4ac³ - 27a²d², and its sign decides the shape of the answer. For x³ - 6x² + 11x - 6 it is 4, above zero, so there are three distinct real roots: 1, 2, 3. For (x - 1)³ it is 0, so roots coincide, and the page says which and how many times. For x³ + x² + x + 1 it is -16, below zero, so there is one real root and one complex conjugate pair: -1, i and -i. The number itself sits in the readout beside the roots, and it is computed from your coefficients as exact integers, so a discriminant of zero really is zero rather than a very small float.
How do I solve x³ - 6x² + 11x - 6 = 0?
Enter a = 1, b = -6, c = 11 and d = -6. The discriminant is 4, which is above zero, so there are three distinct real roots, and they come back as 1, 2, 3 with a residual of 0 beside each one: substituting any of them into the left-hand side gives exactly zero. The page also prints the two checks from the coefficients, that the roots sum to 6 = -b/a and multiply to 6 = -d/a. That cubic is the first of the three worked examples under the calculator, so one press loads it.
Why is a root shown as a fraction or a surd instead of a decimal?
Because that is the exact answer and the decimal is a rounding of it. Coefficients typed as whole numbers, decimals or fractions are held as exact rationals, and once denominators are cleared any rational root has a denominator that divides the leading coefficient, so each polished root is tested against those few candidates in exact integer arithmetic. 2x³ - 3x² - 11x + 6 therefore prints -2, 1/2, 3 rather than -2, 0.4999999999, 3. Dividing an exact root out leaves a quadratic that is also solved exactly, which is where -√2, 1, √2 comes from for x³ - x² - 2x + 2, and -1/2 + (√3/2)i for x³ - 1. The decimal is printed beside the exact form, never instead of it.
What is casus irreducibilis, and why does it change the answer?
It is the case where all three roots are real and irrational. Cardano's formula still holds there, but it asks for the cube root of a complex number, and the real-arithmetic shortcuts that many pages ship instead lose most of their digits. Because the discriminant here is exact, this page can tell that case apart with certainty and switches to the trigonometric form, 2√(-p/3)·cos(acos(3q/(2p)√(-3/p))/3 - 2πk/3), which is stable in double arithmetic. For x³ - 3x + 1 the discriminant is 81 and the roots come back as -1.879385242, 0.3472963553 and 1.532088886, each leaving a residual of at most 4.4e-16.
What is the residual printed next to each root?
It is the left-hand side of your own equation, worked out at that root. A residual of 0 means the root is exact in double arithmetic, which is what the rational and integer roots give. A residual like 4.4e-16 is the last bits of double arithmetic and not a second answer. Each root is substituted back at the full precision it was found to, not at the 6, 10 or 15 digits you chose for the display, and the largest residual sits in its own cell so you can judge the whole answer at a glance.
What happens if a is 0, or if there is a repeated root?
With a = 0 there is no x³ term, so the equation is the quadratic bx² + cx + d = 0. The page solves that instead, names it, and shows its own discriminant: a = 0, b = 1, c = -5, d = 6 becomes x² - 5x + 6 = 0 with roots 2 and 3. With a and b both zero it is a line, and with a, b and c all zero it is either an identity that every number satisfies or a statement nothing satisfies, and both are named rather than left as an empty answer. A repeated root is reported once with its multiplicity: (x - 2)³ gives 2 with multiplicity 3, not three decimals near 1.9999999996.
Can I type fractions, and does the page keep my coefficients?
Fractions like 3/4, decimals like 2.5, powers of ten like 2.5e9, a leading plus, a pasted typographic minus and a thousands separator in a number like 1,000 are all read. Coefficients are accepted up to 1e12; past that the cubed term loses digits the page would then be printing without standing behind them, so it stops and says so. What you type is kept in this browser so the page opens where you left it, and Start over at the top of the page forgets it. Nothing is uploaded, there is no account, and Copy puts the equation, the roots, the discriminant, the working and every residual on your clipboard.

Roots are found numerically and then substituted back, and each residual is printed beside its root so you can see how close the answer really is rather than trust the digits. Exact integer and rational roots come back exact, and the sum and product are checked against the coefficients as a second test. A cubic whose leading coefficient is zero is solved as a quadratic and the page says that it did.