收藏 分销(赏)

遗传算法求解函数最大值(matlab).doc

上传人:w****g 文档编号:2710649 上传时间:2024-06-04 格式:DOC 页数:5 大小:44.01KB
下载 相关 举报
遗传算法求解函数最大值(matlab).doc_第1页
第1页 / 共5页
遗传算法求解函数最大值(matlab).doc_第2页
第2页 / 共5页
遗传算法求解函数最大值(matlab).doc_第3页
第3页 / 共5页
遗传算法求解函数最大值(matlab).doc_第4页
第4页 / 共5页
遗传算法求解函数最大值(matlab).doc_第5页
第5页 / 共5页
亲,该文档总共5页,全部预览完了,如果喜欢就下载吧!
资源描述

1、遗传算法求解函数F(x1,x2)=100*(x12-x2)2+(1-x1)2;的最大值(MATLAB)%Generic Algorithm for function f(x1,x2) optimum (最大值)clear all;close all;%ParametersSize=80; G=100; CodeL=10; umax=2.048;umin=-2.048;E=round(rand(Size,2*CodeL); %Initial Code%Main Programfor k=1:1:Gtime(k)=k;for s=1:1:Sizem=E(s,:);y1=0;y2=0;%Uncodi

2、ngm1=m(1:1:CodeL);for i=1:1:CodeL y1=y1+m1(i)*2(i-1);endx1=(umax-umin)*y1/1023+umin;m2=m(CodeL+1:1:2*CodeL);for i=1:1:CodeL y2=y2+m2(i)*2(i-1);endx2=(umax-umin)*y2/1023+umin;F(s)=100*(x12-x2)2+(1-x1)2;endJi=1./(F+1);%* Step 1 : Evaluate BestJ *BestJ(k)=min(Ji);fi=F; %Fitness FunctionOderfi,Indexfi=s

3、ort(fi); %Arranging fi small to biggerBestfi=Oderfi(Size); %Let Bestfi=max(fi)BestS=E(Indexfi(Size),:); %Let BestS=E(m), m is the Indexfi belong to max(fi)bfi(k)=Bestfi;%* Step 2 : Select and Reproduct Operation* fi_sum=sum(fi); fi_Size=(Oderfi/fi_sum)*Size; fi_S=floor(fi_Size); %Selecting Bigger fi

4、 value (取整) kk=1; for i=1:1:Size for j=1:1:fi_S(i) %Select and Reproduce TempE(kk,:)=E(Indexfi(i),:); kk=kk+1; %kk is used to reproduce end end %* Step 3 : Crossover Operation *pc=0.60;n=ceil(20*rand);for i=1:2:(Size-1) temp=rand; if pctemp %Crossover Condition for j=n:1:20 TempE(i,j)=E(i+1,j); Temp

5、E(i+1,j)=E(i,j); end endendTempE(Size,:)=BestS;E=TempE; %* Step 4: Mutation Operation *%pm=0.001;%pm=0.001-1:1:Size*(0.001)/Size; %Bigger fi, smaller Pm%pm=0.0; %No mutationpm=0.1; %Big mutation for i=1:1:Size for j=1:1:2*CodeL temp=rand; if pmtemp %Mutation Condition if TempE(i,j)=0 TempE(i,j)=1; e

6、lse TempE(i,j)=0; end end end end %Guarantee TempPop(30,:) is the code belong to the best individual(max(fi)TempE(Size,:)=BestS;E=TempE;end Max_Value=BestfiBestSx1x2figure(1);plot(time,BestJ); xlabel(Times);ylabel(Best J);figure(2);plot(time,bfi);xlabel(times);ylabel(Best F);轐行绒果Map_Falue = 3.9059e+ 03BestS = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 01 = -2&0480x2 = -2.0080

展开阅读全文
相似文档                                   自信AI助手自信AI助手
猜你喜欢                                   自信AI导航自信AI导航
搜索标签

当前位置:首页 > 教育专区 > 其他

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        获赠5币

©2010-2024 宁波自信网络信息技术有限公司  版权所有

客服电话:4008-655-100  投诉/维权电话:4009-655-100

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :gzh.png    weibo.png    LOFTER.png 

客服