% 用遗传算法求 20+x^2+y^2-10*(cos(2*pi*x)+cos(2*pi*y) 的最小值
function my_ga_test1()
figure
ezsurf(@(x,y)20+x^2+y^2-10*(cos(2*pi*x)+cos(2*pi*y)),[-5 5],[-5 5])
text(0,0,85,'\downarrowglobelmin(0,0)','EdgeColor','red','FontSize',18,'BackgroundColor',[.7 .9 .7]);
figure
ezcontour(@(x,y)20+x^2+y^2-10*(cos(2*pi*x)+cos(2*pi*y)),[-1 1],[-1 1])
text(0,0,'\downarrowglobelmin(0,0)','FontSize',18);
disp('please press any key to continue.....')
pause()
FitnessFunction = @simple_fitness;
numberOfVariables = 2;
opt= gaoptimset('PlotFcns',{@gaplotbestf,@gaplotmaxconstr},'Display','iter',...
'PopulationSize',50, 'Generations',100,'StallGenLimit', 50,'StallTimeLimit',50,'CrossoverFraction',0.8,'MutationFcn',@mutationadaptfeasible);
[x_ga,fval_ga] = ga(FitnessFunction,numberOfVariables,[],[],[],[],[],[],[],opt)
x0=rand(1,2);
[x1 f1]=fminsearch(FitnessFunction,x0)
[x2 f2]=fminunc(FitnessFunction,x0)
[x_ps,fval_ps] = patternsearch(FitnessFunction,x0)
[x_sa,fval_sa]= simulannealbnd(FitnessFunction,x0)
function y = simple_fitness(x)
y = 20+x(1)^2+x(2)^2-10*(cos(2*pi*x(1))+cos(2*pi*x(2)));
MATLAB神经网络和优化算法:19 遗传算法,模式搜索,模拟退火求局部最优问题.zip
版权申诉
126 浏览量
2023-05-26
11:11:41
上传
评论
收藏 1KB ZIP 举报
![avatar](https://profile-avatar.csdnimg.cn/2ab41b4b301b4cc6861912179f3798cc_qq_41127811.jpg!1)
![avatar-vip](https://csdnimg.cn/release/downloadcmsfe/public/img/user-vip.1c89f3c5.png)
JGiser
- 粉丝: 7605
- 资源: 5113
最新资源
- delphi语言入门教程+培训大纲
- 华为HCIA-WLAN 3.0 课程视频(30 WLAN安全配置.mp4)
- 华为HCIA-WLAN 3.0 课程视频(29 WLAN网络准入控制.mp4)
- 华为HCIA-WLAN 3.0 课程视频(28 WLAN数据安全.mp4)
- 华为HCIA-WLAN 3.0 课程视频(27 WLAN接入安全.mp4)
- php语言入门教程-自学笔记
- 华为HCIA-WLAN 3.0 课程视频(26 WLAN安全威胁与防御.mp4)
- 基于Python+OpenCV的指纹识别系统+源代码+结果截图(高分项目).zip
- mysql和navicat安装包
- Val-EdgeMapVal-EdgeMap
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback-tip](https://img-home.csdnimg.cn/images/20220527035111.png)