Re: Solve Function
- To: mathgroup at smc.vnet.net
- Subject: [mg44975] Re: Solve Function
- From: "Curt Fischer" <crf3 at po.cwru.edu>
- Date: Thu, 11 Dec 2003 05:28:29 -0500 (EST)
- References: <br6oqv$2lb$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
"Gregory Lypny" <gregory.lypny at videotron.ca> wrote in message news:br6oqv$2lb$1 at smc.vnet.net... > Hello Everyone, > > I've got a question about the Solve function. I read in the > Mathematica Book that Solve can handle a set of simultaneous equations > (page 88) and that the syntax for the function is to list each equation > followed by the variables to solve for. What if all of the equations > have the same form, say, because they're constraints in the first-order > conditions of an optimization? I'm wondering whether Solve can handle > a neater specification in matrix form, something along the lines of > > Solve[f[x]==g[x], x], > > where x is a vector of variables {x1, x2, x3, ... , xn}. It would save > a lot of typing. I've tried to feed solve a variable defined as an > array, but I keep getting errors to the effect that the equation is not > well formed. This is possible but as far as I know only in version 5.0. What version are you using? Anyway, even if not possible, you should still be able to use Thread[] to turn a matrix equation into a list of regular equations. Here's a problem I solved. In[2]:= ? Solve \!\(\* RowBox[{"\<\"Solve[eqns, vars] attempts to solve an equation or set of \ equations for the variables vars. Solve[eqns, vars, elims] attempts to solve \ the equations for vars, eliminating the variables elims.\"\>", " ", ButtonBox[ StyleBox["More.", "SR"], ButtonData:>"Solve", Active->True, ButtonStyle->"RefGuideLink"]}]\) In[3]:= A={{a,b},{c,d}}; In[4]:= X={x,y}; In[5]:= B={e,f}; In[6]:= \!\(Solve[A . X\^2\ + \ 2 X == B, X]\) Out[6]= {a horrible mess of formulae many pages long; see if it works on your machine...} If that doesn't work, try doing it like this: In[7]:= \!\(Thread[A . X\^2\ + \ 2 X == B]\) Out[7]= \!\({2\ x + a\ x\^2 + b\ y\^2 \[Equal] e, c\ x\^2 + 2\ y + d\ y\^2 \[Equal] f}\) In[8]:= Solve[%,X] Out[8]= {the same horrible mess that I omitted earlier} -- Curt Fischer