When I test this code which is shown below. I got an error of " not enough input arguements". How can i solve this error?

4 views (last 30 days)
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 Comment
Stephen23
Stephen23 on 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
1.0000 0 0 2.0000 0.0100 0.0060 3.0000 0.0090 0.0040 4.0000 0.0120 0.0080 5.0000 0.0060 0.0030 6.0000 0.0060 0.0020 7.0000 0.0200 0.0100 8.0000 0.0200 0.0100 9.0000 0.0060 0.0020 10.0000 0.0060 0.0020 11.0000 0.0045 0.0030 12.0000 0.0060 0.0035 13.0000 0.0060 0.0035 14.0000 0.0120 0.0080 15.0000 0.0060 0.0010 16.0000 0.0060 0.0020 17.0000 0.0060 0.0020 18.0000 0.0090 0.0040 19.0000 0.0090 0.0040 20.0000 0.0090 0.0040 21.0000 0.0090 0.0040 22.0000 0.0090 0.0040 23.0000 0.0090 0.0050 24.0000 0.0420 0.0200 25.0000 0.0420 0.0200 26.0000 0.0060 0.0025 27.0000 0.0060 0.0025 28.0000 0.0060 0.0020 29.0000 0.0120 0.0070 30.0000 0.0200 0.0600 31.0000 0.0150 0.0070 32.0000 0.0210 0.0100 33.0000 0.0060 0.0040
type ldata33busmod4.m
1.0000 2.0000 0.0058 0.0029 2.0000 3.0000 0.0308 0.0157 3.0000 4.0000 0.0228 0.0116 4.0000 5.0000 0.0238 0.0121 5.0000 6.0000 0.0511 0.0441 6.0000 7.0000 0.0117 0.0386 7.0000 8.0000 0.0444 0.0147 8.0000 9.0000 0.0643 0.0462 9.0000 10.0000 0.0651 0.0462 10.0000 11.0000 0.0123 0.0041 11.0000 12.0000 0.0234 0.0081 12.0000 13.0000 0.0916 0.0721 13.0000 14.0000 0.0338 0.0445 14.0000 15.0000 0.0369 0.0328 15.0000 16.0000 0.0466 0.0340 16.0000 17.0000 0.0804 0.1074 17.0000 18.0000 0.0457 0.0358 2.0000 19.0000 0.0102 0.0098 19.0000 20.0000 0.0939 0.0846 20.0000 21.0000 0.0255 0.0298 21.0000 22.0000 0.0442 0.0585 3.0000 23.0000 0.0282 0.0192 23.0000 24.0000 0.0560 0.0442 24.0000 25.0000 0.0559 0.0441 6.0000 26.0000 0.0127 0.0065 26.0000 27.0000 0.0177 0.0090 27.0000 28.0000 0.0661 0.0583 28.0000 29.0000 0.0502 0.0437 29.0000 30.0000 0.0317 0.0161 30.0000 31.0000 0.0608 0.0601 31.0000 32.0000 0.0194 0.0226 32.0000 33.0000 0.0213 0.0331
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.

Sign in to comment.

Accepted Answer

Torsten
Torsten on 28 Feb 2024
Edited: Torsten on 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 Comments
Khlifi Wahid
Khlifi Wahid on 1 Mar 2024
Moved: Torsten on 1 Mar 2024
Actually, there is no error, but the values are not within the range of Vmax and Vmin. I think I have chosen lb and ub correctly.
Torsten
Torsten on 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.

Sign in to comment.

More Answers (0)

Categories

Find more on Linear Programming and Mixed-Integer Linear Programming in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!