MathGroup Archive 2003

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

Search the Archive

Re: FindRoot in 5.0

  • To: mathgroup at smc.vnet.net
  • Subject: [mg42850] Re: [mg42819] FindRoot in 5.0
  • From: Richard Gass <gass at physics.uc.edu>
  • Date: Wed, 30 Jul 2003 19:30:57 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

On Wednesday, July 30, 2003, at 04:07  AM, Eric Mockensturm wrote:

> I realize that FindRoot has changed but there seems to be a
> fundamental difference in it between pre-5.0 versions and 5.0 that
> breaks most of my notebooks.  Maybe I've been following bad
> 'programming' practices all these years, but....
>
> Anyway, a simple illustration follows.
>
> In 4.2:
>
> In[7]:=func[x_]:=(y=x;NIntegrate[BesselY[1/2,s],{s,1/2,y}])
> In[8]:=FindRoot[(Print[x];func[x]),{x,2,4}]
> Out[8]={x\[Rule]3.04729}
>
> In 5.0:
>
> In[1]:=func[x_]:=(y=x;NIntegrate[BesselY[1/2,s],{s,1/2,y}])
> In[2]:=FindRoot[(Print[x];func[x]),{x,2,4}]
> Out[2]={x\[Rule]4.}
>
> with errors...
>
> NIntegrate::nlim: s = x is not a valid limit of integration
>
> It seems that 5.0 is trying to evaluate func[x] symbolically before
> start to search for a root.  How do I make a global change to this
> behavior.  Does it have something to do with the HoldAll attribute?
> FindRoot was been HoldAll in 4.2, too.
>
>
>
>

This effects more than just FindRoot but you can restore the old 
behavior by using 
Developer`SetSystemOptions["EvaluateNumericalFunctionArgument" ->
False] . This restores the old behavior but you take a substantial 
speed hit. In your case you can fix the problem (without the speed hit) 
by using

> func[x_?NumericQ]:=(y=x;NIntegrate[BesselY[1/2,s],{s,1/2,y}])

and then
> FindRoot[func[x],{x,2,4},EvaluationMonitor:>Print[x]]
or better yet
points={}
FindRoot[func[x],{x,2,4},EvaluationMonitor:>AppendTo[points,x]]
ListPlot[points]


Richard Gass
Department of Physics
University of Cincinnati


  • Prev by Date: Re: Quicktime Controls
  • Next by Date: Re: maximization question
  • Previous by thread: Re: FindRoot in 5.0
  • Next by thread: Re: FindRoot in 5.0