Re: Setting up equations
- To: mathgroup at smc.vnet.net
- Subject: [mg66031] Re: Setting up equations
- From: Bill Rowe <readnewsciv at earthlink.net>
- Date: Thu, 27 Apr 2006 02:26:33 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
On 4/26/06 at 4:37 AM, yaroslavvb at gmail.com (Yaroslav Bulatov) wrote: >I'm trying to do things of the form Solve[5 x + 6 y + 7 z == a x + b >y + c z, {a, b, c}] >But since x,y,z are variables, what I really mean is Solve[5==a && >6==b && 7==c], so I need to convert to this form >If I only have one variable, the following does what I need >LogicalExpand[a*x + b*x^2 + O[x]^3 == 2*x + 3*x^2 + O[x]^3] I think a simpler more direct approach would be to use CoefficientList here, i.e. In[16]:= CoefficientList[2*x + 3*x^2 + O[x]^3, x] Out[16]= {0, 2, 3} or if you prefer rules then: In[17]:= MapThread[Rule @@ {##1} & , {{a, b}, Rest[CoefficientList[2*x + 3*x^2 + O[x]^3, x]]}] Out[17]= {a -> 2, b -> 3} >But what to do if I have several variables? CoefficientList accepts a list of variables, i.e., In[18]:= CoefficientList[5*x + 6*y + 7*z, {x, y, z}] Out[18]= {{{0, 7}, {6, 0}}, {{5, 0}, {0, 0}}} But the output doesn't seem to me to be in a convenient form, so I suggest CoefficientArrays, i.e., In[20]:= Normal[CoefficientArrays[5*x + 6*y + 7*z, {x, y, z}]] Out[20]= {0, {5, 6, 7}} -- To reply via email subtract one hundred and four