请帮我修改一下代码,修改要求如下:实验测试参数设置(种群大小40, 搜索维度30,迭代代数3000代,重复测试次数5次;以上);测试维度为30维;代码如下:% 粒子优化算法 clc clear % 设置初始参数 nPop = 50; % 种群数量 nVar = 2; % 变量数量 maxIter = 3000; % 最大迭代次数 c1 = 1.5; % 学习因子1 c2 = 1.5; % 学习因子2 w = 0.7; % 惯性权重 lb = [-5 -5]; % 变量下限 ub = [5 5]; % 变量上限 % 初始化种群 pop.Position = rand(nPop, nVar) .* (ub - lb) + lb; pop.Velocity = zeros(nPop, nVar); pop.Cost = zeros(nPop, 1); % 计算适应度值 for i = 1:nPop pop.Cost(i) = CostFunction(pop.Position(i,:)); end % 初始化个体最优位置和适应度值 pop.Best.Position = pop.Position; pop.Best.Cost = pop.Cost; % 初始化全局最优位置和适应度值 [globalBestCost, globalBestIndex] = min(pop.Cost); globalBest.Position = pop.Position(globalBestIndex, :); % 迭代寻找最优解 for iter = 1:maxIter for i = 1:nPop % 更新粒子速度 pop.Velocity(i,:) = w * pop.Velocity(i,:)... + c1 * rand(1,nVar) .* (pop.Best.Position(i,:) - pop.Position(i,:))... + c2 * rand(1,nVar) .* (globalBest.Position - pop.Position(i,:)); % 更新粒子位置 pop.Position(i,:) = pop.Position(i,:) + pop.Velocity(i,:); % 处理越界情况 pop.Position(i,:) = max(pop.Position(i,:), lb); pop.Position(i,:) = min(pop.Position(i,:), ub); % 计算适应度值 pop.Cost(i) = CostFunction(pop.Position(i,:)); % 更新个体最优位置和适应度值 if pop.Cost(i) < pop.Best.Cost(i) pop.Best.Position(i,:) = pop.Position(i,:); pop.Best.Cost(i) = pop.Cost(i); end % 更新全局最优位置和适应度值 if pop.Cost(i) < globalBestCost globalBest.Position = pop.Position(i,:); globalBestCost = pop.Cost(i); end end % 输出迭代过程中的最优解 disp(['Iteration ' num2str(iter) ': Best Cost = ' num2str(globalBestCost)]); end % 输出最终结果 disp('Optimization finished.'); disp(['Best Solution: x1 = ' num2str(globalBest.Position(1)) ', x2 = ' num2str(globalBest.Position(2))]); disp(['Best Cost: ' num2str(globalBestCost)]); % 适应度函数 function cost = CostFunction(x) cost = x(1)^2 + x(2)^2; end