polylib::realroots

Isolate all real roots of a real univariate polynomial

Use only in the MuPAD Notebook Interface.

This functionality does not run in MATLAB.

Syntax

polylib::realroots(p)
polylib::realroots(p, eps)

Description

polylib::realroots(p) returns intervals isolating the real roots of the real univariate polynomial p.

polylib::realroots(p, eps) returns refined intervals approximating the real roots of p to the relative precision given by eps.

All coefficients of p must be real and numerical, i.e., either integers, rationals or floating-point numbers. Numerical symbolic objects such as sqrt(2), exp(10*PI) etc. are accepted, if they can be converted to real floating-point numbers via float. The same holds for the precision goal eps.

The isolating intervals are ordered such that their centers are increasing, i.e., ai + bi < ai + 1 + bi + 1.

The number nops(realroots(p)) of intervals is the number of real roots of p. Multiple roots are counted only once. Cf. Example 3.

Isolating intervals may be quite large. The optional argument eps may be used to refine the intervals such that they approximate the real roots to a relative precision eps. With this argument the returned intervals satisfy , i.e., each center approximates a root with a relative precision eps/2.

    Note:   Some care should be taken when trying to obtain highly accurate approximations of the roots via small values of eps. Internally, bisectioning with exact rational arithmetic is used to locate the roots to the precision eps. This process may take much more time than determining the isolating intervals without using the second argument eps in polylib::realroots. It may be faster to use moderate values of eps to obtain first approximations of the roots via polylib::realroots. These approximations may then be improved by a fast numerical solver such as numeric::fsolve with an appropriately high value of DIGITS. Cf. Example 6. However, note that polylib::realroots will always succeed in locating the roots to the desired precision eventually. Numerical solvers may fail or return a root not belonging to the interval which was used for the initial approximation.

    Note:   Unexpected results may be obtained when the polynomial contains irrational coefficients. Internally, any such coefficient c is converted to a floating-point number. This float is then replaced by an approximating rational number r satisfying . Finally, polylib::realroots returns rigorous bounds for the real roots of the rationalized polynomial. Despite the fact that all coefficients are approximated correctly to DIGITS decimal places this may change the roots drastically. In particular, multiple roots or clusters of poorly separated simple roots are very sensitive to small perturbations in the coefficients of the polynomial. See Example 4 and Example 5.

Environment Interactions

The function is sensitive to the environment variable DIGITS, if there are non-integer or non-rational coefficients in the polynomial. Any such coefficient is replaced by a rational number approximating the coefficient to DIGITS significant decimal places.

Examples

Example 1

We use a polynomial expression as input to polylib::realroots:

p := (x - 1/3)*(x - 1)*(x - 4/3)*(x - 2)*(x - 17):
polylib::realroots(p)

The roots 1 and 2 are found exactly: the corresponding intervals have length 0. The other isolating intervals are quite large. We refine the intervals such that they approximate the roots to 12 decimal places. Note that this is independent of the current value of DIGITS, because no floating-point arithmetic is used:

polylib::realroots(p, 10^(-12))

We convert these exact bounds for the real roots to floating point approximations. Note that with the default value of DIGITS=10 we ignore 2 of the 12 correct digits the rational bounds could potentially give:

map(%, map, float)

delete p:

Example 2

Orthogonal polynomials of degree n have n simple real roots. We consider the Legendre polynomial of degree 5, available in the library orthpoly for orthogonal polynomials:

polylib::realroots(orthpoly::legendre(5, x), 10^(-DIGITS)):
map(%, float@op, 1)

Example 3

We consider a polynomial with a multiple root:

p := poly((x - 1/3)^3*(x - 1), [x])

Note that only one isolating interval [0, 1] is returned for the triple root :

polylib::realroots(p)

delete p:

Example 4

We consider a polynomial with non-rational roots:

p := (x - 3)^2*(x - PI)^2:

Converting the result of polylib::realroots to floating-point numbers one sees that the exact roots 3, 3, PI, PI are approximated only to 3 decimal places:

map(polylib::realroots(p, 10^(-10)), map, float)

This is caused by the internal rationalization of the coefficients of p.

The intervals returned by polylib::realroots(p, 10^(-10)) correctly locate the 4 exact roots of this rationalized polynomial to a precision of 10 digits. However, because all 4 roots are close, the small perturbations of the coefficients introduced by rationalization have a drastic effect on the location of the roots. In particular, rationalization splits the two original double roots into 4 simple roots.

delete p:

Example 5

We consider a further example involving non-exact coefficients. First we approximate the roots of a polynomial with exact coefficients:

p1 := (x - 1/3)^3*(x - 4/3):
map(polylib::realroots(p1, 10^(-10)), map, float)

Now we introduce roundoff errors by replacing one entry by a floating-point approximation:

p2 := (x - 1.0/3)^3*(x - 4/3):
map(polylib::realroots(p2, 10^(-10)),map,float)

In this example rationalization caused the triple root 1/3 to split into one real root and two complex conjugate roots.

delete p1, p2:

Example 6

We want to approximate roots to a precision of 1000 digits:

p := x^5 - 129/20*x^4 + 69/5*x^3 - 14*x^2 + 12*x - 8:

We recommend not to obtain the result directly by polylib::realroots(p,10^(-1000)), because the internal bisectioning process for refining crude isolating intervals converges only linearly. Instead, we compute first approximations of the roots to a precision of 10 digits:

approx := map(polylib::realroots(p, 10^(-10)), float@op, 1)

These values are used as starting points for a numerical root finder. The internal Newton search in numeric::fsolve converges quadratically and yields the high precision results much faster than polylib::realroots:

DIGITS := 1000:
roots := map(approx, x0 -> numeric::fsolve([p = 0], [x = x0]))
[[x = 1.489177598846870281338916114673844643894...],
      [x = 1.752191733304413195335101727880090131407...],
      [x = 3.255184555797733438479691333705558491124...]]
[[x = 1.489177598846870281338916114673844643894669835092536119855751693956799904640967549560442110885879232792036010157376720692094324111786567214138671874261338975137998588350095241431631565187958695010130793702827598417889570405343679809195640015438825256423395897317389807927124677048330217185611560160852949992227406316182545396959580280039176037893465855100112382490403103132724393616779034962398657208600132617165954526920236060891430759487625019610374836173025321970552718158822415292019163595043038518384220935972705028945477611475456543388775415466506093811559041063856006743047391776252263444838496706251092035519123766100060810337234190300575428179699397139981402959287942445972759456788519494970776302060047976207990590536517723588654042513954627703954447424230553712144203972480937064497714814500525699902386158552408504404678791694443289789026179257765462709367657630154178036477084236082463141125701214255658949045941081934384364512661126502777097360076809448945203966036936280487253224654608], [x = 1.752191733304413195335101727880090131407549255515946934886764975651528596777530139413027435700423178244012697737775925621169736628313633997119505028761410216547335233826887861790928537905139058441929148638899149921505613428169691594602388717600259860926710864020433335448794046293611575781565167962372525926069504840851131390737978114430473697673816705234767912809890014003914976808633651834853631436815063324805697103241380997436857747515137471824463854839004250763168068588448731030267011174851675260422203349487957694482765216217015555922421918010316929557493585973791003156902126421536687885155637156649050559324198033629515731291712192561327919511278426097398953140543612746520713342053540508449972305165390201261248930256695979113038130147199291994172241517326458580743869944116246839565688551946466979875784631061105546330404293266633837352787587999372999591259356737176858916197613556277960580007442661331655773004119277434679177317819490401279207713738708261765181821319279893839133154762074], [x = 3.255184555797733438479691333705558491124209926859892564938063100419466261488128732686451213396333322617928251096414152612204311659235057154121461289645564926706534034040354272934983953885755648723124912641750396686963968879800490426406784014540438219601734309844079205377950906863614781980930362002424753226352889306940655384188687727687766682007117632290790288688315625071811266922067993880913395310900251109669521901121942045171078585942718340681491511995281225223196693741042061550942716375341151088544751106063443454387747953479632918330311701872965076329895242573555032127634302926766144743800194834055314047503968597941834265422530951202061927796631225684730893107438468467391489980566249653914618030897041865976175003969473002624845045964053461161213538343955694971074978966404467944879471468039587838882141108248251474943918652436220475150264776606271197491386961045569766572956982698254325393750664302906859512563136201163981425062596937476261563890184440432634365619648197679579875533149547]]
delete approx, DIGITS, roots, x0:

Parameters

p

A univariate polynomial: either an expression or a polyomial of domain type DOM_POLY.

eps

A (small) positive real number determining the size of the returned intervals.

Return Values

List of lists [[a1, b1], [a2, b2], …] with rational numbers aibi is returned. Lists with ai = bi represent exact rational roots. Lists with ai < bi represent open intervals containing exactly one real root. If the polynomial has no real roots, then the empty list [ ] is returned.

Was this topic helpful?