资源描述
附录2、各章节中编程计算的MatLab程序2.1模糊综合评判计算程序模糊综合评判的过程:Q、灰色关联分析,求权重(程序见Relation);9、模糊聚类分析,划分等级(程序见F_class);Q、隶属度计算,求隶属函数(程序见Subjection和subject);9、模糊综合评判,计算各单元等级(程序见F_judge)。各步骤的程序如下:(1) Relation :灰色关联分析程序主程序:%灰色关联分析:-母序列必须置为第一行!即x(1,:) clear;sq=-母指标,断层分维值,隔水层厚度,太会含水层水压,开采深度; m=5;n=81;fid=fopen(data1_no E_ZH.dat,r);X_t=fscanf(fid,*%g*,K m);% 从数据文件读入数据。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-1for j=1:nif maxDT(i,j)min=DT(i,j);endendendyita=0.5;fori=1:m-1gama_t(i)=0;for j=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);end fori=1:m weight(i)=gama(i)/gama_all; disp(sq(i),disp(weight(i) end子程序:initia_MAX(X,n)function X1=initia_MAX(X,n)%初始化,亦即无量纲化对地质数据,采用最大值化为宜。max=X(1); fori=1:n if maxzeros(n,n)tr0=1;endendotherwisedisp(You input the wrong value!); enddisp(r);r_t=r;fori=1:1000rr=multiply_F(r_t,r_t);ifrr=r_tdisp(OK!);break;elser_t=rr;disp(NOT OK! Cycle times is:);disp(i); end enddisp(rr);tr=y;whiletr=Y|tr=ynmta=input(Input the value of nmta: ); fori=1:n for j=1:nifrr(i,j)=nmtaR(i,j)=1;elseR(i,j)=0;endendenddisp(R);fori=1:nk=1;for j=i:nif R(i,j)=1C_t(k)=j;k=k+1;endendCi=C_t;disp(Ci);clearC_t;endtr=input(Are you go on ? (Y/N),s);end n_class=n;fori=n:-1:1for j=i-1:-1:1x=Ci;y=Cj;for k=1:length(Cj)for l=1:length(Ci)if x(l)=y(k)Ci=0;n_class=n_class-1;continue;endendendendenddisp(The number of classes is:);disp(n_class);disp(They are as follow:);fori=1:ndisp(Ci);end(3) Subjection:隶属函数计算程序(配合子程序sugject)主程序:%建立隶属函数一一即某单元(i)在某项指标上(Ui)对某评语等级(Vj)的隶属度(Rij)o clear;M=0.002 0.0040.006 0.0080.0100.0120.014 0.0160.0180.020;0.024 0.0280.032 0.0360.0400.0440.048 0.0520.0560.060;0.066 0.0720.078 0.0840.0900.0960.102 0.1080.1140.120;0.126 0.1320.138 0.1440.1500.1560.162 0.1680.1740.180;F=7.515.022.530.037.545.052.560.067.575.0;82.590.097.5 105.0112.5 120.0 127.5 135.0142.5150.0;175.0 200.0225.0 250.0275.0300.0325.0 350.0375.0400.0;440.0 480.0520.0 560.0600.0640.0680.0 720.0760.0800.0;Q=0.25 0.500.75 1.001.251.501.752.002.25 2.50;3.25 4.004.75 5.506.257.007.758.509.25 10.0;11.0 12.013.0 14.015.016.017.018.019.0 20.0;30.0 40.050.0 60.070.080.090.0100.110.120.;A= 0.51.01.5 2.02.53.03.54.04.55.0;5.35.65.96.26.5 6.8 7.17.47.78.0;8.48.89.29.6 10.0 10.4 10.8 11.211.612.0;13.0 14.015.0 16.017.018.019.020.021.0 22.0;R=0.025 0.0500.075 0.1000.1250.1500.175 0.2000.2250.250;0.265 0.2800.295 0.3100.3250.3400.355 0.3700.3850.400;0.420 0.4400.460 0.4800.5000.5200.540 0.5600.5800.600;0.620 0.6400.660 0.6800.7000.7200.740 0.7600.7800.800;D=0.20 0.400.60 0.801.001.201.401.601.80 2.00;2.20 2.402.60 2.803.003.203.403.603.80 4.00;4.40 4.805.20 5.606.006.406.807.207.60 8.00;8.40 8.809.20 9.6010.010.410.811.211.6 12.0;H=6121824303642485460;646872768084889296 100;105 110 115120 125130135 140 145150;155 160 165170 175180185 190 195200;S=0.01 0.020.03 0.040.050.060.070.080.09 0.10;0.11 0.120.13 0.140.150.160.170.180.19 0.20;0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.30;0.32 0.34 0.36 0.38 0.40 0.42 0.44 0.46 0.48 0.50;fid=fopen(subjec_dat.dat,r);A_t=fscanf(fid,%g,8 34);% 从数据文件读入数据。fclose(fid);A=A_t; %各单元(行数)的各项指标(列数)统计结果(矩阵)%注:34个单元,每个单元8项指标,每个指标4个评语等级,故要生成34个8X4矩阵。m0=4; %评语集的维数;m=34;n=8; %指标集的维数,m一单元个数,n 一指标个数; for j=1:n %第一循环开始 switch j case 1X_T=M;ver=0;指标值为升序时ver=0,降序时ver=1,下同! case 2X_T=F;ver=0; case 3X_T=Q;ver=0; case 4X_T=A;ver=0; case 5X_T=R;ver=0; case 6X_T=D;ver=0; case 7X_T=H;ver=0;case 8X_T=S;ver=0;otherwisedisp(指标个数 8修改程序!);endfor i=1:m %第二循环开始for k=1:m0 第三循环开始X=A(i,j),X_T(k,:);switchver case 0 if k=1 chs=1;else if k=m chs=3;else chs=2;end end case 1 if k=1 chs=3;else if k=m chs=1;else chs=2;end end endR_T=subject(X,length(X),chs);R(j,k,i)=R_T(1);end 第三循环结束end %第二循环结束 clear X_T;end %第一循环结束%归一化处理: clear R_T;R_T=R;一 clear R; fori=1:m for j=1:n all=0; for k=1:m0all=all+R_T(j,k,i);end for k=1:m0R(j,k,i)=R_T(j,k,i)/all; end end end%输出到文件fid=fopen(subjec_ans.dat,w); fprintf(fid,n);fori=1:mfprintf(fid,n%s%d%sn,R(,i,);for j=1:nfprintf(fid,%6.4f %6.4f %6.4f %6.4fn,R(j,:,i); end,fprintf(fid,n); end fclose(fid);disp(-各单元的指标对应各评语等级的隶属度); disp(R);子程序:subjectfunction r=subject(x,n,choice)%建立隶属函数一一即某单元(i)在某项指标上(Ui)对某评语等级(Vj)的隶属度(Rij)o x_all=0;fori=1:nx_all=x_all+x(i); endx_ave=x_all/n;dt_a=0;fori=1:ndt_a=dt_a+(x(i)-x_ave)八2; enddt2=dt_a/(n-1);% disp(Input the value of choice:);% choice=input(1-偏小型 2-中间型3-偏大型 ); switch choice case 1 fori=1:nif x(i)=x_aver(i)=1;elser(i)=exp(-(x(i)-x_ave)八2/dt2);endendotherwisedisp(The value of choice is wrong !);end(4) F_judge:模糊综合评判程序%模糊评判一一矩阵相乘clearA=0.153 0.160 0.151 0.094 0.088 0.117 0.096 0.141; % 权重集(矩阵)m0=4;n=8; %评价矩阵维数,m0 一评语集的维数,n 一指标个数;m=34; %单元个数;fid=fopen(subjec_ans.dat,r);fori=1:mTmp=fscanf(fid,%s,1);R_t=fscanf(fid,%g,m0 n);% 从数据文件读入数据。Ri=R_t;endfclose(fid);fori=1:mBi=A*Ri;endfid=fopen(F_judge_ans.dat,w);fprintf(fid,%sn,The answers:);fprintf(fid,%sn,IIIIIIW);fprintf(%sn,The answers:);fprintf(%sn,IIIIIIW);fori=1:mdisp(Bi);fprintf(fid,%6.4f %6.4f%6.4f %6.4fn,Bi);endfclose(fid);
展开阅读全文