Re: Replace in Modules
- To: mathgroup at smc.vnet.net
- Subject: [mg81233] Re: [mg81187] Replace in Modules
- From: DrMajorBob <drmajorbob at bigfoot.com>
- Date: Mon, 17 Sep 2007 03:31:25 -0400 (EDT)
- References: <958016.1189935557863.JavaMail.root@m35>
- Reply-to: drmajorbob at bigfoot.com
Neither one of them works -- nor should they -- but this does:
f[x_?NumericQ] := Module[{a}, a /. FindRoot[x == a^2, {a, 1}]]
f[2]
1.41421
or this
f[x_?NumericQ] := Module[{a}, a /. Solve[x == a^2, {a}]]
f[2]
{-Sqrt[2], Sqrt[2]}
Bobby
On Sat, 15 Sep 2007 03:07:08 -0500, 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
>
>
--
DrMajorBob at bigfoot.com