       Re: Mathematica- Use a previous equation into the function Function

• To: mathgroup at smc.vnet.net
• Subject: [mg111457] Re: Mathematica- Use a previous equation into the function Function
• From: Albert Retey <awnl at gmx-topmail.de>
• Date: Mon, 2 Aug 2010 07:04:15 -0400 (EDT)
• References: <i33cvi\$87q\$1@smc.vnet.net>

```Am 01.08.2010 10:58, schrieb Camille:
> Dear All,
>
> I am fairly new to mathematica. I am stuck with a problem I cannot solve. I would like to call a previous equation into the function Function. If a type directly the expression or copy paste it, it works. However, when I call the expression by its name it does not.
> Here is the code for a more precise explanation:
>
> In: ll
> Out: d + a x + h x^2 + b y + e x y + c z + j z^2
>
> In: Function[##, a x + b y + c z + d + e x y + h x^2 + j z^2] & @@ {Listp}
> Out: Function[{a, b, c, d, e, h, j},
>  a x + b y + c z + d + e x y + h x^2 + j z^2]
>
> It works well and I can use it to generate as many equations I want by replacing the variables a,b,c,d,e,h,j.
> But if I do:
>
> In:Function[##, ll] & @@ {Listp}
> Out:Function[{a, b, c, d, e, h, j}, ll]
>
> And I cannot use it.
>
> Any suggestions?

Function @@ {##, ll} & @@ {Listp}

or

Function[##, Evaluate[ll]] & @@ {Listp}

should do what you want. The deeper reason is the HoldAll-Attribute that
Function has set:

In:= Attributes[Function]

Out= {HoldAll, Protected}

The two examples above make sure the body of the function is evaluated.
Some other possibilities will not work, since Function is also a scoping
construct and some renaming might not turn out as intended:

In:= With[{l = ll}, Function[##, l]] & @@ {Listp}

Out= Function[{a\$, b\$, c\$, d\$, e\$, h\$, j\$},
d + a x + h x^2 + b y + e x y + c z + j z^2]

hth,

albert

```

• Prev by Date: Re: discretized Laplacian or linear inverse problem with extremely
• Next by Date: Re: All pairs shortest paths
• Previous by thread: Re: Mathematica- Use a previous equation into the function Function
• Next by thread: Re: Mathematica- Use a previous equation into the function Function