1 内容介绍
PID参数优化对PID控制性能起着决定性作用,针对PID参数寻优问题,提出运用一种头脑风暴算法.头脑风暴算法优化参数使系统具备更短的响应时间,更高的系统控制精度以及更好的鲁棒性,为PID控制系统的参数整定提供了参考.
2 仿真代码
clc
clear
%bso test
tic
funStr = 'sphere10D5C'; %output worksheet name
funName = @sphere; % fitness function name
rang_l = -100; % left of dynamic range sphere
rang_r = 100; % right of dynamic range
%n_p = 500; % population size
%n_d = 2; % dimension
%n_c = 5; % number of clusters
%rang_l = -100; % left of dynamic range
%rang_r = 100; % right of dynamic range
%max_iteration = 50; % maximal number of iterations
warning off all
n_p = 100; % population size
n_d = 300; % dimension
% n_c = 2; % number of clusters
% funStr = 'sphere10D5C'; %output worksheet name
% funName = @sphere; % fitness function name
% rang_l = -100; % left of dynamic range sphere
% rang_r = 100; % right of dynamic range
% funStr = 'Minima10D5C'; %output worksheet name
% funName = @Minima; % fitness function name
% rang_l = -5; % left of dynamic range rastrigin
% rang_r = 5; % right of dynamic range
% funStr = 'Griewangk10D5C'; %output worksheet name
% funName = @Griewangk; % fitness function name
% rang_l = -50; % left of dynamic range rastrigin
% rang_r = 50; % right of dynamic range
% funName = @ackley_path; % fitness function name
% rang_l = -5; % left of dynamic range rastrigin
% rang_r = 5; % right of dynamic range
% minpts = 10;
max_iteration = 2000; % maximal number of iterations
XX=1;
%P = 0;
n_c = 2;
% P = 0.6;
% for P = 0:0.1:1
for idx = 1:30 % run times
fit = bso2(funName,n_p,n_d,n_c,rang_l,rang_r,max_iteration);
%run BSO one time
if idx <27
str = native2unicode(idx + 64);
else % assume idx <53
str =['A',native2unicode(idx + 38)];
end
xlswrite('bso.xls',fit,funStr, [str,'1']);
% output best fitness over generation to EXCEL worksheet for each BSO run
['run', num2str(idx)]
opt(idx,:)=fit; %可以把列换成行 fit为一列数据
% plot(x,opt(1,:)
end
opt;
format short g
best_value = min(opt(:,max_iteration))
worst_value = max(opt(:,max_iteration))
[ln col]=size(opt);
out_put(XX,:)=sum(opt)/ln; %每一列的均值
format short g
m_value = min(out_put(XX,:))
z = 0;
for idx = 1:30
z = z+(opt(idx,max_iteration)-m_value)^2;
end
SD = z/29
XX=XX+1
% end
% save UUB out_put(n_c,:);
% plot(out_put);
% end
% save UUB out_put(n_c,:);
% plot(opt);
figure(1)
save UUB out_put;
x=1:max_iteration;
% plot(x,out_put(1,:),'b',x,out_put(2,:),'g',x,out_put(3,:),'r',x,out_put(4,:),'c',x,out_put(5,:),'m',x,out_put(6,:),'y',x,out_put(7,:),'k',x,out_put(8,:),'b--',x,out_put(9,:),'g-.',);
% legend('k=2:蓝色','k=3:绿色','k=4:红色','k=5:青色','k=6:品红色','k=7:黄色','k=8:黑色','k=9','k=10');
plot(x,out_put(1,:))%,'b',x,out_put(2,:),'g',x,out_put(3,:),'r',x,out_put(4,:),'c',x,out_put(5,:),'m',x,out_put(6,:),'y',x,out_put(7,:),'k',x,out_put(8,:),'b--',x,out_put(9,:),'g-.',x,out_put(10,:),'r:',x,out_put(11,:),'c-.');
% legend('P=0','P=0.1','P=0.2','P=0.3','P=0.4','P=0.5','P=0.6','P=0.7','P=0.8','P=0.9','P=1');
toc
img =gcf; %获取当前画图的句柄
print(img, '-dpng', '-r600', './运行结果.png') %即可得到对应格式和期望dpi的图像
3 运行结果
编辑
编辑
编辑
4 参考文献
[1]史振兴. 基于遗传算法的PID控制器参数优化与仿真[J]. 仪器仪表与分析监测, 2010(3).
[2]沈兆琪. 基于竞争机制的头脑风暴优化算法及应用研究. Diss. 曲阜师范大学.
博主简介:擅长智能优化算法、神经网络预测、信号处理、元胞自动机、图像处理、路径规划、无人机等多种领域的Matlab仿真,相关matlab代码问题可私信交流。
部分理论引用网络文献,若有侵权联系博主删除。