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]]