MathGroup Archive 1999

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Question: getting list data into a matrix

  • To: mathgroup at smc.vnet.net
  • Subject: [mg17298] Re: Question: getting list data into a matrix
  • From: tobiasoed at my-dejanews.com
  • Date: Fri, 30 Apr 1999 23:22:28 -0400
  • Organization: Deja News - The Leader in Internet Discussion
  • Sender: owner-wri-mathgroup at wolfram.com

In this example I have 4 unknows, a[1],b[1],c[1],d[1], change
the 1 to a 6 in this line (I have to admitt that this line is
is pretty ugly, but I am a little lazy)

In[1]:= u=Sort[Flatten[Table[{a[i],b[i],c[i],d[i]},{i,1}]]]

Out[1]= {a[1], b[1], c[1], d[1]}

Now 4 equations

In[2]:= e={2 a[1]+3 b[1]+4 c[1]==0, 2 a[1]+4
b[1]==24,b[1]-d[1]==9,d[1]+c[1]==8}

Out[2]= {2 a[1] + 3 b[1] + 4 c[1] == 0, 2 a[1] + 4 b[1] == 24,

>    b[1] - d[1] == 9, c[1] + d[1] == 8}

this makes a row of your matrix given one equation

In[3]:= gc[lhs_==rhs]:=Map[Coefficient[lhs,#]&,u]

and this builds the whole matrix

In[4]:= A=Map[gc,e]

Out[4]= {{2, 3, 4, 0}, {2, 4, 0, 0}, {0, 1, 0, -1}, {0, 0, 1, 1}}

this makes the Y vector

In[5]:= Y=Map[Last,e]

Out[5]= {0, 24, 9, 8}

Make rules for your unknowns

In[6]:= r=Thread[Rule[u,Inverse[A].Y]]

                   124           92            7           47
Out[6]= {a[1] -> -(---), b[1] -> --, c[1] -> -(-), d[1] -> --}
                    5            5             5           5

and check

In[7]:= e /. r

Out[7]= {True, True, True, True}

In[8]:=

Hope this helps, Tobias

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


  • Prev by Date: How to: PlotRange->{0, All} ?
  • Next by Date: Re: my previous question on matrix element assignment
  • Previous by thread: Re: How to: PlotRange->{0, All} ?
  • Next by thread: Re: my previous question on matrix element assignment