研赛数学建模期间编写的程序拿出来分享下:
(纤细题目见2007年研究生数学建模竞赛试题B)
编码
function pop = bianma(popsize)
pop=4*(round(10*rand(popsize,5))/10)-2;
建立适应度函数
function f = fitness(pop,dian,ztjd)
popsize=size(pop,1);dian=dian';
f=zeros(1,popsize);
for i=1:popsize
ag1=pop(i,1)+ztjd(1);ag2=pop(i,2)+ztjd(2);ag3=pop(i,3)+ztjd(3);ag4=pop(i,4)+ztjd(4);ag5=pop(i,5)+ztjd(5);
ag1=ag1*pi/180;ag2=ag2*pi/180;ag3=ag3*pi/180;ag4=ag4*pi/180;ag5=ag5*pi/180;
T1=[cos(ag1),-sin(ag1),0,0;sin(ag1),cos(ag1),0,0;0,0,1,140;0,0,0,1];
T2=[1,0,0,0;0,cos(ag2),-sin(ag2),-255*sin(ag2);0,sin(ag2),cos(ag2),255*cos(ag2);0,0,0,1];
T3=[1,0,0,0;0,cos(ag3),-sin(ag3),0;0,sin(ag3),cos(ag3),0;0,0,0,1];
T4=[cos(ag4),-sin(ag4),0,0;sin(ag4),cos(ag4),0,0;0,0,1,255;0,0,0,1];