简体   繁体   中英

Solve special system of linear equations in Matlab (GNU Octave)

I have a matrix, let's say 5x5 looking like this:

          0          0          0          1          0
          0          0          0        4/5        1/5
        3/5        1/5        1/5          0          0
        1/5        2/5        1/5        1/5          0
       1/10       1/10        2/5        1/5        1/5

I need it to solve it like a system of linear equations looking like this (I can transpose it myself, but then multiplying it with the symbolic variables gets me into troubles):

   0 * a  +      0 * b  +    3/5 * c  +    1/5 * d  +    1/10 + e  =  a
   0 * a  +      0 * b  +    1/5 * c  +    2/5 * d  +    1/10 + e  =  b
   0 * a  +      0 * b  +    1/5 * c  +    1/5 * d  +     2/5 + e  =  c
   1 * a  +    4/5 * b  +      0 * c  +    1/5 * d  +     1/5 + e  =  d
   0 * a  +    1/5 * b  +      0 * c  +      0 * d  +     1/5 + e  =  e
       a  +         b  +          c  +          d  +           e  =  1

I can easily solve this in wxMaxima, but I have to manually write all the values there, which is increasingly tedious with bigger matrices.

Is there a way to get the results after some steps using matlab operator \\ for solving system of linear equations?

You can solve the equation set no?

>>[A-eye(5);ones(1,5)]\[0,0,0,0,0,1]'
ans =

  0.1729
  0.2061
  0.1345
  0.4350
  0.0515

>> sum(ans)

ans =

    1.0000

And a symbolic solution:

M=sym(A);
v=sym('[a;b;c;d;e]');
sol=solve(M*v==v,sum(v)==1);

returns solutions in the form sol.a , sol.b , ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM