cubic_roots.m

From Spinach Documentation Wiki
Jump to: navigation, search

Real roots of a cubic polynomial in the unit interval. The coefficient vector is first scaled by its largest absolute element, so that root_tol acts as a relative tolerance; an all-zero coefficient vector returns an empty answer. Leading coefficients smaller than root_tol are dropped, which degrades the cubic to a quadratic or a linear problem when the leading coefficients are numerically zero. The roots of the reduced polynomial are obtained with the Matlab roots function, those with an imaginary part below root_tol are taken as real, the ones outside [-root_tol,1+root_tol] are discarded, the survivors are clamped into [0,1] and sorted, and roots closer to each other than root_tol are merged into one.

Syntax

    root_list=cubic_roots(poly_coeffs,root_tol)

Parameters

    poly_coeffs - four real coefficients [a b c d] of
                  a*x^3+b*x^2+c*x+d

       root_tol - positive real root filtering tolerance

Outputs

    root_list   - sorted row vector of real roots in [0,1]

Notes

A compiled MEX implementation of the same function ships in kernel/eigenfields as cubic_roots.mexa64 and cubic_roots.mexw64, built from cubic_roots.cpp. Matlab gives a MEX file precedence over an .m file of the same name in the same directory, so the Matlab source above is the reference implementation rather than the one that normally executes.

See also

eigenfields.m, rootmatch.m, voitlander.m, Kernel utilities

Version 2.13, authors: Ilya Kuprov