EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
这个是只是用行变换将非严格占优矩阵通过行变换转换为严格占有矩阵。 伪代码如下: Input matrix:A Output: If A can transform into a dominance with our method,we can get the dominance. Else output’Cannot transform the matrix into dominance’ Variable: Set a matrix record with the size [row_of_matrix,3] Record[row_length_matrix,3] %This matrix is for record A’s situation. % Record[1:,1] first volumn stands for this row of A should be put which row % Record[1:,2] second volumn stands for whether this row satisfy the necessity of transform into a dominance.If yes,set 1;otherwise 0. % Record[1:,3] third volumn stands for which initial row belong to. Flag% this variable is to record whether the matrix A can transform into a dominance. % If yes,Flag = 1; % otherwise Flag = 0 % beneath code is to test whether the matrix can transform into a dominance % and record the situation of every row. for i = 1:size_of_matrix Test every row(Record); If test_row’s Record[1:,2] == 0 then break and output ’Cannot transform the matrix into dominance’ Flag = 0; end end % If Flag = 1,we use row exchangement to transform A into dominance If Flag = 1 Row_exchangment by record. for i = 1:row-1 for j = 1:row if record(j,1) == i %exchange line if flag = 1,which %means it can be transformed into dominance exchange A(i,:) and A(record(j,3),:); exchange record(j,:) and record(i,:); break; end end end Display A; end 具体实现代码如下: % Project 1
9 _! z* }1 j0 G% v. a& A7 `% SMIE name:ChenYu class:1202 nunmber:12353032% N: n9 ]. U! E" v- ?! u4 W
% Change nondorminant to dorminant matrix
5 i7 E6 W6 u, w& Q8 Z. s% this method is adapted for the matrix which can be changed to dorminant/ _* ~, _0 U% _6 p
% matrix only using row exchangement
7 a1 X+ F8 _% Y/ B& D1 }. H: c% Input :A matrix0 c8 N! i4 t& X1 v2 H; p" `% p
% Output:A matrix which maybe dorminant
6 P) g+ t9 }( `0 D% R. hfunction method1(A)& j, h0 N) f: }+ M, u
[row,volumn] = size(A);# h' \# m* o) |; O( p9 j
record = ones(volumn,3); %use this matrix to record everyline situation/ F6 K/ d$ K# O' [8 n
flag = 1; %first volumn record if the matrix can change to
: B) B- b' F8 k# [! J) Lfor i = 1:row %dominance,which row the row will �long.Second volumn record
9 H' \4 Y' P+ u: u every_line = A(i,:); %whether the matrix satisfy the necessity %that everydominance, J: y# a E# ?% [5 C. J2 \4 E( _
record(i,3) = i; %third volumn record the rowth5 z. N4 w! ]7 U' ^
[record(i,1),record(i,2)] = which_row(every_line);
! j5 B; n: R% X1 _2 u# T9 U: b2 | if record(i,2) == 0
2 k6 D6 W& L( |" w9 ~+ [ disp('This Matrix cannot change to dorminant matrix by row exchange.');& b$ p/ I" E& c& u0 B5 K
flag = 0;
: l1 |6 D, n8 X* g- \ break;- _0 o4 O" [8 J
end" v: q9 w5 H4 M9 {7 G# j
end
5 `1 n) ]* w$ [5 E5 Vif flag == 1! C* ]/ n4 Q2 D) [- k
for i = 1:row-1
& ]1 N3 F8 m G/ o/ |6 `0 B" U1 l for j = 1:row
3 j6 k$ O4 y+ y0 P if record(j,1) == i %exchange line if flag = 1,which means it can be transformed6 A0 d+ P6 a9 _2 s& e
b = A(i,:); %into dorminance
6 v8 S" m! J: a0 ~! W% Y A(i,:) = A(record(j,3),:);3 e' H/ i7 N( F$ |0 Q% _7 f6 D
A(record(j,3),:) = b;8 X3 m1 A$ s( ]+ F3 q$ _3 v
temp = record(j,:); T7 q/ Z2 Z7 ~8 `+ y
record(j,:) = record(i,:);0 h0 _/ J2 Q" K, h" v: p- z4 ^# U2 B
record(i,:) = temp;
! e( i: V# |6 R" Z' K2 h% [9 j break;
" a U8 p; X* E* l/ Q end1 ]4 h: f; |: ~ _
end5 u1 y2 `' k* V o
end, C" e8 V M" p
disp(A);
! i) x& |/ }1 w2 M' Aend 调用函数: % function judge_row:# s# d6 G# O Z( N
% this function is to judge whether the line is a line of dorminance and
3 [- b* N+ j( w' s7 |% return which row shuold this line stand+ p: q4 M" W- r$ l5 n3 u6 T
% Input : vector(a row of the matrix)5 m+ N& n# ^& F0 r
% Output:if(the line is dorminant) return flag = 1;6 m( u* B: t: n9 V4 S5 N0 _
% else return flag = 0.- k- \& R' ]+ Y2 u; J4 m y
function [row,flag] = which_row(a)
2 ?' g; D! l& B7 Q: x, ^$ s$ On = length(a);% R. p3 o$ ?/ A
max = a(1);
0 G9 O, Y2 @- D8 n# }7 t$ [' Zflag = 0;0 ?. @, M/ v0 B! F& b0 t0 ~4 T
row = 1;
! [5 H% ]- c8 ^# U0 D4 {for i = 2:n9 k ^4 _, B- \! y' r( {
if max < a(i) %fing the max value of the line, p# |& U, ?4 D/ R; s" C& K0 U, a
max = a(i); %it's easy for us to know that if the max value is3 \& X5 r ] j3 }# Z7 K8 f4 v
row = i; %larger than the rest of all sum1 v0 V1 K2 A- K/ K: h6 {* g3 N& N5 L( }
end %than the line is dorminance
1 a' R7 ^- G k3 zend
$ c0 d& \ Z* x+ q0 X/ land = 0;
9 W7 J; J! u2 Ufor i = 1:n
$ q h+ o# L$ z- G' E if i ~= row %compare maxvalue and rest sum2 M0 G6 S9 p# a- U6 V! a! s/ z
and = and + a(i);
5 g& V% v$ E B end( G0 W' R* q; h9 r. |
end
) h3 g8 ]$ e- ` Y0 Q4 k& ]$ d5 iif a(row) >= and
9 W& u8 ^! r6 i flag = 1;( N1 `4 `+ c7 N( U
end % W* s+ z) r9 l( q9 Y) U
|