-1

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.

  • Anything with a local minimum / maximum close to the x-axis (short of touching it). When using a constant threshold (on the imaginary component) to decide if a root is real or not, some of the complex roots can "sneak" in. I also don't really trust the minimum absolute imaginary value in these cases. – Alexander Meißner Feb 06 '21 at 14:16
  • Even if I were to provide concrete values for the coefficients, this would not help as floating point arithmetic is not deterministic / implemented differently on various devices (and that is not related to pure mathematics). Also, these instabilities are not the problem, finding a way to avoid judging the result by its numerical value is. – Alexander Meißner Feb 06 '21 at 14:22
  • I am making this up, what for? – Alexander Meißner Feb 06 '21 at 14:23
  • @yves-daoust No need to hide, I know you deleted your comments and down-voted the question. But you still haven't answered why I would make this up and even better, why this would make a mathematical problem invalid / unworthy of being answered. – Alexander Meißner Feb 06 '21 at 14:34
  • 1
    if there really is just one real root, Cardano's method gives a recipe for that root that involves just square roots of reals and cube roots of reals. No mistaking it. – Will Jagy Feb 06 '21 at 17:49

1 Answers1

1

For the general cubic equation $\space ax^3+bx^2+cx+d\space $ the cubic formula provides a single real root allowing the other two roots, real or complex, to be solved by the quadratic equation.

$$x=\sqrt[\Large{3}]{\biggl(\frac{-b^3}{27a^3 }+\frac{bc}{6a^2}-\frac{d}{2a}\biggr)+\sqrt{\biggl(\frac{-b^3}{27a^3}+\frac{bc}{6a^2}-\frac{d}{2a}\biggr)^2+\biggl(\frac{c}{3a}-\frac{b^2}{9a^2}\biggr)^3}}\\ +\sqrt[\Large{3}]{\biggl(\frac{-b^3}{27a^3 }+\frac{bc}{6a^2}-\frac{d}{2a}\biggr)-\sqrt{\biggl(\frac{-b^3}{27a^3}+\frac{bc}{6a^2}-\frac{d}{2a}\biggr)^2+\biggl(\frac{c}{3a}-\frac{b^2}{9a^2}\biggr)^3}}\\-\frac{b}{3a}$$

There will sometimes be complex intermediate results requiring robust software like "D", IDL, Matlab, Octave, and Fortran, Python, or WolframAlpha to resolve. (I know because Excel could sometimes not handle this formula as shown here). The advantage is that, with sufficient variable manipulation, computations can be kept in rational form for however long the programmer chooses.

poetasis
  • 6,338