Re: Replace in Modules
- To: mathgroup at smc.vnet.net
- Subject: [mg81226] Re: [mg81187] Replace in Modules
- From: Bob Hanlon <hanlonr at cox.net>
- Date: Sun, 16 Sep 2007 04:08:32 -0400 (EDT)
- Reply-to: hanlonr at cox.net
Works this way
Clear[f];
f[x_] := Module[{a, y}, y = x; a /. FindRoot[y == a^2, {a, 1}]];
f[2]
1.41421
Clear[f];
f[x_] := Module[{a}, a /. FindRoot[x == a^2, {a, 1}]];
f[2]
1.41421
Bob Hanlon
---- Joerg Schaber <schaber at molgen.mpg.de> wrote:
> Hi,
>
> why doesn't the following give me the square root?
>
> f[x_] := Module[{a, y},y = x;Return[FindRoot[y == a^2, {a, 1}]]]
>
> f[z] /. {z -> 2}
>
> where as
>
> f[x_] := Module[{a},Return[FindRoot[x == a^2, {a, 1}]]]
>
> f[z] /. {z -> 2}
>
> works fine?
>
> best,
>
> joerg
>