can I use this library to solve a cubic equation?

May 20, 2013 at 5:01 PM
I have an equation of this form:

0 = at^3+bt^2+ct+d

I know a, b, c, and d but need to find a valid real value of t ranged [0, 1]. Can this library solve this for me?
Coordinator
May 22, 2013 at 10:21 PM
The next release is supposed to support this. You can already test it in the current codebase though. Feedback on it would be welcome, as we can still change it completely until released. We do not yet provide specific polynomial root solvers but if you know a close enough range to a single root (you mentioned [0,1]) the generic root solvers may work as well to find real roots:

Since you know the form, we can leverage its derivative 3at^2+2bt+c. Or we can use a variant that doesn't need the derivative. Both methods accept an optional accuracy parameter (default 10^-8):
RealRoots.OfFunctionAndDerivative(t => Evaluate.Polynomial(t,d,c,b,a), t =>  Evaluate.Polynomial(t,c,2*b,3*a), 0, 1);
RealRoots.OfFunction(t => Evaluate.Polynomial(t,d,c,b,a), 0, 1);
Alternatively you can use the algorithms from the Algorithms namespace directly which also offer some more parameters. See the unit tests for brent and hybrid newton-raphson