Re: System of linear equation
- To: mathgroup at smc.vnet.net
- Subject: [mg112351] Re: System of linear equation
- From: Peter Pein <petsie at dordos.net>
- Date: Fri, 10 Sep 2010 04:49:56 -0400 (EDT)
- References: <i6a5hh$kmp$1@smc.vnet.net>
Am Thu, 9 Sep 2010 08:23:13 +0000 (UTC)
schrieb mfduqued <mfduqued at gmail.com>:
> Hi community,
>
> I have a system of linear equation 8x8. So I use LinearSolve but I
> obtain
>
> LinearSolve::matrix: Argument (<<1>>) at position 1 is not a nonempty
> rectangular matrix.
>
> I don't know why doesn't work this program.
>
> Please help.
>
Hi!
Say you've got a system of equations like this:
In[1]:=
eqns=Thread[RandomInteger[{-9,9},{8,8}].{a,b,c,d,e,x,y,z}==RandomInteger[{-9,9},{8}]]
Out[1]={4 a-4 c+9 d+2 e+7 x-9 y-6 z==2,4 a+5 c+7 d-7 e+5 x+9 y+7 z==3,-2
a-2 b+9 c-9 d+8 e+2 x+2 y+9 z==0,5 a-4 b+3 d-2 e+7 x+5 y+8 z==1,6 a+6
b+3 c+2 d+8 e+8 x+6 y-2 z==2,2 a-2 b-5 c+d-3 e-2 x+2 y+z==2,-2 a-3 b+4
c+3 d-2 e-x+4 y-4 z==-5,-6 a+6 b-c+9 d+3 e-9 x+6 y-3 z==9}
get the names of the variables:
In[2]:= vars=Variables[List@@@Flatten[eqns]]
Out[2]= {a,b,c,d,e,x,y,z}
and the coefficients:
In[3]:= mat=Coefficient[#,vars]&/@eqns[[All,1]]
Out[3]=
{{4,0,-4,9,2,7,-9,-6},{4,0,5,7,-7,5,9,7},{-2,-2,9,-9,8,2,2,9},{5,-4,0,3,-2,7,5,8},
{6,6,3,2,8,8,6,-2},{2,-2,-5,1,-3,-2,2,1},{-2,-3,4,3,-2,-1,4,-4},{-6,6,-1,9,3,-9,6,-3}}
call LinearSolve with this matrix and the right hand side of the
equations:
In[4]:= sol=LinearSolve[mat,eqns[[All,2]]]
Out[4]=
{51354071/42208205,16988863/42208205,10288482/42208205,6028995/8441641,
4176856/8441641,-(51657713/42208205),-(17796744/42208205),31914331/42208205}
and verify the result:
In[5]:= eqns/.Thread[vars->sol]
Out[5]= {True,True,True,True,True,True,True,True}
hth,
Peter