找回密码
 注册
关于网站域名变更的通知
查看: 439|回复: 1
打印 上一主题 下一主题

Matlab之将非严格占优矩阵化为严格占优矩阵

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2020-8-20 16:17 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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
# ?% V/ d; y2 q% SMIE   name:ChenYu   class:1202   nunmber:12353032* |1 q% a0 \  R/ X6 V( h% G! }
% Change nondorminant to dorminant matrix+ d; R; j3 f4 j3 B7 w' w: J
% this method is adapted for the matrix which can be changed to dorminant
" h! F7 Z$ ], h% matrix only using row exchangement2 I/ U* {2 F: k1 k# G
% Input :A matrix
% v: G6 K- T2 n& E# o6 J# J% Output:A matrix which maybe dorminant. C+ A2 K7 ~3 F8 U
function method1(A)
* w  `7 A3 q& [. J& v[row,volumn] = size(A);
  w; {5 n- D  xrecord = ones(volumn,3);                 %use this matrix to record everyline situation
9 H8 g1 L6 |, F: @( u0 h: wflag   = 1;                              %first volumn record if the matrix can change to; T8 |4 ]* `4 s
for i = 1:row                            %dominance,which row the row will

                                         �long.Second volumn record
5 [4 f; q/ v3 L$ o    every_line                = A(i,:);  %whether the matrix satisfy the necessity

                                         %that everydominance* Q# W+ G  Z  v+ u3 @  V( J
    record(i,3)               = i;       %third volumn record the rowth
7 i& ]$ k+ U" }2 t2 }) U    [record(i,1),record(i,2)] = which_row(every_line);
( F. W8 ~/ ?0 t0 C" e( v) X  w& J    if  record(i,2)           == 07 n, C+ a$ L8 J
        disp('This Matrix cannot change to dorminant matrix by row exchange.');3 `' L/ p. e' R% t/ I  K
        flag                  = 0;
/ g, ^; W9 `+ ^7 V5 g6 {* v5 L        break;/ e$ t# N  w3 e8 k, Q- @
    end" U/ Y: v: s8 |) C: g5 \
end* _" J/ g7 H& e
if flag == 1' ?" {* x: u/ j; @; T
    for i = 1:row-11 M* i3 P# P5 Y: q/ _% S
        for j = 1:row6 I5 j: K; A4 Z: S
            if record(j,1) == i         %exchange line if flag = 1,which means it can be transformed, Z4 {1 u9 w8 ^* Y' H' ]
                b                = A(i,:);             %into dorminance: x' a5 Q  T$ v. h6 w
                A(i,:)           = A(record(j,3),:);6 X9 m8 `$ p$ y* J1 ?
                A(record(j,3),:) = b;7 f% [) F5 d5 G- C+ [; k" x; f
                temp             = record(j,:);% G/ V, t8 U+ U0 l+ P$ f8 E
                record(j,:)      = record(i,:);) U3 w2 n$ c4 `* p! w# ]
                record(i,:)      = temp;( t* ^% _. Y7 @. y$ x
                break;
, n8 C# z# ~! S, Y            end$ q/ Z0 E! A( l1 M( D
        end3 y6 H8 [5 _6 x: a
    end- x/ X4 i3 _( n
    disp(A);
/ M" [' P0 h; {8 _& Gend

调用函数:

% function judge_row:
- e- D1 B! }, ~4 D& H0 F# G4 f% this function is to judge whether the line is a line of dorminance and
$ |, X" O( C0 ]1 r! e- j7 t% return which row shuold this line stand7 J: D$ _- I8 C0 W
% Input : vector(a row of the matrix)
  r# `* {; S% u8 w2 L% Output:if(the line is dorminant) return flag = 1;
9 y2 k0 o. q9 T& O5 Z8 ~: z%                             else return flag = 0.
, L; ~8 v) l" f, Ffunction [row,flag] = which_row(a)
" U; [2 }% Y  n: [6 f' Sn = length(a);
, m( ~7 r5 t1 y+ Smax  = a(1);. C1 b$ D' ]7 y# E
flag = 0;
5 h& v. H0 D# e0 j7 E8 A( W: l6 Zrow  = 1;, s' \# c, a& \' d
for i = 2:n
# R* {0 U$ W' Q0 }    if max < a(i)          %fing the max value of the line$ Q1 P+ `1 q5 A) t2 f
       max = a(i);         %it's easy for us to know that if the max value is
, p# f4 ]% b, m& O% g+ K: r, B       row = i;            %larger than the rest of all sum
$ q1 n; n" [% O. O6 h9 k) O    end                    %than the line is dorminance( C: i  U" j( B7 c
end
+ U' q7 K9 a8 Eand = 0;: t$ x- K) O* f( _2 f
for i = 1:n
3 N9 V  N+ V- [4 W  t; U" {/ R   if i ~= row             %compare maxvalue and rest sum
  D5 `" x5 U2 w4 Z+ j- q% H6 a        and = and + a(i);
$ P1 h; G4 k$ F0 r$ W# u* c    end
7 w- [0 s8 J0 k3 Y" ?4 `: Yend
: V+ T0 E) n2 {: m8 Yif a(row) >= and
; d3 L/ ~+ t& Q$ _9 [5 `$ ^    flag = 1;7 r% S+ `) ?- P" P5 ^% d# q
end

4 l; W% p0 h) W8 }1 o

该用户从未签到

2#
发表于 2020-8-20 16:49 | 只看该作者
代码有点长啊,我泡泡试试
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

推荐内容上一条 /1 下一条

EDA365公众号

关于我们|手机版|EDA365电子论坛网 ( 粤ICP备18020198号-1 )

GMT+8, 2025-6-23 15:56 , Processed in 0.093750 second(s), 23 queries , Gzip On.

深圳市墨知创新科技有限公司

地址:深圳市南山区科技生态园2栋A座805 电话:19926409050

快速回复 返回顶部 返回列表