rdecision.m

来自「清华大学运筹学课件」· M 代码 · 共 111 行

M
111
字号
% the program is with the risk decision analysis
% please input the decision matrix and the rule of your decision

input('the program is with the risk decision analysis')

m=input('Please input the line number=')
n=input('Please input the column number=')
P=input('Please input the possibility array P(n)=')
D=input('Please input the decision matrix D(m,n)=')
R=input('Please input the decision rules:maxprofit_maxpossible=1,mincost_maxpossible=2,expectation=3! R=')



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if R==1
  
    maxnumber=P(1);
    
    for j=1:n
            if P(j)>maxnumber 
                maxnumber=P(j);
            end
    end
   
    for j=1:n
         if P(j)==maxnumber
             columnnumber=j;
         end
    end

    maxbasenumber=D(1,columnnumber);
    for i=1:m
       if D(i,columnnumber)>maxbasenumber
           maxbasenumber=D(i,columnnumber);
       end
    end
    
    for i=1:m
        if D(i,columnnumber)==maxbasenumber
            input('The decision is :')
            decision=i
        end
    end
    
 
 


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
elseif R==2
   
    maxnumber2=P(1);
    
    for j=1:n
            if P(j)>maxnumber2 
                maxnumber2=P(j);
            end
    end
   
    for j=1:n
         if P(j)==maxnumber2
             columnnumber2=j;
         end
    end

    minbasenumber=D(1,columnnumber2);
    for i=1:m
       if D(i,columnnumber2)<minbasenumber
           minbasenumber=D(i,columnnumber2);
       end
    end
    
    for i=1:m
        if D(i,columnnumber2)==minbasenumber
            input('The decision is :')
            decision=i
        end
    end
   %end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
elseif R==3
    
    for i=1:m
       sumtemp=0;
        
       for j=1:n
         sumtemp=sumtemp+D(i,j)*P(j);
       end
      
       ER(i)=sumtemp;
       
    end
    
    maxer=ER(1);
    for i=1:m
        if ER(i)>maxer
            maxer=ER(i);
        end
    end
    
    for i=1:m
        if ER(i)==maxer
          input('The decision is :')
          decision=i
        end
    end
    
end
               
          

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?