A cubic equation is a polynomial equation of the third degree. The general form is ax^{3}+bx^{2}+cx+d=0, where a ≠ 0.

if(discriminant) > 0 term1 = (b/3.0) else s = r + √ (discriminant) t = r - √ (discriminant) term1 = √ (3.0) * ((-t + s) / 2)

Calculate the roots(x1, x2, x3) of the cubic equation (third degree polynomial), x^{3} - 4x^{2} - 9x + 36 = 0

From the above equation, the value of a = 1, b = - 4, c = - 9 and d = 36.

Find values of q and r q = (3c - b2) / 9 q = ((3*-9) - (-4)2) / 9 = -4.77778

Find value of discriminate, denoted generally as delta(Δ)
discriminant(Δ)= q^{3} + r^{2}
discriminant(Δ) = (-4.77778)^{3} + (-9.62963)^{2} = -16.3333
Here the discriminant value is less than 0

Find term1 and r_{13}
If Δ< 0, term1 = (b/3.0) = -4 / 3 = -1.33333
term1 = -1.33333
r_{13} = 2 * √(q)
where, q = -q = 4.77778
r_{13} = 2 * √ 4.77778 = 4.371626

To Substitute term1 and r_{13} values to Cubic formula
x_{1} = -term1 + r_{13} * cos(q^{3} / 3)
x_{1} = 1.33333 + 4.371626 x cos(4.77778^{3} / 3) = 4
x_{2} = -term1 + r_{13} * cos(q^{3} + (2 * ∏) / 3)
x_{2} = 1.33333 + 4.371626 x cos(4.77778^{3} + (2 * ∏)/ 3) = -3
x_{3} = -term1 + r_{13} * cos(q^{3} + (4 * ∏) / 3)
x_{3} = 1.33333 + 4.371626 x cos(4.77778^{3} + (4 * ∏)/ 3) = -3

We get the roots, x1 = 4, x2 = -3 and x3 = -3. This is an example for real roots in the cubic equation.