Re: Parculiarities of FindRoot
- To: mathgroup at smc.vnet.net
- Subject: [mg116079] Re: Parculiarities of FindRoot
- From: "Sjoerd C. de Vries" <sjoerd.c.devries at gmail.com>
- Date: Tue, 1 Feb 2011 06:53:16 -0500 (EST)
- References: <ii5rjj$fit$1@smc.vnet.net>
You define Func such that it only works for numeric input (try giving it a symbolic input and see what happens). One of the first steps of FindRoot involves the symbolic evaluation of the function to find the derivative, which in this case is unsuccessful. Changing the definition of Func slightly, so that it tests for its arguments being numeric helps: In[24]:= ClearAll[Func]; Func[y_?NumericQ] := x^2 /. FindRoot[x + y == 0, {x, 0.}] Func[.2] FindRoot[Func[z] == 0, {z, 0.}] Out[26]= 0.04 Out[27]= {z -> 0.} Cheers -- Sjoerd On Jan 31, 9:24 am, Tianhui Li <tianh... at princeton.edu> wrote: > Here's a question for the group: in the following function, Func seems > to evaluate numerical arguments correctly and *works* when you throw > it into a FindRoot. But the second command generates a lot of warning > messages. Does anyone understand why? > > Func[y_] := x^2 /. FindRoot[x + y == 0, {x, 0.}] > Func[.2] > FindRoot[Func[z], {z, 0.}] > > Warm Regards, > Michael Li > Bendheim Center for Finance > Princeton University > Princeton, NJ 08544