MathGroup Archive 2001

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

Search the Archive

Roots of a function

  • To: mathgroup at
  • Subject: [mg29404] Roots of a function
  • From: Ranko Bojanic <bojanic at>
  • Date: Sat, 16 Jun 2001 22:43:52 -0400 (EDT)
  • Sender: owner-wri-mathgroup at

Maarten van der Burgt wrote today:

> What is the easiest solution to finding the 13 (real) roots of
> 0.05 x +Cos[x] == 0.
> I can be easily seen that there are 13 roots by plotting:
> Plot[{0.05 x,-Cos[x]},{x,-30,30}]
> but this is not sufficient for finding accurate numerical values.

> FindRoot only gives one value and it is hard to predict which root it will find 
> with a specified start value:

> In[83]:= FindRoot[0.05 x  +Cos[x] == 0,{x,0}]
> Out[83]= {x -> -4.96317}

> There are three roots closer to 0 then x == -4.96317
> An NSolve only works for polynomials.
> Is there no simple way to find all roots of such an equation, eventually within 
> a specified range.
> thanks for your help

> Maarten van der Burgt
> Leuven

Newton's method does not work here well with the initial value 0 because the 
derivative of 

f[x] = 0.05 +Cos[x] 

is small at 0. The best procedure in cases like 
this is to find a list of intervals which contain a zero and then use the 
function FindRoot[f[x]==0,{x, {x1,x2}}]. The function

zIntList[f_, a_, b_, h_] := 
produces the list of 13 intervals:

int = zIntList[f, -20, 20, 0.1] 


Map[ FindRoot[f[x] == 0,{x,#}]& , int]

gives the list of zeros:

{{x -> -19.1433},{x -> -18.4538},{x -> -13.4028},{x -> -11.6152},
{x -> -7.47114},{x -> -4.96317},{x -> -1.49593},{x -> 1.65357},
{x -> 4.48616},{x -> 8.28087},{x -> 10.446},{x -> 14.984},
{x ->16.324}}

bojanic at

PS. In a Mathematica based Numerical Analysis course I asked students 
to find the fastest function that would produce intervals containing zeros
of a given  function. My solution, given above, was somewhere in the middle.
The fastest function, found by a student (Yu Zhang) looks like this:

zIntList[f_, a_, b_, h_]:=
	 Module[{aLst, bLst, cLst, dLst},
	   	aLst = Range[(b-a)/h]*h+a;
	   	cLst=Sign[Take[bLst, Length[bLst]-1]*Take[bLst,1-Length[bLst]]];
	   	Return[Transpose[{aLst[[dLst]], aLst[[dLst]]+h}]]];

  • Prev by Date: Re: roots
  • Next by Date: RE: roots
  • Previous by thread: RE: R: Local iterator
  • Next by thread: How to produce "thick" lines in 3D?