• 大小: 28KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-06-17
  • 语言: Matlab
  • 标签: pso  pid  

资源简介

用matlab实现粒子群算法实现对PID参数的优化,实现对系统的控制

资源截图

代码片段和文件信息

%% Tunning of PID controller using Particle Swarm Optimization 
%
%
% Author: Wael Mansour (wael192@yahoo.com)
%
% MSc Student Electrical Enginering Dept 
% Faculty of Engineering Cairo University Egypt
%

%% Initialization
clear
clc
n = 50;           % Size of the swarm “ no of birds “
bird_setp  =50;   % Maximum number of “birds steps“
dim = 2;          % Dimension of the problem

c2 =1.2;          % PSO parameter C1 
c1 = 0.12;        % PSO parameter C2 
w =0.9;           % pso momentum or inertia  
fitness=0*ones(nbird_setp);

                                       %-----------------------------%
                                       %    initialize the parameter %
                                       %-----------------------------%
                                       
R1 = rand(dim n);
R2 = rand(dim n);
current_fitness =0*ones(n1);

                                 %------------------------------------------------%
                                 % Initializing swarm and velocities and position %
                                 %------------------------------------------------%
                                 
current_position = 10*(rand(dim n)-.5);
velocity = .3*randn(dim n) ;
local_best_position  = current_position ;


                                 %-------------------------------------------%
                                 %     Evaluate initial population           %           
                                 %-------------------------------------------%

for i = 1:n
    current_fitness(i) = tracklsq(current_position(:i));    
end


local_best_fitness  = current_fitness ;
[global_best_fitnessg] = min(local_best_fitness) ;

for i=1:n
    globl_best_position(:i) = local_best_position(:g) ;
end
                                               %-------------------%
                                               %  VELOCITY UPDATE  %
                                               %-------------------%

velocity = w *velocity + c1*(R1.*(local_best_position-current_position)) + c2*(R2.*(globl_best_position-current_position));

                                               %------------------%
                                               %   SWARMUPDATE    %
                                               %------------------%
                                               
            
current_position = current_position + velocity ;

                                               %------------------------%
                                               %  evaluate anew swarm   %
                                               %------------------------%
                                               

%% Main Loop
iter = 0 ;        % Iterations抍ounter
while  ( iter < bird_setp )
iter = iter + 1;

for i = 1:n
current_fitness(i) = tracklsq(current_position(:i)) ;    
end


for i = 1 : n
        if current_fitness(i) < local_best_fitness(i

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-05-20 10:18  PID by PSO\
     文件        3930  2008-06-11 19:59  PID by PSO\PSO.asv
     文件        3936  2008-06-11 19:59  PID by PSO\PSO.m
     目录           0  2018-05-20 10:18  PID by PSO\html\
     文件       14694  2008-06-11 20:03  PID by PSO\html\PSO.html
     文件        2679  2008-06-11 20:03  PID by PSO\html\PSO.png
     文件        4307  2008-06-11 19:59  PID by PSO\html\PSO_01.png
     文件        4671  2008-06-11 20:03  PID by PSO\html\PSO_02.png
     文件        9728  2008-06-11 20:36  PID by PSO\html\Thumbs.db
     文件       29696  2008-01-18 21:25  PID by PSO\optsim1.mdl
     文件         723  2008-06-11 19:38  PID by PSO\tracklsq.m

评论

共有 条评论