在Shubert函数中,输入参数为一个2维向量,但是在粒子群优化算法的迭代中,fit(i) = Shubert(pop(i,:))中pop(i,:)只是一个1维向量,需要将其转化为2维向量再传入Shubert函数中。修改方法如下:

将Shubert函数中的

f = prod(sin((repmat(1:5,2,1).*repmat(x',1,5))+repmat([1;2],1,5)).*2.0,2) * s1 * s2;

修改为

f = prod(sin((repmat(1:5,2,1).*repmat([x(1),x(2)]',1,5))+repmat([1;2],1,5)).*2.0,2) * s1 * s2;

即可解决问题。

使用粒子群优化算法计算Shubert函数的最优解function f = Shubertx x为一个2维向量 计算Shubert函数的值s1 = 0;s2 = 0;for i = 15 s1 = s1 + icosi+1x1+i; s2 = s2 + icosi+1x2+i;endf = prodsinrepmat1521repmatx15+repmat1;215202 s1 s2

原文地址: https://www.cveoy.top/t/topic/cdPz 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录