Coefficients
- Cubic coefficient (not zero)
- Quadratic coefficient
- Linear coefficient
- Constant term
Maths · sample calcsheet · 4 pages
Finding every real root of a cubic f(x) = a₃x³ + a₂x² + a₁x + a₀. A cubic has at least one real root and at most three. This sheet finds them numerically with the built-in root(f, a, b), which needs only a bracket [a, b] where f changes sign, then confirms them two independent ways: Vieta's relations between the roots and the coefficients, and the trigonometric closed form that applies when all three roots are real. The coefficients are the only inputs — change them and the whole sheet re-solves.

root(f, a, b) returns one root inside the bracket [a, b] and insists that f(a) and f(b) have opposite signs — Brent's method then cannot miss. Tabulating f at a few integers shows where the sign flips: between 0 and 1, between 1 and 2, and between 3 and 4 (not between 2 and 3, where f stays negative). Three sign changes, three real roots, one bracket each.
The first argument is the function itself (f, not f(x)); the other two are the bracket ends. A bracket may contain only one root — a wide one such as [0, 4] still returns a single root, whichever the iteration lands on.
For a₃(x − x₁)(x − x₂)(x − x₃) expanded, the roots' sum, pairwise products and product must equal −a₂/a₃, a₁/a₃ and −a₀/a₃. Three identities the three numerical roots have to satisfy together.
Substituting x = t + x_sh with x_sh = −a₂/(3a₃) removes the square term and leaves the depressed cubic t³ + p·t + q = 0. Its discriminant Δ = (q/2)² + (p/3)³ says how many real roots there are: Δ < 0 means three distinct real roots. In that case every root is a cosine — Viète's trigonometric form — which sidesteps the complex cube roots Cardano's formula would need (the casus irreducibilis).