Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2007
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2007

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

Search the Archive

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


  • 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