Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2010

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

Search the Archive

Re: FindRoots?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg112120] Re: FindRoots?
  • From: "David Park" <djmpark at comcast.net>
  • Date: Tue, 31 Aug 2010 04:17:33 -0400 (EDT)

True, Sin[1/x] will eventually break any root finding algorithm because we
will always run out of time or space to store the answers if we push too
close to zero.

However, this does provide a good example to show how well Ted's algorithm
works. In this case the exact roots are 1/(n Pi) where n is a positive
interger that runs between limits that span the region we are searching.

So, let's try some cases numerically. To search for roots between 0.01 and
0.1 n runs from 4 to 21 and there are 28 roots. Here are the results from
RootSearch.

Needs["Ersek`RootSearch`"] 

RootSearch[Sin[1/x] == 0, {x, 0.01, 0.1}] 
Length[%] 

{{x -> 0.0102681}, {x -> 0.0106103}, {x -> 0.0109762}, {x -> 
   0.0113682}, {x -> 0.0117893}, {x -> 0.0122427}, {x -> 
   0.0127324}, {x -> 0.0132629}, {x -> 0.0138396}, {x -> 
   0.0144686}, {x -> 0.0151576}, {x -> 0.0159155}, {x -> 
   0.0167532}, {x -> 0.0176839}, {x -> 0.0187241}, {x -> 
   0.0198944}, {x -> 0.0212207}, {x -> 0.0227364}, {x -> 
   0.0244854}, {x -> 0.0265258}, {x -> 0.0289373}, {x -> 
   0.031831}, {x -> 0.0353678}, {x -> 0.0397887}, {x -> 
   0.0454728}, {x -> 0.0530516}, {x -> 0.063662}, {x -> 0.0795775}} 

28 

For the domain from 0.001 to 0.01 n runs from 32 to 318 and there are 287
roots.

RootSearch[Sin[1/x] == 0, {x, 0.001, 0.01}, InitialPrecision :> 40, 
  InitialSamples -> 5000, MaxBrentSteps -> 1000, 
  MaxSecantSteps -> 1000, PrecisionGoal :> 10]; 
Length[%] 

287 

For the domain from 0.0001 to 0.001 n runs from 319 to 3183 and there are
2865 roots. RootSearch took about 20 minutes on this. (I'm not certain if I
picked optimum values for the parameters to get the best efficiency.)

results3 =
  RootSearch[Sin[1/x] == 0, {x, 0.0001, 0.001}, 
   InitialPrecision :> 40, InitialSamples -> 30000, 
   MaxBrentSteps -> 1000, MaxSecantSteps -> 1000, PrecisionGoal :> 10]; 
Length[%] 

2865 

I would consider this pretty good performance.


David Park
djmpark at comcast.net
http://home.comcast.net/~djmpark/  



From: Mark Adler [mailto:madler at alumni.caltech.edu] 


On 2010-08-28 23:51:42 -0700, Sam Takoy said:
> Is there a command for numerically finding all roots of a function in a
> given interval. If not, what's the best way of accomplishing this task?

NSolve and NRoots does that, but only for polynomials.  I think you'd 
have to roll your own to search for the roots in an interval of any 
function.  If you consider functions like Sin[1/x] from 0 to 0.1, you 
can see that it might be quite difficult to do in general.

Mark




  • Prev by Date: Re: Numerical solution of coupled nonlinear PDEs
  • Next by Date: Re: i get an empty figure when exporting it, if I keep
  • Previous by thread: Re: FindRoots?
  • Next by thread: How avoid .nb in palette title bar?