Re: A problem with FindRoot

• To: mathgroup at smc.vnet.net
• Subject: [mg83824] Re: A problem with FindRoot
• From: Szabolcs Horvát <szhorvat at gmail.com>
• Date: Sat, 1 Dec 2007 05:49:45 -0500 (EST)
• References: <fim7qp\$qqp\$1@smc.vnet.net> <fioqve\$cns\$1@smc.vnet.net>

```Jean-Marc Gulliet wrote:
> I bet that the error messages you get are a similar to "FindRoot::srect:
> "Value x in search specification {y,x} is not a number or array of numbers."
>
> Add a condition to your definition of f so it is called only for numeric
> arguments.
>
> In[1]:= Clear[f]
> f[x_?NumberQ] := {y /. FindRoot[y^3 + 1 == x, {y, x}][[1]]}[[1]]
> FindRoot[f[x] == 0, {x, 3}, AccuracyGoal -> 5]
>
> Out[3]= {x -> 1.}

I'd just like to add a small comment:  In these situations it is more
correct to use NumericQ instead of NumberQ, otherwise expressions like
f[Sqrt[2]] will not evaluate.  Sqrt[2] is not an "atomic" number in
Mathematica, but a compound expression.  However, it does represent a
number in the mathematical sense, and N[Sqrt[2]] evaluates to a floating
point value.  So NumberQ[Sqrt[2]] === False and NumericQ[Sqrt[2]] ===
True.  Of course this does not make a difference if the function f is
only used inside FindRoot[].

--
Szabolcs

```

• Prev by Date: Re: how draw box with open front
• Next by Date: Interpolation in 2 D, bug?
• Previous by thread: Re: Mathematica: Long divison for polynomials
• Next by thread: Interpolation in 2 D, bug?