Re: Putting an expression into a module
- To: mathgroup at smc.vnet.net
- Subject: [mg84906] Re: Putting an expression into a module
- From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
- Date: Fri, 18 Jan 2008 05:54:30 -0500 (EST)
- Organization: Uni Leipzig
- References: <fmngh8$3fl$1@smc.vnet.net>
- Reply-to: kuska at informatik.uni-leipzig.de
Hi, if using a simple variable fails e = y^2 - x^2 ClearAll[f]; ReleaseHold[ SetDelayed @@ {f[x_], Hold[Module[{y}, y /. FindRoot[e1, {y, 1}]]] /. e1 -> e} ] Regards Jens Hugh wrote: > 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]] >