How can I write an optimization problem and PSO code separately?

1 view (last 30 days)
Hello
I am trying to write a code using the PSO algorithm to optimize the PV and battery system. So I was looking for an example code and there was one in Mathworks. But there is an optimization problem in it with PSO code. How can I write an optimization problem and PSO code separately? Please help me
Example code part of PSO:
for i=1:NPOP
cc=1;%a value for cost
ww=0.3;% a value for lose of load probability%
kkk=2;%renewable energy factor%
ff=0;
%C=0.9;%price of electricity
%W=0.2;%lose of load probability%
%K=0.99;%renewable energy factor%
while ww>=W | kkk>=K% LOLP/REfactor
particle(i).position(1,:)=unifrnd(0,45,1,nvars);%pv kW
particle(i).position(2,:)=unifrnd(0,8,1,nvars);%autonomy days
particle(i).position(3,:)=unifrnd(1,20,1,nvars);%number of houses
particle(i).position(4,:)=unifrnd(0,10,1,nvars);%number of wind turbine
for g=1:4
particle(i).velocity(g,:)=rand(1,nvars);
end
%----convert------------
p_npv=particle(i).position(1);
ad=particle(i).position(2);
houses=round(particle(i).position(3));
nwt=round(particle(i).position(4));
%-----------------------
[LPSP,price_electricity,renewable_factor,b,ali]=techno_economic_analysis_pso(houses,p_npv,ad,nwt);
ff=ff+1;
ww(i)=LPSP;
kkk(i)=renewable_factor;
end
Example code:
Techno-Economic Analysis of Hybrid Renewable Energy System with PSO

Answers (0)

Products


Release

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!