MathGroup Archive 1997

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

Search the Archive

Re: Help with findroot

At 09:38 +0200 97.10.16, Karl Kevala wrote:
> I'm having a problem using findroot to solve an equation.  Perhaps
> someone
>  could shed some light on what's wrong.
> FindRoot[Sqrt[x/(1.2 10^ -4)]==-0.1*Tan[Sqrt[x/(1.2*10^
> -4)]],{x,0.1,0.1,2}]
> Mathematica 3. returns a value of -0.07 for x which is not anywhere
> close to correct.
>  Further, I've tried several different starting values and min/max
> limits, but
>  a negative answer is always returned.  Eventually I'de like to compile
> a list
>  of all the roots of the equation up to, say, x=1000, but I can't even
> get one
>  right now.
> Thanks,
> Karl Kevala

Let me add to the several reasonable responses already posted. One
useful method might be to remove the source of singularities, that is,
kill the denominator.

In[45]:= ee = Cos[y]*y + .1*Sin[y] /. y->Sqrt[x/(1.2*10^(-4))] Out[45]=
91.2871 Sqrt[x] Cos[91.2871 Sqrt[x]] + 0.1 Sin[91.2871 Sqrt[x]]

In[46]:= rutes = x /. Table[FindRoot[ee == 0, {x,j}], {j,0,.02,.001}];
   Newton's method failed to converge to the prescribed accuracy after

In[47]:= rutes = Union[rutes, SameTest->(Chop[Abs[#1-#2],10^-5]==0&)]
Out[47]= {0., 0.000319609, 0.00268874, 0.00742618, 0.0145323, 0.0240071,
>    0.0358507, 0.130599}

So apparently FindRoot had minor trouble on one attempt, but still found
a bunch of roots in the region sampled. The point is that Newton/secant
methods will behave much better in the absence of poles.

Alternatively (as several others noted) if you know the location of the
poles and roughly where to proceed toward the zeroes, you can give
sufficiantly good initial values that FindRoot will have a chance to

Closer investigation reveals that the troublesome starting point was
.001. Looking at the plot makes it clear what goes awry: a nearly
horizontal slope sends Newton's method to the negative axis, where the
function is complex-valued (and discontinuous) due to presence of Sqrt.
In general it might be better (when possible) to make a substitution
that removes such multi-valued inverses, then solve in two stages.
Others made this point so I'll skip the details.

By the way, you can do the denominator removal more-or-less
automatically using Together and related commands. It typically takes a
few minutes playing around to get the right use of Trig->True and that
sort of thing.

In[69]:= origee = Sqrt[x/(1.2 10^(-4))] +

In[70]:= ee2 = Together[origee, Trig->True];

In[71]:= ee3 = Chop[Numerator[ee2, Trig->True]] Out[71]= 91.2871 Sqrt[x]
Cos[91.2871 Sqrt[x]] + 0.1 Sin[91.2871 Sqrt[x]]

Daniel Lichtblau
Wolfram Research
danl at

  • Prev by Date: RE: Help with findroot
  • Next by Date: Re: mathematica question
  • Previous by thread: RE: Help with findroot
  • Next by thread: Re: Help with findroot