i have written the following code for pso based mppt but the simulink model gets stuck at one value and the duty does not change.... kindly suggest me the error
Afficher commentaires plus anciens
function D = PSO(Param, V, I)
% MPPT controller based on the Perturb & Observe algorithm.
% D output = Duty cycle of the boost converter (value between 0 and 1)
%
% V input = PV array terminal voltage (V)
% I input = PV array current (A)
%
% Param input:
%Dinit = Param(1); %Initial value for D output
Dmax = Param(2); %Maximum value for D
Dmin = Param(3); %Minimum value for D
deltaD = Param(4); %Increment value used to increase/decrease the duty cycle D
persistent D_mat_cur Power_old vel max_power_new max_power_old Power_new global_best_duty self_best_duty D_mat_new
pop_size=10;
vmin=-1*deltaD;
vmax=deltaD;
%%wmax=0.9;
%%wmin=0.4;
c1=2;
C=1;
c2=2;
if isempty(Power_old)
%%intiallize all matrices
Power_old=zeros(1,pop_size);
Power_new=zeros(1,pop_size);
vel=zeros(1,pop_size);
D_mat_new=zeros(1,pop_size);
D_mat_cur=rand(1,pop_size);
vel=rand(1,pop_size).*(vmax-vmin)+vmin;
for i=1 : pop_size
if (D_mat_cur(i)>Dmax)
D_mat_cur(i)=Dmax;
end
end
for i=1 : pop_size
if (D_mat_cur(i)<Dmin)
D_mat_cur(i)=Dmin;
end
end
for iter =1:pop_size
D=D_mat_cur(iter);
pause(0.0001)
Power_old(iter)=V*I;
end
[max_power_old,global_index]=max(Power_old);
self_best_duty=D_mat_cur;
global_best_duty=D_mat_cur(1,global_index);
end
iter=0;
max_iter=100;
while iter<max_iter
iter=iter+1;
%calculate power
for iter =1:pop_size
D=D_mat_cur(iter);
pause(0.0001)
Power_new(iter)=V*I;
end
%%update self best duty
for i=1:pop_size
if (Power_new(1,i)>Power_old(1,i))
Power_old(1,i)=Power_new(1,i);
self_best_duty(1,i)=D_mat_cur(1,i);
end
end
%%update global best duty
[max_power_new,index]=max(Power_old);
if (max_power_new>max_power_old)
max_power_old=max_power_new;
global_best_duty=D_mat_cur(1,index);
end
w=.001;
%%calculation of new velocity matrix
for i=1 :pop_size
vel(1,i)= C*(w.*vel(1,i) +c1*rand*(self_best_duty(1,i) - D_mat_cur(1,i)) +c2*rand*(global_best_duty-D_mat_cur(1,i)));
end
%%update positions
D_mat_new=D_mat_cur+ vel;
%%bring back the param that go out of the bounds
%%upper limit
for i=1 : pop_size
if (D_mat_new(1,i)>Dmax)
D_mat_new(1,i)=Dmax;
end
end
%%lower limit
for i=1 : pop_size
if (D_mat_new(1,i)<Dmin)
D_mat_new(1,i)=Dmin;
end
end
D_mat_cur=D_mat_new;
end
[~,global_ind]=max(Power_new);
D=D_mat_cur(1,global_ind);
14 commentaires
ghita bennis
le 27 Août 2016
manisha panneer
le 11 Avr 2017
hi did u find out the error? for what reason the duty cycle is not changing? because i face the same problem
lily mona
le 3 Juin 2017
kamran etivand
le 23 Nov 2017
Hello, is anyone helping me with the above code? ...... Thanks
kamran etivand
le 23 Nov 2017
Hi my friends, I wrote this code into Matlab Function. Now I do not know why the Duty Cycle does not change...
kamran etivand
le 23 Nov 2017
Modifié(e) : Walter Roberson
le 23 Nov 2017
function Dnew = PSO(Vpv,Ipv)
%%Problem Definition
persistent particle_Position particle_Cost particle_Velocity GlobalBest_Position ...
particle_Best_Position particle_Best_Cost GlobalBest_Cost
% persistent
nVar=1; % Number of Decision Variables
VarSize=[1 nVar]; % Size of Decision Variables Matrix
VarMin=0.02; % Lower Bound of Variables
VarMax=0.95; % Upper Bound of Variables
%%PSO Parameters
MaxIt=2; % Maximum Number of Iterations
nPop=3; % Population Size (Swarm Size)
phi1=2.05;
phi2=2.05;
phi=phi1+phi2;
chi=2/(phi-2+sqrt(phi^2-4*phi));
w=chi; % Inertia Weight
wdamp=1; % Inertia Weight Damping Ratio
c1=chi*phi1; % Personal Learning Coefficient
c2=chi*phi2; % Global Learning Coefficient
% Velocity Limits
VelMax=0.1*(VarMax-VarMin);
VelMin=-VelMax;
%%Initialization
if isempty(particle_Position)
particle_Position=zeros(nPop,1);
end
if isempty(particle_Cost)
particle_Cost=zeros(nPop,1);
end
if isempty(particle_Velocity)
particle_Velocity=zeros(nPop,1);
end
if isempty(particle_Best_Position)
particle_Best_Position=zeros(nPop,1);
end
if isempty(particle_Best_Cost)
particle_Best_Cost=zeros(nPop,1);
end
if isempty(GlobalBest_Cost)
GlobalBest_Cost=0;
end
if isempty(GlobalBest_Position)
GlobalBest_Position=unifrnd(VarMin,VarMax,VarSize);
end
BestCost=zeros(MaxIt,1);
nfe=zeros(MaxIt,1);
% PSO Main Loop
for it=1:MaxIt
for i=1:nPop
Dnew= particle_Position(i);
particle_Cost(i)=Vpv*Ipv;
if particle_Cost(i)>particle_Best_Cost(i)
particle_Best_Position(i)=particle_Position(i);
particle_Best_Cost(i)=particle_Cost(i);
end
% Update Global Best
if particle_Best_Cost(i)>GlobalBest_Cost
GlobalBest_Position=particle_Best_Position(i)
GlobalBest_Cost=particle_Best_Cost(i);
end
for i=1:nPop
% Update Velocity
particle_Velocity(i) = w*particle_Velocity(i) ...
+c1*rand(VarSize)*(particle_Best_Position(i)-particle_Position(i)) ...
+c2*rand(VarSize)*( GlobalBest_Position-particle_Position(i));
% Apply Velocity Limits
particle_Velocity(i) = max(particle_Velocity(i),VelMin);
particle_Velocity(i) = min(particle_Velocity(i),VelMax);
% Update Position
particle_Position(i) = particle_Position(i) + particle_Velocity(i);
% Apply Position Limits
particle_Position(i) = max(particle_Position(i),VarMin);
particle_Position(i) = min(particle_Position(i),VarMax);
% Evaluation
end
end
w=w*wdamp;
end
Dnew=GlobalBest_Position
end
MOKHLIS MOHCINE
le 19 Mar 2018
cheikhne cheikh ahmed
le 10 Avr 2018
I have the same problem, can you help me please. This is my e-mail :cheikhna12@gmail.com
himnshu kumar gautam
le 24 Mai 2018
I have the same problem can you send me the ...correct version ...of PSO algorithm.thi is my e-mail: hkg51449@gmail.com
laxman bhukya
le 3 Juil 2018
I have the same problem can you send me the ...correct version ...of PSO algorithm.thi is my e-mail: laxman.03209@gmail.com
Shashwat Nayak
le 23 Déc 2018
I have the same problem can you send me the ...correct version ...of PSO algorithm.thi is my e-mail: shashwatnayak@outlook.com
119104005 EEE VII sem Haripriya.K
le 11 Fév 2019
I have the same problem can you send me the ...correct version ...of PSO algorithm.thi is my e-mail:aishu2997@gmail.com
Chabane Bouali
le 5 Avr 2019
I have the same problem can you send me the correct code of PSO algorithm .
thank you very much
halli aiissa
le 5 Mar 2020
can you send me the ...correct version ...of PSO algorithm.thi is my e-mail: haliaissa11@gmail.com
thank you very much
Réponses (3)
Immad Shams
le 15 Avr 2019
0 votes
can i have the correct code plz. Many Thanks
doaa nabil
le 7 Juin 2019
0 votes
can i have the correct code please
Nisar Ahmed
le 30 Avr 2020
0 votes
please send me these function codes
nisark37@gmail.com
Communautés
Plus de réponses dans Power Electronics Control
Catégories
En savoir plus sur Particle Swarm dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!