资源描述:
《大连海事大学matlab平时作业范本5》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、4.4生产计划问题max7=4・X
2、+3・x?s.t.2x]+x2<10“Xj+x2<8x2<7xpx2>01.源代码:c=[-4-3];a=[21;1l;01];b=[1087];lb=zeros(2,1);[x,fval]=1inprog(c,a,b,[],[],lb);2.程序运行:2.00006.0000fval=-26.00003.结果分析:甲机床2台,乙机床6台,最大总利润2万6000元4.5军事方案问题minz=Iog(0・9)X][+log(0.92)x12+log(0.8)x2
3、1+log(0.84)x22+log(0.85)x3I+log(0.88)x32+log(0.75)x42+log(0.8)x42+X21+X31+X41<48<32X12+X22+X32+X42<48000537.5X][+462・5X
4、2+560^2
5、+480x22+605x3l+515x32+650x4I+550x42X]]9X?],X3],X4”X2],X22,X32,X42n°1.源代码:c=[log(0.9)log(0.92)log(0.8)log(0.84)log(0.85)log
6、(0.88)log(0.75)log(0.8)];a=[l0101010;01010101;537.5462.5560480605515650550];b=[483248000];lb=zeros(8,l);[x,fval]=linprog(c,azbz[]z[],lb);2.程序运行:0.00000.00000.00000.00000.00000.000048.000030.5455fval=-20.62481.结杲分析:轻型炸弹31枚,剩余1枚轻型炸弹向4号目标投放重型炸弹48枚,5.4背包
7、问题—遗传算法1.源代码:1).主程序clearall;closeall;popsize=50;chromlength=6;pm=0•5;a=[3Z4,3,4,6,3];c=[12,12,9,16,30,12];b=12;pop=round(rand(popsize,chromlength));whilei<=200fit=fitness(pop,azbzc);maxi=max(fit);[popl,popnew]=selection(fit,pop);pop2=pmutation(popl,a
8、,b,pm);pop=pop2;i=i+lenddisp('最优解为:1);disp(popnew(1,:));disp(*物品总价值为:J;disp(maxi);1).适应度子程序functionfit=fitness(pop,a,b,c);[pxzpy]=size(pop);total=zeros(pxz1);fit=zeros(pxA1);fori=l:pxforj=l:pytotal(i)=total(i)+pop(izj)*a(j);endiftotal(i)>bfit(i,1)=0;
9、elseforj=l:pyfit(i)=fit(i)+pop(izj)*c(j);endendend2).选择子程序function[popl,popnew]=selection(fit’pop);[px,py]=size(pop);[fit1,num]=sort(fit,1descend1);fori=l:10popnew(i,:)=pop(num(i)A:);endpopl=[popnew;popnew];3).变异子程序function[poplzpopnew]=selection(fit
10、,pop);[px,py]=size(pop);[fitl,num]=sort(fit,1descend1);fori=l:10popnew(i,:)=pop(num(i)A:);endpopl=[popnew;popnew];1.程序运行:最优解为:100011物品总价值等于:545.5指派问题一模拟退火1.源代码:clearall;closeall;a=0.99;t0=100;tf=3;t=tO;value=[3353;3252;1516;46410];amount=size(value,1
11、);num=randperm(amount);fori=l:amountifnum(i)==1pop(i,:)=[1000];elseifnum(i)==2pop(iz:)=[0100];elseifnum(i)==3pop(iz:)=[0010];elseifnum(i)==4pop(i,:)=[000endendE_best=inf;pop_best=pop;whilet>=tfindl=O;ind2=0;while(indl==ind2)indl=ceil(rand.*amount);in