%% 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(n,bird_setp);
%-----------------------------%
% initialize the parameter %
%-----------------------------%
R1 = rand(dim, n);
R2 = rand(dim, n);
current_fitness =0*ones(n,1);
%------------------------------------------------%
% 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_fitness,g] = 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�counter
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)
local_best_fitness(i) = current_fitness(i);
local_best_position(:,i) = current_position(:,i) ;
end
end
[current_global_best_fitness,g] = min(local_best_fitness);
if current_global_best_fitness < global_best_fitness
global_best_fitness = current_global_best_fitness;
for i=1:n
globl_best_position(:,i) = local_best_position(:,g);
end
end
velocity = w *velocity + c1*(R1.*(local_best_position-current_position)) + c2*(R2.*(globl_best_position-current_position));
current_position = current_position + velocity;
sprintf('The value of interation iter %3.0f ', iter );
end % end of while loop its mean the end of all step that the birds move it
xx=fitness(:,50);
[Y,I] = min(xx);
current_position(:,I)
%
朱moyimi
- 粉丝: 75
- 资源: 1万+
最新资源
- 微信自动抢红包APP.zip毕业设计参考学习资料
- 为 Wireshark 能使用纯真网络 IP 数据库(QQwry)而提供的格式转换工具.zip
- 音频格式转换工具.zip学习资料程序资源
- 自用固件,合并openwrt和immortalwrt编译AX6(刷机有风险).zip
- 最新GeoLite2-City.mmdb,GeoLite2-Country.mmdb打包下载
- 基于BootStrap + Springboot + FISCO-BCOS的二手物品交易市场系统.zip
- 使用Java语言编写的九格拼游戏,找寻下曾经小时候的记忆.zip
- gakataka课堂管理系统
- 一个简单ssh(spring springMVC hibernate)游戏网站,在网上找的html模板,没有自己写UI,重点放在java后端上.zip
- 一个采用MVC架构设计、Java实现的泡泡堂游戏.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈