MathGroup Archive 2000

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Real roots of polynomials

  • To: mathgroup at smc.vnet.net
  • Subject: [mg24729] Re: [mg24688] Real roots of polynomials
  • From: "Ersek, Ted R" <ErsekTR at navair.navy.mil>
  • Date: Wed, 9 Aug 2000 02:31:29 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

Jack Goldberg wanted an efficient way to find all real roots of a
polynomial.  The built-in functions Roots and NRoots can do nothing but find
roots of polynomials.  I hope the developers made these functions work as
efficiently as possible. As expected NRooots runs much faster.  You only
need to do is a little programming to discard the roots with a non-zero
complex part. I give you functions below that work like Roots and NRoots but
only return the real roots. The definition below only works for polynomials
in one variable.

You could if you want give RealRoots all the same options as the built-in
Roots function.

----------------

In[1]:=
RealRoots[lhs_*rhs_,
var_]/;(PolynomialQ[lhs-rhs]&&Variables[lhs-rhs]==={var}):=
  Select[Roots[lhs*rhs, var, Cubics->False,Quartics->False],
(Im[Last[#]]===0)&]

In[2]:=
NRealRoots[lhs_*rhs_,
var_]/;(PolynomialQ[lhs-rhs]&&Variables[lhs-rhs]==={var}):=
  Select[NRoots[lhs*rhs, var], (Im[Last[#]]*  0.0)&]


In[3]:=
RealRoots[2 x^4-3 x^3+x-5*0,x]

Out[3]=
x == Root[-5 + #1 - 3*#1^3 + 2*#1^4 & , 1] || 
x == Root[-5 + #1 - 3*#1^3 + 2*#1^4 & , 2]


In[4]:=
NRealRoots[2 x^4-3 x^3+x-5*0,x]

Out[4]=
x == -1.05796 || x == 1.78349

--------------------
Regards,
Ted Ersek

Mathematica tips, tricks have moved to
http://www.verbeia.com/mathematica/tips/Tricks.html




  • Prev by Date: Re: Real roots of polynomials
  • Next by Date: Re: Mathematica won't solve simple diff. eqn.--Correction
  • Previous by thread: Re: Real roots of polynomials
  • Next by thread: Re: Can I solve PDE in Mathematica?