j) temp=y'; temp=sum(temp); for i=1:xsize(1) for j=1:xsize(2) p(i,j)=y(i,j)/temp(j); end end clear temp; %计算 e(j)
15
2011 精品
k=1/log(xsize(1)); for j=1:xsize(2) tempsum=0; for i=1:xsize(1) temp=p(i,j)*log(p(i,j)); tempsum=tempsum+temp; end e(j)=-k*tempsum; end %求差异性系数 g(j) g=1-e; clear temp; temp=sum(g); for j=1:xsize(2) w(j)=g(j)./temp; end w return 问题三 MATLAB 代码: 代码: %shijixiaoyiguihua.m function temp clear all clc c=[8991 17322 5481 7266 1731 35256 6375 19983 29946 7101 7794 8220 744 2850 2715 3645 4767 2796 23112 10503 1347]; e=[0.0461 0.0548 0.0397 0.0452 0.0497 0.0537 0.0391 0.0585 0.0552 0.0444 0.043 0.0505 0.039 0.0537 0.0533 0.0374 0.0456 0.046 0.0593 0.0528 0.0327]; price=[225674.1 486748.2 121130.1 189916 65951.1 1131718 128137.5 561522.3 7339765 199538.1 304745.4 206322 20162.4 100035 98011.5 102424.5 185913 64587.6 834343.2 305637.3 60749.7]; tmp=c./e; ptmp=tmp; pc=c; eachprice=price./c; x=zeros(1,21);
16
2011 精品
ppx=round(c*0.03); x=ppx+x; pprice=ppx.*eachprice; px=x; STD=std(ptmp); while sum(eachprice.*px)<=(1000000-sum(pprice)) [pnumber pindex]=min(ptmp); px(pindex)=px(pindex)+1; pc(pindex)=pc(pindex)+1; ptmp=pc./e; ptemp=std(ptmp); STD=[STD ptemp]; end n=size(STD,2); STD=STD(1,[1:n-1]); [number index]=min(STD); for i=1:index [pnumber pindex]=min(tmp); x(pindex)=x(pindex)+1; c(pindex)=c(pindex)+1; tmp=c./e; end x sumprice=sum(x.*eachprice)+sum(pprice) return 代码: 问题四 MATLAB 代码: %wenti4.m function temp clear all clc disp('读入一个 txt 的矩阵数据文件\n');
17
2011 精品
disp('数据的顺序为: 重点学科和重点专业 常用 重要公共课 技能课图书 出借 册书\n'); [filename pathname]=uigetfile('*.txt','请选择数据'); name=[pathname filename]; dif=fopen(name,'r'); x1=fscanf (dif,'%f'); n=size(x,1); w=[0.3647 0.2941 0.1795 0.0946 0.0672];%人为定义的一个奴隶度关系得到的 权向量 xsum=sum(x1); for i=1:n x1(i,:)=x1(i,:)./xsum; end x1=x1'; w1=w*x1; %得到第一个 w1 disp('请输入第二个数的 txt 文件的矩阵数据\n'); [filename pathname]=uigetfile('*.txt','输入的数据格式为:出借册数 册数 出借时总时间 出借种类 内容种类\n'); name=[pathname filename]; if filename==0 return end fid=fopen (name,'r+'); data=fscanf (fid,'%c'); data=str2num(data); x2=[data(1)/data(2) data(3)/data(1) data(4)/data(5)]; %对 x2 标准化得到 y xsize=size(x2); temp=max(x2); for i=1:xsize(1) y(i,:)=x2(i,:)./temp; end clear temp; %计算 p(i,j) temp=y'; temp=sum(temp); for i=1:xsize(1)
18
2011 精品
for j=1:xsize(2) p(i,j)=y(i,j)/temp(j); end end clear temp; %计算 e(j) k=1/log(xsize(1)); for j=1:xsize(2) tempsum=0; for i=1:xsize(1) temp=p(i,j)*log(p(i,j)); tempsum=tempsum+temp; end e(j)=-k*tempsum; end %求差异性系数 g(j) g=1-e; clear temp; temp=sum(g); for j=1:xsize(2) w(j)=g(j)./temp; end xxsum=sum(x2); for i=1:xsize(1) x2=x2./xxsum; end x2=x2'; w2=w*x2; %得到第二 w2 数据 w3=(data(1)/data(4))/
(data(2)/data(5)); pw=[w1 w2 w3]; ppw=pw; ppwsum=sum(ppw); n=size(ppw,1); for i=1:n ppw(i,:)=pw(i,:)./ppwsum;
19
2011 精品
end R=ppw'; %对 pw 标准化得到 y pwsize=size(pw); temp=max(pw); for i=1:pwsize(1) y(i,:)=pw(i,:)./temp; end clear temp; %计算 p(i,j) temp=y'; temp=sum(temp); for i=1:pwsize(1) for j=1:pwsize(2) p(i,j)=y(i,j)/temp(j); end end clear temp; %计算 e(j) k=1/log(pwsize(1)); for j=1:pwsize(2) tempsum=0; for i=1:pwsize(1) temp=p(i,j)*log(p(i,j)); tempsum=tempsum+temp; end e(j)=-k*tempsum; end %求差异性系数 g(j) g=1-e; clear temp; temp=sum(g); for j=1:pwsize(2) ppw(j)=g(j)./temp;
20
2011 精品
end pxxsum=sum(ppw); for i=1:xsize(1) ppw=ppw./pxxsum; end ppw=ppw'; w=ppw*pw; %得到 w 数据 e=w*R; c=data(1); disp('请输入一个 txt 的图书总价数据的矩阵'); [filename pathname]=uigetfile('*.txt','请择择文件'); name=[pathname filename]; dif=fopen(name,'r'); price=fscanf (dif,'%f'); %c=[8991 17322 5481 7266 1731 35256 6375 19983 29946 7101 7794 8220 744 2850 2715 3645 4767 2796 23112 10503 1347]; %e=[0.0461 0.0548 0.0397 0.0452 0.0497 0.0537 0.0391 0.0585 0.0552 0.0444 0.043 0.0505 0.039 0.0537 0.0533 0.0374 0.0456 0.046 0.0593 0.0528 0.0327]; %price=[225674.1 486748.2 121130.1 189916 65951.1 1131718 128137.5 561522.3 7339765 199538.1 304745.4 206322 20162.4 100035 98011.5 102424.5 185913 64587.6 834343.2 305637.3 60749.7]; tmp=c./e; ptmp=tmp; pc=c; eachprice=price./c; x=zeros(1,21); ppx=round(c*0.03); x=ppx+x; pprice=ppx.*eachprice; sum(pprice) px=x; STD=std(ptmp); zongzijin=input('请输入总资金数:(单位\元)'); while sum(eachprice.*px)<=(zongzijin-sum(pprice)) [pnumber pindex]=min(ptmp); px(pindex)=px(pindex)+1; pc(pindex)=pc(pindex)+1;
21
2011 精品
ptmp=pc./e; ptemp=std(ptmp); STD=[STD ptemp]; end n=size(STD,2); STD=STD(1,[1:n-1]); [number index]=min(STD); for i=1:index [pnumber pindex]=min(tmp); x(pindex)=x(pindex)+1; c(pindex)=c(pindex)+1; tmp=c./e; end x sumprice=sum(x.*eachprice)+sum(pprice) return
22

