Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2007

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

Search the Archive

Re: Why is FindRoot[] HoldAll?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg81980] Re: [mg81957] Why is FindRoot[] HoldAll?
  • From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
  • Date: Mon, 8 Oct 2007 00:06:53 -0400 (EDT)
  • References: <200710070940.FAA20590@smc.vnet.net>

On 7 Oct 2007, at 18:40, Szabolcs Horv=E1t wrote:

> Recently there was a question about finding the roots of an equation
> that is defined in terms of NIntegrate[].
>
> The following *works*, but it gives lots of error messages:
>
> FindRoot[NIntegrate[Exp[a x], {x, 0, 1}] == 2, {a, 1}]
>
> The messages suggest that FindRoot evaluates the equation even before
> the unknown 'a' is substituted with a numerical value.  This is not
> consistent with the fact that FindRoot has HoldAll.
>
> Would it be possible to
>
> 1. Either remove the attribute HoldAll to make it clear to the 
> users how
> this function works (and allow FindRoot to receive Unevaluated 
> arguments
> so that equations containing NIntegrate[] can be used directly),
>
> 2. Or prevent FindRoot from evaluating the equation before the unknown
> has been substituted with a numerical value.
>
> If either of these two possibilities is implementable in Mathematica,
> then IMO the current behaviour can be considered a bug.  If they 
> are not
> implementable, could someone explain why?
>
> --
> Szabolcs
>

I am not sure from your message if you are aware of this:

FindRoot[NIntegrate[Exp[a x], {x, 0, 1}] == 2, {a, 1}, Evaluated -> 
False]
{a -> 1.25643}

No error messages. Of course, one would expect that using this option 
will in most cases have a negative impact ton the performance.
Why the HoldAll attribute? Well, presumably without the HoldAll 
attribute the function would always be evaluated irrespective of any 
option settings so one could not use this approach. Not having the 
HoldAll or HoldFirst argument means that it will always be evaluated, 
before the function is applied. having it does not mean that the 
argument will not be evaluated; it only means it will not be "pre-
evaluated". It may still be evaluated by the function itself.

Andrzej Kozlowski


  • Prev by Date: Re: Why is FindRoot[] HoldAll?
  • Next by Date: NumberForm question
  • Previous by thread: Re: Why is FindRoot[] HoldAll?
  • Next by thread: RE: Re: Generic TCPIP sockets in Mathematica (Mathlink?) > incorporation of external sensors and 16-button mouse