MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Replace in Modules


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


  • Prev by Date: Is automatic EquationNumbered tags not working in ver. 6?
  • Next by Date: question on 2 separate Mathematica instances on the same PC
  • Previous by thread: Re: Replace in Modules
  • Next by thread: Re: Replace in Modules