Re: FindRoot cannot find obvious solution

• To: mathgroup at smc.vnet.net
• Subject: [mg48050] Re: FindRoot cannot find obvious solution
• From: ab_def at prontomail.com (Maxim)
• Date: Sat, 8 May 2004 01:24:13 -0400 (EDT)
• References: <200404270847.EAA18892@smc.vnet.net> <c6o3lc\$cd0\$1@smc.vnet.net> <c6qags\$s56\$1@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```The recommendation to simply set "EvaluateNumericalFunctionArgument"
to False ( http://support.wolfram.com/mathematica/mathematics/numerics/nsumerror.html
) can be a bad idea. The reason is that with the default settings for
FindRoot the jacobian is still pre-evaluated. Hence it may happen that
we are evaluating one function and using the derivative of an entirely
different function:

In[1]:=
Developer`SetSystemOptions["EvaluateNumericalFunctionArgument" ->
False];
Module[{f = If[TrueQ[# > 0], #, -#] &},
FindRoot[f[x] == 2, {x, 1}]
]

FindRoot::lstol: The line search decreased the step size to within
tolerance specified by AccuracyGoal and PrecisionGoal but was
unable to find a sufficient decrease in the merit function.
You may need more than MachinePrecision digits of working
precision to meet these tolerances.

Out[2]=
{x -> 1.}

One way is to use RuleDelayed for Jacobian:

In[3]:=
Developer`SetSystemOptions["EvaluateNumericalFunctionArgument" ->
False];
Module[{f = If[TrueQ[# > 0], #, -#] &},
FindRoot[f[x] == 2, {x, 1}, Jacobian :> {{f'[x]}}]
]

Out[4]=
{x -> 2.}

This method isn't guaranteed to work either, because the first step in
evaluation of f'[x] is to evaluate f', and the question of how
Mathematica does that is equally unclear:

In[5]:=
Module[{f, g},
f = If[TrueQ[# > 0], #, -#] &;
g[x_] := If[TrueQ[x > 0], x, -x];
{f', g'}
]

Out[5]=
{If[TrueQ[#1 > 0], 1, -1] &, -1 &}

The output for g' agrees with what the documentation says: g' is
evaluated as Evaluate[D[g[#],#]]& (actually the reference for
Derivative says D[f[#]&,{#,n}], which doesn't make any sense. So I
assume it was supposed to mean Evaluate[D[f[#],{#,n}]]&). But f' is
evaluated differently, because there are special rules for the
derivatives of pure functions (or maybe specifically for control
structures like If).

Because of this, the safest way is still to use f[x_?NumericQ], even
with "EvaluateNumericalFunctionArgument"->False, to block the
evaluation of f'...and then to hope that it doesn't give some
unexpected effect in combination with Compiled->True (which is the
default setting for all numerical functions that use Compiled).

Maxim Rytin
m.r at prontomail.com

```

• Prev by Date: RE: Building List
• Next by Date: Re: Simple question
• Previous by thread: RE : Building List
• Next by thread: Re: Re: FindRoot cannot find obvious solution