您好,欢迎访问三七文档
附录2、各章节中编程计算的MatLab程序2.1模糊综合评判计算程序模糊综合评判的过程:○1、灰色关联分析,求权重(程序见Relation);○2、模糊聚类分析,划分等级(程序见F_class);○3、隶属度计算,求隶属函数(程序见Subjection和subject);○4、模糊综合评判,计算各单元等级(程序见F_judge)。各步骤的程序如下:(1)Relation:灰色关联分析程序主程序:%灰色关联分析:--母序列必须置为第一行!即x(1,:)clear;sq={'母指标','断层分维值','隔水层厚度','太会含水层水压','开采深度'};m=5;n=81;fid=fopen('data1_noE_ZH.dat','r');X_t=fscanf(fid,'%g',[nm]);%从数据文件读入数据。fclose(fid);x=X_t';fori=1:mD(i,:)=initia_MAX(x(i,:),n);endfori=1:m-1DT(i,:)=abs(D(1,:)-D(i+1,:));endmax=DT(1,1);min=DT(1,1);fori=1:m-1forj=1:nifmaxDT(i,j)max=DT(i,j);elseifminDT(i,j)min=DT(i,j);endendendyita=0.5;fori=1:m-1gama_t(i)=0;forj=1:nxigma(i,j)=(min+yita*max)/(abs(DT(i,j))+yita*max);gama_t(i)=gama_t(i)+xigma(i,j);endendgama(1)=1.0;%母序列对自己的关联度总是为1。disp(strcat(sq(1),'-to-',sq(1))),disp(gama(1))fori=1:m-1gama(i+1)=gama_t(i)/n;disp(strcat(sq(i+1),'-to-',sq(1))),disp(gama(i+1))enddisp('归一化处理如下:')gama_all=0;fori=1:mgama_all=gama_all+gama(i);endfori=1:mweight(i)=gama(i)/gama_all;disp(sq(i)),disp(weight(i))end子程序:initia_MAX(X,n)functionX1=initia_MAX(X,n)%初始化,亦即无量纲化,对地质数据,采用最大值化为宜。max=X(1);fori=1:nifmaxX(i)max=X(i);endendX1=X./max;(2)F_class:模糊聚类程序%模糊聚类--减数法或相关系数法建立F关系。clear;m=4;n=81;fid=fopen('data_class.dat','r');X_t=fscanf(fid,'%g',[nm]);%从数据文件读入数据。fclose(fid);X=X_t;choice=input('Inputthevalueofchoice:1-相关系数法,2-绝对值减数法');switchchoicecase1fori=1:nforj=1:nxi_all=0;xj_all=0;fork=1:mxi_all=xi_all+X(i,k);xj_all=xj_all+X(j,k);endxi_ave=xi_all/m;xj_ave=xj_all/m;dt_x=0;dt_xi2=0;dt_xj2=0;fork=1:mdt_x=dt_x+abs(X(i,k)-xi_ave)*abs(X(j,k)-xj_ave);dt_xi2=dt_xi2+(X(i,k)-xi_ave)^2;dt_xj2=dt_xj2+(X(j,k)-xj_ave)^2;endr(i,j)=dt_x/(sqrt(dt_xi2)*sqrt(dt_xj2));endendcase2tr0=0;whiletr0==0c=input('Inputthevalueofc;');fori=1:nforj=1:nd_all=0;fork=1:md_all=d_all+abs(X(i,k)-X(j,k));endr(i,j)=1-c*d_all;endendifrzeros(n,n)tr0=1;endendotherwisedisp('Youinputthewrongvalue!');enddisp(r);r_t=r;fori=1:1000rr=multiply_F(r_t,r_t);ifrr==r_tdisp('OK!');break;elser_t=rr;disp('NOTOK!Cycletimesis:');disp(i);endenddisp(rr);tr='y';whiletr=='Y'|tr=='y'nmta=input('Inputthevalueofnmta:');fori=1:nforj=1:nifrr(i,j)=nmtaR(i,j)=1;elseR(i,j)=0;endendenddisp(R);fori=1:nk=1;forj=i:nifR(i,j)==1C_t(k)=j;k=k+1;endendC{i}=C_t;disp(C{i});clearC_t;endtr=input('Areyougoon?(Y/N)','s');endn_class=n;fori=n:-1:1forj=i-1:-1:1x=C{i};y=C{j};fork=1:length(C{j})forl=1:length(C{i})ifx(l)==y(k)C{i}=[0];n_class=n_class-1;continue;endendendendenddisp('Thenumberofclassesis:');disp(n_class);disp('Theyareasfollow:');fori=1:ndisp(C{i});end(3)Subjection:隶属函数计算程序(配合子程序sugject)主程序:%建立隶属函数--即某单元(i)在某项指标上(Ui)对某评语等级(Vj)的隶属度(Rij)。clear;M=[0.0020.0040.0060.0080.0100.0120.0140.0160.0180.020;0.0240.0280.0320.0360.0400.0440.0480.0520.0560.060;0.0660.0720.0780.0840.0900.0960.1020.1080.1140.120;0.1260.1320.1380.1440.1500.1560.1620.1680.1740.180];F=[7.515.022.530.037.545.052.560.067.575.0;82.590.097.5105.0112.5120.0127.5135.0142.5150.0;175.0200.0225.0250.0275.0300.0325.0350.0375.0400.0;440.0480.0520.0560.0600.0640.0680.0720.0760.0800.0];Q=[0.250.500.751.001.251.501.752.002.252.50;3.254.004.755.506.257.007.758.509.2510.0;11.012.013.014.015.016.017.018.019.020.0;30.040.050.060.070.080.090.0100.110.120.];A=[0.51.01.52.02.53.03.54.04.55.0;5.35.65.96.26.56.87.17.47.78.0;8.48.89.29.610.010.410.811.211.612.0;13.014.015.016.017.018.019.020.021.022.0];R=[0.0250.0500.0750.1000.1250.1500.1750.2000.2250.250;0.2650.2800.2950.3100.3250.3400.3550.3700.3850.400;0.4200.4400.4600.4800.5000.5200.5400.5600.5800.600;0.6200.6400.6600.6800.7000.7200.7400.7600.7800.800];D=[0.200.400.600.801.001.201.401.601.802.00;2.202.402.602.803.003.203.403.603.804.00;4.404.805.205.606.006.406.807.207.608.00;8.408.809.209.6010.010.410.811.211.612.0];H=[6121824303642485460;646872768084889296100;105110115120125130135140145150;155160165170175180185190195200];S=[0.010.020.030.040.050.060.070.080.090.10;0.110.120.130.140.150.160.170.180.190.20;0.210.220.230.240.250.260.270.280.290.30;0.320.340.360.380.400.420.440.460.480.50];fid=fopen('subjec_dat.dat','r');A_t=fscanf(fid,'%g',[834]);%从数据文件读入数据。fclose(fid);A=A_t';%各单元(行数)的各项指标(列数)统计结果(矩阵)%注:34个单元,每个单元8项指标,每个指标4个评语等级,故要生成34个8×4矩阵。m0=4;%评语集的维数;m=34;n=8;%指标集的维数,m-单元个数,n-指标个数;forj=1:n%第一循环开始switchjcase1X_T=M;ver=0;%指标值为升序时ver=0,降序时ver=1,下同!case2X_T=F;ver=0;case3X_T=Q;ver=0;case4X_T=A;ver=0;case5X_T=R;ver=0;case6X_T=D;ver=0;case7X_T=H;ver=0;case8X_T=S;ver=0;otherwisedisp('指标个数8----修改程序!');endfori=1:m%第二循环开始fork=1:m0%第三循环开始X=[A(i,j),X_T(k,:)];switchvercase0ifk==1chs=1;elseifk==mchs=3;elsechs=2;endendcase1ifk==1chs=3;elseifk==mchs=1;elsechs=2;endendendR_T=subject(X,length(X),chs);R(j,k,i)=R_T(1);end%第三循环结束end%第二循环结束clearX_T;end%第一循环结束%归一化处理:clearR_T;R_T=R;clearR;fori=1:mforj=1:nall=0;fork=1:m0all=all+R_T(j,k,i);endfork=1:m0R(j,k,i)=R_T(j,k,i)/all;endendend%输出到文件......fid=fopen('subjec_ans.dat','w');fprintf(fid,'\n');fori=1:mfprintf(fid,'\n%s%d%s\n','R(',i,')');forj=1:nfprintf(fid,'%6.4f%6.4f%6.4f%6.4f\n',R(j,:,i));end,fprintf(fid,'\n');endfclose(fid);disp('各单元的指标对应各评语等级的隶属度');disp(R);子程序:subjectfunctionr=subject(x,n,choice)%建立隶属函数--即某单元(i)
本文标题:模糊综合评价代码
链接地址:https://www.777doc.com/doc-7235421 .html