[Date Index]
[Thread Index]
[Author Index]
Re: Mathematica- Use a previous equation into the function Function
*To*: mathgroup at smc.vnet.net
*Subject*: [mg111450] Re: Mathematica- Use a previous equation into the function Function
*From*: Bill Rowe <readnews at sbcglobal.net>
*Date*: Mon, 2 Aug 2010 07:02:55 -0400 (EDT)
On 8/1/10 at 4:58 AM, camille.segarra at gmail.com (Camille) wrote:
>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?
It would be helpful to know what you want to do after you have
created a function. I am guessing, you have an expression (ll)
and a list of parameters (Listp) in that expression. Then with
this you want to be able to substitute particular values for the
parameters and arrive at a specific instance of your expression
with those values. I would do this as follows:
In[22]:= ll = d + a x + h x^2 + b y + e x y + c z + j z^2;
Listp = {a, b, c, d, e, h, j};
test = RandomInteger[{1, 10}, 7]
Out[24]= {7,6,1,3,4,5,3}
Here, ll is your expression and Listp is your list of
parameters. I've created the variable test to be specific values
for the parameters. I can substitute the values in test for the
corresponding parameters using ReplaceAll as follows:
In[25]:= ll /. Thread[Listp -> test]
Out[25]= 5*x^2 + 4*x*y + 7*x + 6*y + 3*z^2 + z + 3
Prev by Date:
**ReplaceAll and ReplaceRepeated Strange Behavior**
Next by Date:
**Re: Bare Bones Backup Button**
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**
| |