Re: A problem with FindRoot
- To: mathgroup at smc.vnet.net
- Subject: [mg83770] Re: A problem with FindRoot
- From: Szabolcs Horvát <szhorvat at gmail.com>
- Date: Fri, 30 Nov 2007 05:17:34 -0500 (EST)
- References: <fim7qp$qqp$1@smc.vnet.net>
Vassilis Dimitrakas wrote:
> Hi All,
>
> I'd like some help with respect to a problem I have with the FindRoot,
> NSolve and FindInstance functions.
> My version of Mathematica is 5.2
>
> I define the function f as follows:
>
> f[x_]:={
> y/.FindRoot[y^3+1==x,{y,x}][[1]]
> }[[1]]
>
> f[x] returns the root of the equation y^3 + 1 == x, i.e. the value
> (x-1)^(1/3). f[x] has obviously a
> unique root at x=1.
>
> If I now try to find f[x]'s root with FindRoot, for example like
>
> FindRoot[f[x]==0,{x,3}]
>
> Mathematica (v 5.2) returns error messages and no solution. The same
> happens if I use instead NSolve
> or FindInstance. Can you guys explain why this happens and suggest a
> remedy?
Try evaluating f[x]. You get the same errors. The function f should
only be evaluated with a numerical argument. So use
f[x_?NumericQ] := Module[{y}, y /. FindRoot[y^3 + 1 == x, {y, x}]]
instead. Note that all those lists and indices are not necessary, but
'y' should be made a local variable to avoid unpleasant surprised when
it is given a value.
--
Szabolcs