When I test this code which is shown below. I got an error of " not enough input arguements". How can i solve this error?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
htis code for minimize power loss in IEEE 33bus using ga with capacitor in bus18
i got this error
Not enough input arguments.
Error in power_flow_cap (line 19)
BD(capplc(tt),3)=BD(capplc(tt),3)-capsz(tt);
this is the main function
clear all
[ploss,v]=power_flow1()
figure(1);
bar(abs(v));
axis([1 33 0 1.1]);
ncap=1;
capplc=[18];
%capsz=[0 100; 0 100];
%lb=zeros(1,50);
%ub=0.5*ones(1,50);la puissance de la batterie en pu 0.5
options = gaoptimset;
options = gaoptimset('PopulationSize', 50,'Generations', 500,'StallGenLimit',100,'TimeLimit', 500,'StallTimeLimit', 50,'PlotFcn',@gaplotbestf);
[capsz_opt,fval]=ga(power_flow_cap,1,[],[],[],[],0,0.5,[],[],options);
capsz_opt*Sbase;
fval*Sbase;
[ Ploss,Busvoltage]=power_flow_cap(capsz_opt)
figure(2);
bar(abs(v));
axis([1 33 0 1.1]);
the function
% ecoulement de puissance aprés l'isertion de batterie (ligne 17)
function [ Ploss,Busvoltage]=power_flow_cap(capsz,ncap,capplc)
display('entrer la puissance de base du system en MVA');
Sbase=input('Sbas= ');
display('entrer la tension de base du system en KV');
Vbase=input('Vbas= ');
display('entrer la tolerance epsilon');
epsilon=input('epsilon= ')
display('entrer le nombre d"iteration T');
T=input('T= ');
Zbase=(Vbase^2)/Sbase;
BD=load('bdata33bus.m');
LD=load('ldata33busmod4.m');
BD(:,2:3)=BD(:,2:3)/(Sbase*10^3); %%per unit initialization
LD(:,3:4)=LD(:,3:4)/Zbase; %%per unit initialization
ncap=1;
capplc=[18];
for tt=1:ncap
BD(capplc(tt),3)=BD(capplc(tt),3)-capsz(tt);
end
dimBD=size(BD);
dimLD=size(LD);
Nbus=dimBD(1,1);%%%% nombre de jeux de barres
Nbr=dimLD(1,1); %%%% nombre de branche
impdance=zeros(Nbus); %%% matrice d'impedance
courant=zeros(Nbus); %%%% matrice courant
terminbus=zeros(Nbus,1); %%% noeuds fineaux
interbus=zeros(Nbus,1); %%%% bus intermedier
for i=1:Nbr
impdance(LD(i,1),LD(i,2))=complex(LD(i,3),LD(i,4)); %for intermediate
end
for k=1:Nbus
co=0;
l=0;
for n=1:Nbr
if LD(n,1)==k
co=co+1;
end
end
if co==0
terminbus(k,1)=k;
elseif co>= 1
for m=1:Nbr
l=l+1;
if LD(m,2)==k
interbus(k,1)=k;
break
elseif l==Nbr
refbus=k;
end
end
end
end
Busvoltage=ones(Nbus,1);
iteration=0;
for s=1:T %iteration
%%%%%%%%%%%%%%%%%%%
%%%backward sweep%%
%%%%%%%%%%%%%%%%%%%
for i=1:Nbus
if terminbus(i,1)~=0
nodenumber=terminbus(i,1);
for j=1:Nbus
if impdance(j,nodenumber)~=0
connectedfrom=j;
end
end
courant(connectedfrom,nodenumber)=conj(complex(BD(nodenumber,2),BD(nodenumber,3))/Busvoltage(nodenumber,1));
end
end
for i=Nbus:-1:1%for intermediate nodes
if interbus(i,1)~=0
for k=1:Nbus %find which upper node is connected to current intermediate node
if impdance(k,interbus(i,1))~=0 %&& k~=IntermediateNodes(i,1)
upperNode=k;
break;
end
end
courant(upperNode,interbus(i,1))=(conj(complex(BD(interbus(i,1),2),BD(interbus(i,1),3))/Busvoltage(interbus(i,1),1)));%current equal to load or generation connected to intermediate node
for i1=1:Nbus%current to intermediate node is equal to currents going from inter node to all connected downstream nodes + current of node itself if it exists
if impdance(interbus(i,1),i1)~=0 && i1~=interbus(i,1)
courant(upperNode,interbus(i,1))=courant(upperNode,interbus(i,1))+courant(interbus(i,1),i1);
end
end
if upperNode==refbus
end
end
end
%%%%%%%%%%%%%%%%%
%%forward sweep%%
%%%%%%%%%%%%%%%%%
voltage(:,1)=Busvoltage(:,1);
for i=1:Nbus
for j=1:Nbus
if impdance(i,j)~=0
Busvoltage(j,1)=Busvoltage(i,1)-courant(i,j)*impdance(i,j);
end
end
end
count=0;
p=0;
for p=2:1:Nbus
if abs(voltage(p)-Busvoltage(p))<=epsilon
count=count+1;
end
end
if count==(Nbus-1)
break
end
iteration=iteration+1;
end
%%%%%% l'écoulement de puissance%%%%
bilan=zeros(Nbr,3);
c=0;
for i=1:Nbus
for j=1:Nbus
if courant(i,j)~=0
c=c+1;
bilan(c,1)=i;%depart
bilan(c,2)=j;%arrive
bilan(c,3)=Busvoltage(i)*conj(courant(i,j))+Busvoltage(j)*conj(-1*courant(i,j)); %les perts par la methode Sloss=Sij+Sji
end
end
end
sLOSS=sum(bilan(:,3));
Qloss=imag(sLOSS);
Ploss=real(sLOSS);
end
1 Commento
Stephen23
il 29 Feb 2024
This code is very odd:
BD=load('bdata33bus.m');
LD=load('ldata33busmod4.m');
Why are you calling LOAD on Mfiles? Lets take a look at the files themselves:
type bdata33bus.m
type ldata33busmod4.m
Well, those are not executable Mfiles, so that .m file extension is inappropriate (and/or misleading). It would much better to simply use a .txt extension and call READMATRIX. That would be clearer and not misleading.
Risposta accettata
Torsten
il 28 Feb 2024
Modificato: Torsten
il 28 Feb 2024
ga will call your function "power_flow_cap" with one input argument. Your function has three inputs (capsz,ncap,capplc).
I don't know how many parameters you try to optimize: I guess 3 (capsz,ncap,capplc), but you only supply nvars = 1.
So many things are unclear in your settings.
9 Commenti
Torsten
il 1 Mar 2024
I doubt lb and ub can be used in your case because you want to set constraints on a derived quantity of your optimization, namely V = abs(Busvoltage), not capsz_opt.
Più risposte (0)
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!