基于麻雀搜索算法(SSA)优化PID控制器参数

博客介绍了2020新算法SSA用于优化PID控制器参数,给出部分代码,包含设定适应度函数、维度、最大迭代次数等参数的代码,还展示了单位阶跃响应和正弦输入响应的收敛曲线及控制输出量的结果图,代码有详细中文注释且可更改传递函数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

2020新算法SSA,优化PID控制器参数。 有详细中文注释,可更改传递函数。

部分代码如下:

% fobj = @YourCostFunction        设定适应度函数
% dim = number of your variables   设定维度
% Max_iteration = maximum number of generations 设定最大迭代次数
% SearchAgents_no = number of search agents   种群数量
% lb=[lb1,lb2,...,lbn] where lbn is the lower bound of variable n  变量下边界
% ub=[ub1,ub2,...,ubn] where ubn is the upper bound of variable n   变量上边界
% If all the variables have equal lower bound you can just
% define lb and ub as two single number numbers

% To run SSA: [Best_pos,Best_score,curve]=SSA(pop,Max_iter,lb,ub,dim,fobj)
%__________________________________________

clear all 
clc
rng('default')
SearchAgents_no=50; % Number of search agents 种群数量
Max_iteration=100; % Maximum numbef of iterations 设定最大迭代次数
lb = -5; %下边界
ub = 5;  %上边界
dim = 3; %维度pid3个参数
S = 1;% 1为单位阶跃响应,其他为正弦输入
fobj = @(X) PID_controller(X,S);%适应度函数
[Best_pos,Best_score,SSA_curve]=SSA(SearchAgents_no,Max_iteration,lb,ub,dim,fobj); %开始优化
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure
plot(SSA_curve,'Color','r','linewidth',2)
hold on
title('单位阶跃响应收敛曲线')
xlabel('迭代次数');
ylabel('最优适应度值');

axis tight
grid on
box on
legend('SSA')
[Bsu,rin,yout,error]=PID_controller(Best_pos,1);
figure('color',[1,1,1]),
plot(rin,'r--','Linewidth',2);
hold on;
plot(yout,'b-','Linewidth',2)
legend('rin','SSA-PID')
xlabel('时间');ylabel('PID控制输出量');
grid on;
title('单位阶跃响应')
disp(['PID值为:',num2str(Best_pos)]);


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
S = 2;%正弦输入
fobj = @(X) PID_controller(X,S);%适应度函数
[Best_pos,Best_score,SSA_curve]=SSA(SearchAgents_no,Max_iteration,lb,ub,dim,fobj); %开始优化
figure
plot(SSA_curve,'Color','r','linewidth',2)
hold on
title('正弦输入响应收敛曲线')
xlabel('迭代次数');
ylabel('最优适应度值');

axis tight
grid on
box on
legend('SSA')
[Bsu,rin,yout,error]=PID_controller(Best_pos,S);
figure('color',[1,1,1]),
plot(rin,'r--','Linewidth',2);
hold on;
plot(yout,'b-','Linewidth',2)
legend('rin','SSA-PID')
xlabel('时间');ylabel('PID控制输出量');
grid on;
title('正弦输入响应')
disp(['PID值为:',num2str(Best_pos)]);

完整代码:

麻雀搜索算法(SSA)优化PID控制器参数_麻雀搜索算法pid-其它文档类资源-CSDN文库

结果图:

 

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

学习不好的电气仔

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值