PSO-PID算法优化

```

clc; 
clear;
close all;

ns=[1];
ds=[1 2 3];
G=tf(ns,ds);
step(G)
Gf=feedback(G,1);
step(Gf);
hold on


% Param PSO
c=2; w=0.7; particles=20; iteration=50; Var=3;

% search space
a=0;
b=30;

% optimization steps
c_cf=0;

% Initialization
for m=1:particles
    for n=1:Var
        v(m,n)=0;
        x(m,n)=a+rand*(b-a);
        xp(m,n)=x(m,n);
    end
    %Model param
    kp=x(m,1);
    ki=x(m,2);
    kd=x(m,3);
    
     %Model de simulation
    Gc=pid(kp,ki,kd);
    Gcf=feedback(Gc*G,1);
    y=step(Gcf);
    
    % TIAE (fonction on=bjectif)
    ff1=0;
    sim1=size(y);
    for m1=1:sim1
        ff1=ff1+((abs(y(m1)-1))*m1);
        end
    ITAE(m)=ff1;
end

% find best value
[Best_performance,location]=min(ITAE);
fg=Best_performance;
xg(1)=x(location,1);
xg(2)=x(location,2);
xg(3)=x(location,3);

for i=1:iteration

    for m=1:particles
        for n=1:Var
           v(m,n)=(w*v(m,n))+(c*rand*(xp(m,n)-x(m,n)))+(c*rand*(xg(n)-x(m,n)));
           x(m,n)=x(m,n)+v(m,n);
        end
        
        % chek bound
        for n=1:Var
            if x(m,n)<a
            x(m,n)=a;
            
            end
            if x(m,n)>b
               x(m,n)=b;
            end
        end
        %Model param
        kp=x(m,1);
        ki=x(m,2);
        kd=x(m,3);
        
        %Model de simulation
        Gc=pid(kp,ki,kd);
        Gcf=feedback(Gc*G,1);
        y=step(Gcf);
        
        
        % TIAE (fonction on=bjectif)
        ff1=0;
        sim1=size(y);
        for m1=1:sim1
            ff1=ff1+((abs(y(m1)-1))*m1);
        end
        ITAEp(m)=ff1;
        
        
        % compare Local
        if ITAEp(m)<ITAE(m)
            ITAE(m)=ITAEp(m);
            xp(m,1)=x(m,1);
            xp(m,2)=x(m,2);
            xp(m,3)=x(m,3);
        end
    
    end 
    
     [B_fg,location]=min(ITAE);
     
    %  compare global
    if B_fg<fg
        fg=B_fg;
        xg(1)=xp(location,1);
        xg(2)=xp(location,2);
        xg(3)=xp(location,3);
    end
    c_cf=c_cf+1;
    best_cf_ac(c_cf)=fg;

end

Min_ITAE=fg;
kp=xg(1)
ki=xg(2)
kd=xg(3)

Gc=pid(kp,ki,kd);
Gcf=feedback(Gc*G,1);
y=step(Gcf);

t_cf=1:c_cf;

figure
plot(t_cf,best_cf_ac,'r--','LineWidth',2),xlabel('iteration'),ylabel('cost function(TIAE)')
legend('ITAE for PSO-PID')
title('ITAE with each iteration')

```

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值