MathGroup Archive 2008

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

Search the Archive

Putting an expression into a module

  • To: mathgroup at smc.vnet.net
  • Subject: [mg84883] Putting an expression into a module
  • From: Hugh <h.g.d.goyder at cranfield.ac.uk>
  • Date: Thu, 17 Jan 2008 07:04:36 -0500 (EST)

Suppose you have generated a long symbolic expression, e, and now wish
to  use the expression inside a Module. One method would be to cut-and-
paste the expression into the Module but how do you do this without
cutting-and-pasting?
Below in a warm up problem I first get what I want by cutting-and-
pasting and then try various combinations of Hold, ReleaseHold and
Evaluate. These don't work (why?) but how can it be done?

Thanks
Hugh Goyder

e = y^2 - x^2

ClearAll[f];
f[x_] := Module[{y}, y /. FindRoot[y^2 - x^2, {y, 1}]]

ClearAll[f];
ReleaseHold[f[x_] := Hold[Module[{y}, y /. FindRoot[e1, {y, 1}]]] /.
e1 -> e]

ClearAll[f];
ReleaseHold[
 f[x_] := Evaluate[Hold[Module[{y}, y /. FindRoot[e1, {y, 1}]]] /.
         e1 -> e]]

ClearAll[f];
Evaluate[ReleaseHold[
  f[x_] := Hold[Module[{y}, y /. FindRoot[e1, {y, 1}]]] /.
         e1 -> e]]

ClearAll[f];
ReleaseHold[
 f[x_] := Evaluate[Hold[Module[{y}, y /. FindRoot[e1, {y, 1}]]] /.
         e1 -> e]]

ClearAll[f];
f[x_] := Evaluate[
  ReleaseHold[Hold[Module[{y}, y /. FindRoot[e1, {y, 1}]]] /.
         e1 -> e]]


  • Prev by Date: Re: Findfit in C++
  • Next by Date: Re: What is the algorithm Mathematica uses to detrmine
  • Previous by thread: Strange errors when evaluating InverseGammaRegularized with 3 arguments for some values.
  • Next by thread: Re: Putting an expression into a module