Re: Why is FindRoot[] HoldAll?
- To: mathgroup at smc.vnet.net
- Subject: [mg81941] Re: Why is FindRoot[] HoldAll?
- From: Szabolcs Horvát <szhorvat at gmail.com>
- Date: Sun, 7 Oct 2007 05:32:18 -0400 (EDT)
Szabolcs Horvát wrote:
> 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),
I thought a bit more about this, and I can see that HoldAll is necessary
so that the unknown variable can be made local to FindRoot.
For example,
In[1]:=
a = 3;
FindRoot[a^2 == 2, {a, 1}]
Out[2]= {3 -> 1.4142135623730951}
works, but it still returns 'a' in the result ({a -> solution}), which
is then replaced with 3. So even though 'a' is local to FindRoot, it is
not a good idea to use it as the unknown if it has a value.
> 2. Or prevent FindRoot from evaluating the equation before the unknown
> has been substituted with a numerical value.
The problem with this is that in certain cases it will make it necessary
to use Evaluate[]:
eq = a^2 == 1
FindRoot[eq, {a, 1}]
Whether having to use Evaluate[] in certain situations is a greater
disadvantage than the current problem with NIntegrate etc. is debatable.
Szabolcs