Re: Parculiarities of FindRoot
- To: mathgroup at smc.vnet.net
- Subject: [mg116071] Re: Parculiarities of FindRoot
- From: DrMajorBob <btreat1 at austin.rr.com>
- Date: Tue, 1 Feb 2011 06:51:45 -0500 (EST)
Limiting "func" to numeric input prevents FindRoot trying to use a
symbolic one.
Clear[func]
func[y_?NumericQ] := Module[{x},
x^2 /. FindRoot[x + y == 0, {x, 0.}]
]
func[.2]
0.04
FindRoot[func[z], {z, 0.}]
{z -> 0.}
Block also works, in place of Module.
Bobby
On Mon, 31 Jan 2011 02:24:17 -0600, Tianhui Li <tianhuil 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
>
--
DrMajorBob at yahoo.com