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/ R' e9 a, [+ ^2 B8 G. W' `1 G8 L b
% SMIE name:ChenYu class:1202 nunmber:12353032
6 ?- Q9 U; B X6 O1 b `( D1 d% Change nondorminant to dorminant matrix+ C- f6 r# Z4 P
% this method is adapted for the matrix which can be changed to dorminant Q4 {$ S) ]7 L: w$ ~/ O6 M, l& m
% matrix only using row exchangement
$ x- b* W7 J+ a% a0 x) S% Input :A matrix
) q1 O* U( f3 A( e% N/ p3 @% Output:A matrix which maybe dorminant0 X+ F( q! @- I! `! J3 n; _- x- v+ ^
function method1(A)
/ j! o& n6 U2 Q' P[row,volumn] = size(A);
0 I8 c0 E# M; ^0 K7 X* C( {record = ones(volumn,3); %use this matrix to record everyline situation9 o- W+ H: y- Q7 [
flag = 1; %first volumn record if the matrix can change to9 l* ]* E( B6 u6 m8 ]
for i = 1:row %dominance,which row the row will �long.Second volumn record
6 r) U. L4 J0 x( _" Q every_line = A(i,:); %whether the matrix satisfy the necessity %that everydominance
7 J& c1 J2 {' a- w) P record(i,3) = i; %third volumn record the rowth
4 A; S0 f9 V3 X2 d$ R! M [record(i,1),record(i,2)] = which_row(every_line);
7 N! G8 j! d9 l( L if record(i,2) == 02 b% u/ s. W2 H5 p: b7 E
disp('This Matrix cannot change to dorminant matrix by row exchange.');
; B ~& @1 ^3 v2 X4 F flag = 0;) J8 {( y9 C; V& W% Y- I
break;9 D4 ?7 c! d+ Y! X5 f0 G, F, m
end
0 C: _( e# ~6 S/ i0 Wend7 q- h+ y* l5 c9 a Q- g+ T
if flag == 1
0 e1 ^# i: y8 g' W" b Q for i = 1:row-1
; r4 @0 l. R& e3 q) V for j = 1:row2 i5 I+ r `- Z0 A4 G- T
if record(j,1) == i %exchange line if flag = 1,which means it can be transformed
! w; A. B" y1 C1 b4 a: N b = A(i,:); %into dorminance Q! C' @, X' Q
A(i,:) = A(record(j,3),:);
9 E% m H* {% G- ] I A(record(j,3),:) = b;! G" C3 M; E! P# h. ?/ Z
temp = record(j,:);
/ @% j( ]6 l" u. v. B0 ]# J& R record(j,:) = record(i,:);1 ~6 J4 R9 @; [& b Y0 r+ h# o
record(i,:) = temp;
5 O; ^1 x% G3 L4 Z3 y2 ] break;( |/ V6 j/ s3 q0 Z( E$ h
end) f0 o9 a0 G6 p/ d ?! n
end( R7 r, H$ ^ r6 \4 g9 M
end5 R% z: e6 `; B' B, O. T( P4 Z5 H
disp(A);
( I3 F+ b: y; b$ _/ m+ e: [% aend 调用函数: % function judge_row:
8 v3 O: S" L6 k* \2 Y% this function is to judge whether the line is a line of dorminance and5 ~" b- [" j$ P% y
% return which row shuold this line stand
' X' f' o; K& h% U( S! g' m. j: g% Input : vector(a row of the matrix)
- d- m, _7 j" l) v7 h/ [3 n) ]. j' W% Output:if(the line is dorminant) return flag = 1;
) I- F/ Y) }2 l) X% else return flag = 0.; s, Y3 E4 I9 h! ]3 f
function [row,flag] = which_row(a)& r* ^ v* \4 \9 O* V$ Z
n = length(a); h% n, ?; o" U" F# S& V; l/ C
max = a(1);
- O) R( n3 o5 v# z1 j: r1 W% S4 Nflag = 0;
?& k7 L( d5 Orow = 1;
5 H/ ?/ t- j( |! ?- F" `8 ffor i = 2:n! t. }& Y* ?8 L) T/ P3 \% i* _; Y
if max < a(i) %fing the max value of the line' h: W* u& k& W( g0 D7 ?
max = a(i); %it's easy for us to know that if the max value is
! h9 A4 o# ^8 V- O0 u3 N row = i; %larger than the rest of all sum- l+ p' Q% y7 F4 X) R
end %than the line is dorminance! k4 h/ _/ d$ o, W
end
L: Q9 P" c; o$ N- a% gand = 0;
+ J w) m. @2 n: v5 v* b% W; _for i = 1:n8 V1 J$ Q% s" P( I' @- s& o2 [
if i ~= row %compare maxvalue and rest sum
1 i; z: {2 i. _8 k. Q and = and + a(i);
% p: s& g: L$ I D- E4 T# d end" i5 R8 X' e3 ~+ P
end7 C3 r A+ \) y" _1 H
if a(row) >= and0 S. l, \* d6 c: a* G
flag = 1;
m- c/ l& c3 Kend
# m1 g$ l) U3 x, r5 l4 B2 W* n/ A |