MathGroup Archive 2002

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

Search the Archive

RE: RE: Re: ALL roots of non-polynomial equation

  • To: mathgroup at smc.vnet.net
  • Subject: [mg36012] RE: [mg35996] RE: [mg35942] Re: [mg35926] ALL roots of non-polynomial equation
  • From: "David Park" <djmp at earthlink.net>
  • Date: Mon, 12 Aug 2002 03:34:29 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

Bobby,

Ted Ersek has a package on MathSource called Rootsearch that is pretty
decent at finding roots. Here is how it works on your examples.

<< Enhancements`Rootsearch`

RootSearch[Sin[x] + 1 == 0, {x, -30, 30}]
{{x -> -26.7035}, {x -> -20.4204}, {x -> -14.1372}, {x -> -7.85398},
{x -> -1.5708}, {x -> 4.71239}, {x -> 10.9956}, {x -> 17.2788}, {x ->
23.5619}, {x -> 29.8451}}

The last example is of course more difficult because there are an infinite
number of roots clustered around zero. However, if we want to find the roots
in a given range:

roots = RootSearch[1 + Sin[1/x] == 0, {x, 0.005, 0.01}]
Length[roots]
{{x -> 0.00501275}, {x -> 0.00517577}, {x -> 0.00534975}, {x ->
      0.00553582}, {x -> 0.00573531}, {x -> 0.00594972}, {x ->
      0.00618077}, {x -> 0.0064305}, {x -> 0.00670126}, {x ->
      0.00699582}, {x -> 0.00731747}, {x -> 0.00767012}, {x ->
      0.00805848}, {x -> 0.00848826}, {x -> 0.00896648}, {x -> 0.00950179}}
16

1 + Sin[1/x] /. roots
{0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.}


Plot[1 + Sin[1/x], {x, 0.005, 0.01}];

Not too bad.

David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/



From: DrBob [mailto:majort at cox-internet.com]
To: mathgroup at smc.vnet.net

Good luck with a function like 1 + Sin[x], which has infinitely many
roots but never changes sign!

Or Sin[1/x], which has infinitely many roots converging on 0, but no
limit for the function at 0.

Or... still worse... 1 + Sin[1/x], which has BOTH problems.

Bobby

-----Original Message-----
From: Andrzej Kozlowski [mailto:andrzej at platon.c.u-tokyo.ac.jp]
To: mathgroup at smc.vnet.net
Subject: [mg36012] [mg35996] [mg35942] Re: [mg35926] ALL roots of non-polynomial
equation

In your example, yes. Here is one way (adapted from a slightly different

problem in Stan Wagon's "Mathematica in Action")

We make use of Mathematica's ability to plot graphs:


In[1]:=
g = Plot[Sin[x], {x, 0.1, 10.1*Pi}, DisplayFunction ->
      Identity];

We make a list of all the coordinates of the points represented on the
graph.

In[2]:=
points = Cases[g, Line[x_] -> x, Infinity][[1]];

We make a list of the signs of the y values:

In[3]:=
signs = Sign /@ Transpose[Cases[g, Line[x_] -> x, Infinity][[
        1]]][[2]];

We find the points where the sign changes:

In[4]:=
positions = Position[Rest[signs]*Rest[RotateRight[signs]],
    -1]

Out[4]=
{{27}, {51}, {74}, {101}, {126}, {149}, {177}, {200}, {226},
   {252}}

We make a list of starting points for FindRoot:

In[5]:=
starts = First[Transpose[Extract[points, positions]]]

Out[5]=
{2.7825096162536145, 6.080185995733974, 8.787418231655966,
   12.198138489619575, 15.464841498197309, 18.61672099859868,
   21.92859710988888, 24.46767425065356, 27.840417480532142,
   31.139545383515845}


We find the roots:

In[6]:=
(FindRoot[Sin[x] == 0, {x, #1}, WorkingPrecision ->
      20] & ) /@ starts

Out[6]=
{{x -> 3.141592653589793238462643383255068`20},
   {x -> 6.283185307179586476925286766538051`20},
   {x -> 9.424777960769379715387930149825109`20},
   {x -> 12.566370614359172953850573533079026`20},
   {x -> 15.707963267948966192313216916378673`20},
   {x -> 18.849555921538759430775860299681079`20},
   {x -> 21.991148575128552669238503682979946`20},
   {x -> 25.132741228718345907701147066183302`20},
   {x -> 28.274333882308139146163790449476032`20},
   {x -> 31.415926535897932384626433832775678`20}}


This question has been asked frequently so you can find various
approaches, including this one, in the archives. Of course there is no
guarantee. For very complex functions you may well miss some roots. The
situation can become a lot more complicated if your equation has
multiple roots.

Andrzej


On Thursday, August 8, 2002, at 07:06  PM, Mihajlo Vanevic wrote:

>
> Can Mathematica find (localize) ALL roots of non-polynomial equation
>
> eq[x]==0
>
> on a given segment x \in [a,b],  a,b=Real??
>
> (for example  Sin[x]==0, for   0.1<x<10.1 Pi )
>
>
>
>
>
>
>







  • Prev by Date: Correction to my last post
  • Next by Date: Re: correction to my last post
  • Previous by thread: RE: Re: ALL roots of non-polynomial equation
  • Next by thread: Re: ALL roots of non-polynomial equation