这个错误提示是因为在计算适应度时,需要把两个变量x和y传入到Shubert函数中,但是这个函数只接受一个2维向量作为输入,因此需要修改适应度计算的部分代码。

可以将适应度计算的部分代码修改为:

% 计算适应度 for i = 1:popSize fit(i) = Shubert(pop(i,:)); end

% 更新最优解和适应度 [currentBestFit, currentBestIdx] = min(fit); if currentBestFit < bestFit bestFit = currentBestFit; bestPos = pop(currentBestIdx,:); end

% 记录历史最优解和适应度 bestFitHistory(iter) = bestFit; bestPosHistory(iter,:) = bestPos;

其中,Shubert函数的输入仍然是一个2维向量,适应度计算只需要调用Shubert函数即可,不需要再传入x和y。


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

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