完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
扫一扫,分享给好友
模型一程序
clear;clc; AB=140;BC=255;CD=255;DE=65; x_obj=input('x_Obj='); y_obj=input('y_Obj='); z_obj=input('z_Obj='); obj=[x_obj,y_obj,z_obj]; %=========Theta取值范围==== max_range=[180 125+90 138 270 133.5+90]; min_range=[-180 -125+90 -138 -270 -120+90]; %=========Theta取值范围end==== M=400;T=5000;pc=0.8;pm=0.1;%M为种群规模,T为迭代次数,PC为交叉率,PM为变异率 for i=1:M for j=1:5 pop(i,j)=round(((min_range(j)+(max_range(j)-min_range(j))*rand))*10)*0.1;%每个种群的取值 end E(i,1)=-(BC*cos(pop(i,2)*(pi/180))+CD*cos(pop(i,3)*(pi/180)))*sin(pop(i,1)*(pi/180))-DE*cos(pop(i,5)*(pi/180))*sin(pop(i,4)*(pi/180)); E(i,2)=(BC*cos(pop(i,2)*(pi/180))+CD*cos(pop(i,3)*(pi/180)))*cos(pop(i,1)*(pi/180))+DE*sin(pop(i,5)*(pi/180)); E(i,3)=BC*sin(pop(i,2)*(pi/180))+AB+CD*sin(pop(i,3)*(pi/180))-DE*cos(pop(i,5)*(pi/180))*cos(pop(i,4)*(pi/180)); end %=======误差作为目标函数===== for i=1:M Objfun(i,1)=0.99*sqrt((obj(1)-E(i,1)).^2+(obj(2)-E(i,2)).^2+(obj(3)-E(i,3)).^2)+0.01*round(0.5*round(max(abs(pop(i,:)))));%round(0.5*round(max(abs(BestofPop(:))))) end %=======误差作为目标函数end===== for t=1:T FitnV=ranking(Objfun); parent_pop=select('rws',pop,FitnV); child_pop=gafk_operator(parent_pop,t,T,pc,pm,min_range,max_range); com_pop=round([parent_pop;child_pop]*10)*0.1; [N,temp]=size(com_pop); for i=1:N E(i,1)=-(BC*cos(com_pop(i,2)*(pi/180))+CD*cos(com_pop(i,3)*(pi/180)))*sin(com_pop(i,1)*(pi/180))-DE*cos(com_pop(i,5)*(pi/180))*sin(com_pop(i,4)*(pi/180)); E(i,2)=(BC*cos(com_pop(i,2)*(pi/180))+CD*cos(com_pop(i,3)*(pi/180)))*cos(com_pop(i,1)*(pi/180))+DE*sin(com_pop(i,5)*(pi/180)); E(i,3)=BC*sin(com_pop(i,2)*(pi/180))+AB+CD*sin(com_pop(i,3)*(pi/180))-DE*cos(com_pop(i,5)*(pi/180))*cos(com_pop(i,4)*(pi/180)); Objfun_mind(i,1)=0.99*sqrt((obj(1)-E(i,1)).^2+(obj(2)-E(i,2)).^2+(obj(3)-E(i,3)).^2)+0.01*round(0.5*round(max(abs(com_pop(i,:))))); end [sorted_obj,index_obj]=sort(Objfun_mind); for k=1:M pop(k,:)=com_pop(index_obj(k),:); Objfun(k,:)=Objfun_mind(index_obj(k),:); end [best_obj(t,1),index]=min(Objfun); best_pop(t,:)=pop(index,:); best_E(t,:)=E(index,:); end [JofObj,daishu]=min(best_obj(:,1)); BestofPop=best_pop(daishu,:); BestofE=best_E(daishu,:); error=sqrt((obj(1)-BestofE(1)).^2+(obj(2)-BestofE(2)).^2+(obj(3)-BestofE(3)).^2);%误差 step=round(0.5*round(max(abs(BestofPop(:)))));%步子数 plot(best_obj(:,1),'-') www.xszlw.com 求大神帮忙哈,急用!!!! |
|
相关推荐
1个回答
|
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
1391 浏览 1 评论
200圆!求助大佬给一份VSG并网和离网模式的simulink仿真
1692 浏览 0 评论
MATLAB(3)--矩阵的引用(sub2ind、ind2sub、reshape函数使用)
2503 浏览 0 评论
2841 浏览 0 评论
4086 浏览 1 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-17 08:19 , Processed in 0.516005 second(s), Total 74, Slave 56 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号