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: [mg111503] Re: Mathematica- Use a previous equation into the function Function
  • From: Raffy <adraffy at gmail.com>
  • Date: Tue, 3 Aug 2010 06:41:12 -0400 (EDT)
  • References: <i33cvi$87q$1@smc.vnet.net>

On Aug 1, 1:58 am, Camille <camille.sega... at gmail.com> wrote:
> 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?
>
> Thanks in advance. Do not hesitate to post if you need some further information. Sorry for my bad english.
>
> Camille

I'd suggest something like:
ClearAll[injector];
injector[expr_, args_] := expr& //. Table[args[[i]]->Slot[i],
{i,Length[args]}];

Usage:
injector[a+b+c, {a,b}] === #1+#2+c&

Your example:
injector[ll, Listp] === #4 + #1 x + #6 x^2 + #2 y + #5 x y + #3 z + #7
z^2 &

Identity:
injector[expr, args]@@args === expr


  • Prev by Date: Re: ReplaceAll and ReplaceRepeated Strange Behavior
  • Next by Date: Re: A distribution problem using Mathematica
  • 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