Solving linear algebraic eqns. in vector (matrix) notation ?
- Subject: Solving linear algebraic eqns. in vector (matrix) notation ?
- From: Radovan Omorjan
- Date: Tue, 01 Jan 2008 00:01:59 -0800
I've figured out myself how to solve this. It took me some time to
realise that equations and unknowns have to be in lists in order to
solve them with "solve" or "linsolve". I also realised that I do not
need "eigen". Something like transforming matrix m into equation list like:
(%i9) eqns : makelist(m[i][1]=0,i,1,6);
(%o9) [- n2 + n1 - eps = 0, - n2 + n1 - eps + eps = 0,
1 1 1 2 2 2 1
eps eps
2 1
- n2 + n1 + eps = 0, - n2 + n1 + eps = 0, - n2 + n1 - ---- -
---- = 0,
3 3 2 4 4 1 5 5 2 2
n1 - n2 = 0]
6 6
and solving by:
(%i10) linsolve(eqns,n2);
(%o10) [n2 = n1 - eps , n2 = n1 - eps + eps , n2 = n1 + eps ,
1 1 1 2 2 2 1 3 3 2
- 2 n1 + eps + eps
5 2 1
n2 = n1 + eps , n2 = - ---------------------, n2
= n1 ]
4 4 1 5 2
6 6
will do the job. I should have read the manual more carefuly, sorry.
Anyway, I've learned some new things.
Radovan
Radovan Omorjan wrote:
> Dear all!
>
> I am trying to solve some simple linear algebraic system of equations
> using array, vector, matrix notation.
> Here is my first attempt:
>
> (%i1) n1:makelist(n1[k],k,1,6);
> (%o1) [n1 , n1 , n1 , n1 , n1 , n1 ]
> 1 2 3 4 5 6
> (%i2) n2:makelist(n2[k],k,1,6);
> (%o2) [n2 , n2 , n2 , n2 , n2 , n2 ]
> 1 2 3 4 5 6
> (%i3) load(eigen);
> (%o3) D:/PROGRA~1/MAXIMA~1.0/share/maxima/5.12.0/share/matrix/eigen.mac
> (%i4) n1:columnvector(n1);
> [ n1 ]
> [ 1 ]
> [ ]
> [ n1 ]
> [ 2 ]
> [ ]
> [ n1 ]
> [ 3 ]
> (%o4) [ ]
> [ n1 ]
> [ 4 ]
> [ ]
> [ n1 ]
> [ 5 ]
> [ ]
> [ n1 ]
> [ 6 ]
> (%i5) n2:columnvector(n2);
> [ n2 ]
> [ 1 ]
> [ ]
> [ n2 ]
> [ 2 ]
> [ ]
> [ n2 ]
> [ 3 ]
> (%o5) [ ]
> [ n2 ]
> [ 4 ]
> [ ]
> [ n2 ]
> [ 5 ]
> [ ]
> [ n2 ]
> [ 6 ]
> (%i6) S: matrix([-1,0],[1,-1],[0,1],[1,0],[-1/2,-1/2],[0,0]);
> [ - 1 0 ]
> [ ]
> [ 1 - 1 ]
> [ ]
> [ 0 1 ]
> [ ]
> (%o6) [ 1 0 ]
> [ ]
> [ 1 1 ]
> [- - - - ]
> [ 2 2 ]
> [ ]
> [ 0 0 ]
> (%i7) eps:columnvector(makelist(eps[k],k,1,2));
> [ eps ]
> [ 1 ]
> (%o7) [ ]
> [ eps ]
> [ 2 ]
> (%i8) m: n1-n2+S.eps;
> [ - n2 + n1 - eps ]
> [ 1 1 1 ]
> [ ]
> [ - n2 + n1 - eps + eps ]
> [ 2 2 2 1 ]
> [ ]
> [ - n2 + n1 + eps ]
> [ 3 3 2 ]
> [ ]
> (%o8) [ - n2 + n1 + eps ]
> [ 4 4 1 ]
> [ ]
> [ eps eps ]
> [ 2 1 ]
> [ - n2 + n1 - ---- - ---- ]
> [ 5 5 2 2 ]
> [ ]
> [ n1 - n2 ]
> [ 6 6 ]
>
> So far so good!. I was trying to figure out how to solve the column
> vector m (every element equals to 0) ie. 6 linear equations in 6
> variables. What should I do in order to find, say, vector n2[k],k,1,6
> (I know how to assign values to other variables - if needed)?. On the
> other hand, I suppose there must be some other, more elegant way to
> work with and solve equations with indexed variables. I might missing
> something but could not find in Maxima book or help any examples of
> this kind.
>
> Any comments are appreciated.
> Regards,Radovan
>