Re: Converting set of equations to matrix

*To*: mathgroup at smc.vnet.net*Subject*: [mg26740] Re: [mg26709] Converting set of equations to matrix*From*: Daniel Lichtblau <danl at wolfram.com>*Date*: Fri, 19 Jan 2001 02:14:16 -0500 (EST)*References*: <200101180557.AAA16610@smc.vnet.net>*Sender*: owner-wri-mathgroup at wolfram.com

Helge Kreutzmann wrote: > > Hello ! > I have a set of equations I create following some rules, like > > 3 a[0,0] + 2 a[0,2] + 4 a[2,0] = 0 > -1 a[0,0] + 0.3 a[2,0] = 0 > 4 a[0,2] - 1 a[0,2] = 0 > > The numbers of coefficients (the a[i,j]) is different in each run > but fixed. For further calculations I would like to transform the > above equations into the matrix > {{3,2,4 },{-1,0,0.3},{0,4,-1}} > > Currently I have a list (called coeffli) where I can get the equations > from. The existing coefficients are stored in a second list (klist). > I also have a list where the values i,j are stored (cplist). > > The above list I would create by > For[i = 1, i <= Length[kflist], i++, > Print[Collect[coeffli[[cplist[[i]][[1]]]][[cplist[[i]][[2]]]], klist]]] > > I can create a list of the equations but I do not know how to tear > apart the sum into matrix elements. > > Thanks > > Helge There is a built in utility for this sort of thing in the MatrixManipulation standard add-on package. eqns = {3*a[0,0] + 2*a[0,2] + 4*a[2,0] == 0, -a[0,0] + 0.3*a[2,0] == 0, 4*a[0,2] - a[0,2] == 0}; vars = Variables[Map[#[[1]]-#[[2]]&,eqns]]; <<LinearAlgebra`MatrixManipulation` In[111]:= LinearEquationsToMatrices[eqns, vars] Out[111]= {{{3., 2., 4.}, {-1., 0., 0.3}, {0., 3., 0.}}, {0., 0., 0.}} Daniel Lichtblau Wolfram Research

**References**:**Converting set of equations to matrix***From:*Helge Kreutzmann <helgek@studserv.stud.uni-hannover.de>