Re: ALL roots of non-polynomial equation
- To: mathgroup at smc.vnet.net
- Subject: [mg35942] Re: [mg35926] ALL roots of non-polynomial equation
- From: Andrzej Kozlowski <andrzej at platon.c.u-tokyo.ac.jp>
- Date: Fri, 9 Aug 2002 05:17:50 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
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 ) > > > > > > >