Index / Angle of the Real Root in a Cubic Equation. I am trying to find the roots of a general cubic equation, but with a twist: In case there is only one real root (the discriminant of the polynomial is less than zero), I want to separate the real root from the pair of complex conjugate roots and treat them differently (replace them by other complex roots specific to the actual problem I am solving).

Mark Rosales

Mark Rosales

Answered question

2022-11-04

Index / Angle of the Real Root in a Cubic Equation
- I am trying to find the roots of a general cubic equation, but with a twist:
In case there is only one real root (the discriminant of the polynomial is less than zero), I want to separate the real root from the pair of complex conjugate roots and treat them differently (replace them by other complex roots specific to the actual problem I am solving).
- I also want to stick to complex numbers (as opposed to explicit trigonometry) because I have to factor out all divisions at the end to represent the roots as homogeneous coordinates.
I currently use the approach described on Wikipedia. But because I use floating point arithmetic (not real numbers) it suffers from a bit of numeric instability, which makes it hard to tell which of the three results was supposed to be the real root (in case the curve is really flat and they are all close to the real line).
My current approach selects the root with the smallest absolute imaginary component. However I think there should be a better way to tell them apart before calculating the result, maybe related to the angles of the root of unity, so that I can get the index (k) of the real root ( x k ) sooner.

Answer & Explanation

Paskcreessy4k5

Paskcreessy4k5

Beginner2022-11-05Added 20 answers

Step 1
For the general cubic equation   a x 3 + b x 2 + c x + d   the cubic formula provides a single real root allowing the other two roots, real or complex, to be solved by the quadratic equation.
x = ( b 3 27 a 3 + b c 6 a 2 d 2 a ) + ( b 3 27 a 3 + b c 6 a 2 d 2 a ) 2 + ( c 3 a b 2 9 a 2 ) 3 3 + ( b 3 27 a 3 + b c 6 a 2 d 2 a ) ( b 3 27 a 3 + b c 6 a 2 d 2 a ) 2 + ( c 3 a b 2 9 a 2 ) 3 3 b 3 a
Step 2
There will sometimes be complex intermediate results requiring robust software like "D", IDL, Matlab, Octave, and Fortran, Python, or WolframAlpha to resolve. The advantage is that, with sufficient variable manipulation, computations can be kept in rational form for however long the programmer chooses.

Do you have a similar question?

Recalculate according to your conditions!

Ask your question.
Get an expert answer.

Let our experts help you. Answer in as fast as 15 minutes.

Didn't find what you were looking for?