MathGroup Archive 2010

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

Search the Archive

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

  • To: mathgroup at smc.vnet.net
  • Subject: [mg111443] Re: Mathematica- Use a previous equation into the function Function
  • From: Peter Pein <petsie at dordos.net>
  • Date: Mon, 2 Aug 2010 07:01:38 -0400 (EDT)
  • References: <i33cvi$87q$1@smc.vnet.net>

Am Sun, 1 Aug 2010 08:58:26 +0000 (UTC)
schrieb Camille <camille.segarra at gmail.com>:

> Dear All,
> 
...
> 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?
> 
> Thanks in advance. Do not hesitate to post if you need some further
> information. Sorry for my bad english.
> 
> Camille
> 
Salut Camille,


In[1]:= ll=d+a x+h x^2+b y+e x y+c z+j z^2;
Listp=Variables[ll]~Complement~{x,y,z};

Function has the attribute HoldAll. The function Function does not
evaluate its parameters.

In[3]:= Attributes@Function
Out[3]= {HoldAll,Protected}

But you can force evaluation:

In[4]:= Function[##,Evaluate@ll]&@@{Listp}
Out[4]= Function[{a,b,c,d,e,h,j},d+a x+h x^2+b y+e x y+c z+j z^2]

Peter

P.S.: if you like unusal ways to define functions, try:

In[7]:= Evaluate[f@@(Pattern[#,Blank[]]&/@Listp)]=ll
Out[7]= d+a x+h x^2+b y+e x y+c z+j z^2
In[8]:= ??f
:-)



  • Prev by Date: Re: trading
  • Next by Date: Surprising FullSimplify result
  • Previous by thread: Mathematica- Use a previous equation into the function Function
  • Next by thread: Re: Mathematica- Use a previous equation into the function Function