Unrecognized function or variable 'GEPP'.

3 visualizaciones (últimos 30 días)
Wael Atiyah
Wael Atiyah el 5 de Ag. de 2021
Comentada: Walter Roberson el 6 de Ag. de 2021
clear
clc
%%Required input data
Busdata = xlsread('Gepdata.xlsx', 'Busdata');
Linedata = xlsread('Gepdata.xlsx', 'Linedata');
Candidatesdata = xlsread('Gepdata.xlsx', 'Candidatesdata');
%Maximum capacity that line i can be enhanced:
Biu = xlsread('Gepdata.xlsx', 'Biu');
%Investment cost for transmission lines enhancement(R/p.u.km)
Ga = xlsread('Gepdata.xlsx', 'Gama');
%% Data retrieval from input data
%Candidate buses for generation expansion:
Candidates = Candidatesdata(:,1);
%Beta(i):Investment factor cost of generation expansion
%in bus i
Beta = Candidatesdata(:,2);
%PGmax(i):Maximum generation expansion limit of bus i
PGmax = Candidatesdata(:,3);
%PGmin(i):Minimum generation expansion limit of bus i
PGmin = Busdata(:,3);
Nlin = Linedata(:,1); %Line number
Nl = Linedata(:,2); %Nl:From bus
Nr = Linedata(:,3); %Nr:To bus
R = Linedata(:,4); %R(i):Line resistance
X = Linedata(:,5); %X(i):Line reactance
%Smax(i):Maximum thermal rating of line i
Smax = Linedata(:,6);
%Length(i):Path length of line i
Length = Linedata(:,7);
Busn = Busdata(:,1); %Bus number
Btype = Busdata(:,2); %Type of bus 1-Slack, 2-PV, 3-PQ
Pg = Busdata(:,3); %Pg(i):Generation of bus i
Pl = Busdata(:,4); %Pl(i):Load of bus i
Nc = setxor(Busn,Candidates); %Nc:Non-candidate buses
[Ybus] = ybus(Busdata, Linedata); %Computing Ybus
%%
[Gi,Ol,To,Ef] = GEPP(Candidates,Nc,Beta,PGmax,PGmin,X,Btype,Nl,Nr,Smax,Length,Biu,Ga,Pg,Pl,Ybus);
%Gi:Generation of candidate buses after expansion
%Ol:Overloaded lines after expansion
%To:Total overload after expansion
%%
%Ef:Exit flag, integer identifying the reason the algorithm
%is terminated. Ef is 1, if there is a feasible solution
if Ef==1
Print_Gep
else
end
fprintf('There is no feasible solution.\n');
function [Ybus] = ybus (Busdata, Linedata)
nbus = size(Busdata,1);
nl = Linedata(:,2);
nr = Linedata(:,3);
Ld = Linedata;
%%
j = sqrt(-1);
X = Ld(:,5);
nbr = length(Ld(:,1));
%Z = R + j*X;
Z = (j*X);
y = ones(nbr,1)./Z; %Branch admittance
%for n = 1:nbr
Ybus = zeros(nbus,nbus);%Initialize Ybus to zero
%%
%Formation of the off diagonal elements
for k = 1:nbr
Ybus(nl(k),nr(k)) = Ybus(nl(k),nr(k))-y(k);
Ybus(nr(k),nl(k)) = Ybus(nl(k),nr(k));
end
%%
%Formation of the diagonal elements
for n = 1:nbus
for m = (n+1):nbus
Ybus(n,n) = Ybus(n,n)-Ybus(n,m);
end
for m = 1:n-1
Ybus(n,n) = Ybus(n,n)-Ybus(n,m);
end
end
function [Gi, Ol, To, Ef]= GEPP (Candidates, Nc, Beta ,PGmax ,PGmin, X, Btype, Nl, Nr, Smax, Length, Biu, Ga , Pg, Pl, Ybus);
if isempty(Ybus)
error('Input argument "Ybus" is undefined.');
end
if isempty(Pg)
fprintf('Input argument "Pl" determining');
fprintf(' load demand of buses.\n');
error('"Pl" is undefined and must be determined.');
end
if isempty(Pg)
fprintf('Input argument "Pg" determining');
fprintf(' generation of buses.\n');
error('"Pg" is undefined and must be determined.');
end
if isempty(Ga)
fprintf('Input argument "Ga" determining Investment ');
fprintf('cost of transmission lines enhancement.\n');
warning('"Ga" is undefined and is set to a default value.');
Ga = 20;
end
if isempty(Biu)
fprintf('Input argument "Biu" determining ');
fprintf('maximum capacity of lines enhancement.\n');
warning('"Biu" is undefined & is set to a default value.');
Biu = 1.1;
end
if isempty(Length)
fprintf('Input argument "Length" determining');
fprintf(' path length of lines.\n');
error('"Length" is undefined and must be determined.');
end
if isempty(Smax)
fprintf('Input argument "Smax" defining');
fprintf(' lines thermal loading before expansion.\n');
error('"Smax" is undefined and must be determined.');
end
if isempty(Nr) || isempty(Nl)
fprintf('Input argument "NL" & "Nr" defining');
fprintf(' lines sending and ending buses.\n');
error('"NL" & "Nr" are undefined and must be determined.');
end
if isempty(Btype)
fprintf('Input argument "Btype" defining');
fprintf(' information of bus types.\n');
error('"Btype" is undefined and must be determined.');
end
if isempty(X)
fprintf('Input argument "X" containing');
fprintf(' data of lines reactance.\n');
error('"X" is undefined and must be determined.');
end
if isempty(PGmin)
fprintf('Input argument "PGmin" defining minimum ');
fprintf('generation expansion limit of candidate buses.\n');
error('"PGmin" is undefined and must be determined.');
end
if isempty(PGmax)
fprintf('Input argument "PGmax" defining maximum ');
fprintf('generation expansion limit of candidate buses.\n');
error('"PGmax" is undefined and must be determined.');
end
if isempty(Beta)
fprintf('Input argument "Beta" defining investment cost');
fprintf('of generation expansion in candidate buses.\n');
error('"Beta" is undefined and must be determined.');
end
if isempty(Candidates)
fprintf('Input argument "Candidates" defining');
fprintf('candidate buses.\n');
error('"Candidates" is undefined and must be determined.');
end
%% Problem outputs
%Gi:Generation of candidate buses after expansion
%Ol:Overloaded lines after expansion
%To:Total overload after expansion
%Ef:Exit flag, integer identifying the reason the algorithm
%is terminated. Ef is 1, if there is a feasible solution
%% Problem Inputs
%Candidates:Candidate buses for generation expansion
%Beta(i):investment cost of generation expansion in bus i
%PGmax(i):Maximum generation expansion limit of bus i
%PGmin(i):Minimum generation expansion limit of bus i
%Nlin:Line number
%Nl:Line from bus
%Nr:Line to bus
%R(i):Line resistance
%X(i):Line reactance
%Smax(i):Maximum thermal rating of line i
%Length(i):Path Length of Line i
%Busn:Bus number
%Btype:Type of bus 1-Slack, 2-PV, 3-PQ
%Pg(i):Generation of bus i
%Pl(i):load of bus i
%Nc:Non-candidate buses
%%Obtaining Ybus matrix
%%
Ps = (Pg-Pl);
Na = size (Pg, 1);
M = size (X, 1);
%%%%
[Nons] = find(Btype~=1);
Nx = length(Nons);
B = zeros (Nx,Nx);
for k = 1:Nx
for j = 1:Nx
Ymn = Ybus(Nons(k),Nons(j));
B(k,j) = -imag(Ymn);
end
end
E = inv (B);
Binv = zeros (Na,Na);
for k = 1:Nx
an = Nons(k);
for j = 1:Nx
am = Nons(j);
Binv(an,am) = E(k,j);
end
end
%% Computing branch admittance calculation (b)
%The admittance matrix in which bii is the admittance
% of line i and non-diagonal elements are zero
jay = sqrt(-1);
Z = (jay*X);
Y = ones(M,1)./Z;
b = zeros (M,M);
for i = 1:M
b(i,i) = -imag(Y(i));
end
%% Computing connection matrix (A)
% The connection matrix (M*N) in which aij is 1, if a
% line exists from bus i to bus j; otherwise zero.
A = zeros (M, Na);
for i = 1:M
nl = Nl(i);
nr = Nr(i);
A(i, nl) = 1;
A(i, nr) = -1;
end
%% Computing sensitivity matrix (a)
theta = Binv*Ps;
a = b*A*Binv;
%% The line flows are calculated as follows:
Pli = zeros (M,1);
for i = 1:M
for k = 1:Na
Pli(i,1) = Pli(i,1)+(a(i,k)*(Pg(k,1)-Pl(k,1)));
end
end
%% Generation expansion cost of each bus
Pmax = zeros (Na,1);
beta = zeros (Na,1);
for j = 1:length (Nc)
Inc = Nc(j);
beta(Inc) = 10^10;
Pmax(Inc) = 0.000001;
end
for j = 1:length (Candidates)
Ica = Candidates(j);
beta(Ica) = Beta(j);
Pmax(Ica) = PGmax(j);
end
Beta = beta;
PGmax = Pmax;
%% Investment cost for transmission lines enhancement (R/MW)
Gama = Ga*Length;
%% Maximum possible capacity expansion of each line
Biu = Biu.*ones(M,1);
%% Thermal rating of each line
Pcu = Smax; %Upper bound of thermal rating of each line
Pcl = -Pcu; %Lower bound of thermal rating of each line
%% Defining objective function
for k = 1:Na
OF(k) = Beta(k);
end
for i = 1:M
I = i+Na;
OF(I) = Gama (i);
end
%% First set of inequality constraints: determining
%% minimum permissible thermal rating of each line
for i = 1:M
C(i) = (-a(i,:)*Pg)+Pli(i);
end
GH1 = zeros (M, M+Na);
bGH1 = zeros (M,1);
for i = 1:M
for k = 1:Na
GH1(i,k) = -a(i,k);
end
I = i+Na;
GH1(i,I) = Pcl(i);
bGH1(i,1) = C(i);
end
%% Second set of inequality constraints: determining
%% maximum permissible thermal rating of each line
GH2 = zeros (M, M+Na);
bGH2 = zeros (M,1);
for i = 1:M
for k = 1:Na
GH2(i,k) = a(i,k);
end
I = i+Na;
GH2(i,I) = -Pcu(i);
bGH2(i,1) = -C(i);
end
%% Integrating all inequality constraints
%% to one matrix, called An & bn here
for i = 1:M
An(i,:) = GH1(i,:);
bn(i) = bGH1(i);
I = i+M;
An(I,:) = GH2(i,:);
bn(I) = bGH2(i);
end
%% Determining upper and lower bounds of
%% decision variables, called lb & ub here
lb = zeros (M+Na,1);
ub = zeros (M+Na,1);
for k = 1:Na
lb(k,1) = PGmin(k);
ub(k,1) = PGmax(k);
end
for i = 1:M
I = i+Na;
lb(I,1) = 1;
ub(I,1) = Biu(i);
end
%% Defining equality constraint
%% (Total generation = Total demand)
Aeq = zeros (1, Na+M);
for k = 1:Na
Aeq(1,k) = 1;
end
beq = sum (Pl);
%% Solving the problem and finding the optimal point
[Dv, Fval, Ef] = linprog(OF,An,bn,Aeq,beq,lb,ub);
To = 0;
if Ef~=1
fprintf('\nWARNING: No feasible solution was found.')
Gi = zeros(size(Candidates,1),1);
Ol = zeros(M,1);
else
for k = 1:size(Candidates,1)
Gi (k,1) = Candidates(k,1);
Gi (k,2) = Dv(k);
end
for i = 1:M
I = i+Na;
Ol (i,1) = Nl(i);
Ol (i,2) = Nr(i);
Ol (i,3) = Dv(I,1)-1;
To = To+(Dv(I)-1);
end
end
Print_Gep
clc
fprintf('*************************************************');
fprintf('***************\n');
fprintf('Generation of each candidate bus after expansion');
fprintf(' is as follows: \n');
fprintf('*************************************************');
fprintf('***************\n');
fprintf(' |Bus number| |Gi (p.u.)|');
for i = 1:size(Gi,1)
fprintf('\n %18.0f % 22.2f', Gi(i,1), Gi(i,2));
end
fprintf('\n\n********************************************');
fprintf('********************\n');
fprintf(' Total overload value and enhanced lines ');
fprintf('are as follows\n');
fprintf('************************************************');
fprintf('****************\n');
fprintf(' |Total overload| \n');
fprintf('%31.2f \n', To);
if To>=0.0001
El = find (Ol(:,3)>=0.0001);
Sel = length(El);
fprintf('********************************************');
fprintf('********************\n');
fprintf(' |Enhanced lines| ');
fprintf(' \n');
fprintf(' |From bus| |To bus| ');
fprintf('|Enhancement(%%)|');
for i = 1:Sel
fprintf('\n %10i %18i % 19.2f \n',...
Ol(El(i),1), Ol(El(i),2), Ol(El(i),3)*100);
end
fprintf('\n********************************************');
fprintf('********************\n');
else
fprintf('\n No enhanced line ');
fprintf(' \n');
end
%% Printing the results in results.txt
fid = fopen('results.txt', 'wt');
fprintf(fid,'*********************************************');
fprintf(fid,'*******************\n');
fprintf(fid,...
'Generation of each candidate bus after expansion');
fprintf(fid,'is as follows: \n');
fprintf(fid,'**********************************************');
fprintf(fid,'******************\n');
fprintf(fid,' |Bus number| |Gi (p.u.)|');
for i = 1:size(Gi,1)
fprintf(fid,'\n %18.0f % 22.2f', Gi(i,1), Gi(i,2));
end
fprintf(fid,'\n\n*****************************************');
fprintf(fid,'***********************\n');
fprintf(fid,' Total overload value and enhanced lines');
fprintf(fid,' are as follows\n');
fprintf(fid,'*********************************************');
fprintf(fid,'*******************\n');
fprintf(fid,' |Total overload| \n');
fprintf(fid,'%31.2f \n', To);
if To>=0.0001
El = find (Ol(:,3)>=0.0001);
Sel = length(El);
fprintf(fid,'******************************************');
fprintf(fid,'**********************\n');
fprintf(fid,' |Enhanced lines| ');
fprintf(fid,' \n');
fprintf(fid,' |From bus| |To bus| ');
fprintf(fid,' |Enhancement(%%)|');
for i = 1:Sel
fprintf(fid,'\n %10i %18i % 19.2f \n',...
Ol(El(i),1), Ol(El(i),2), Ol(El(i),3)*100);
end
fprintf(fid,'\n***************************************');
fprintf(fid,'*************************\n');
else
fprintf(fid,'\n No enhanced line ');
fprintf(fid,' \n');
end
end
end
my problem Ihave the following error message
Unrecognized function or variable 'GEPP'.
anybody can help to solve this problem
  2 comentarios
Walter Roberson
Walter Roberson el 5 de Ag. de 2021
Is it possible you are using R2015a or earlier?
We do not have the data files so we cannot test your code.
Wael Atiyah
Wael Atiyah el 5 de Ag. de 2021
I using R2020b

Iniciar sesión para comentar.

Respuesta aceptada

Walter Roberson
Walter Roberson el 5 de Ag. de 2021
function [Gi, Ol, To, Ef]= GEPP (Candidates, Nc, Beta ,PGmax ,PGmin, X, Btype, Nl, Nr, Smax, Length, Biu, Ga , Pg, Pl, Ybus);
Insert a line containing
end
immediately before that function line.
Delete the final
end
right at the bottom of your code.
  3 comentarios
Walter Roberson
Walter Roberson el 5 de Ag. de 2021
I do not know. In the source you posted, the only call to ybus() is at line 35, not anywhere near line 289, so you must be looking at a different program.
Walter Roberson
Walter Roberson el 6 de Ag. de 2021
I have attached adjusted code. You did not put in the end in the place I told you to :(
I also fixed several other problems.
However, there a problem that I do not know the solution to. On the (new) line 247 there is
Gama = Ga*Length;
At that point, Ga and Length are both column vectors, but they are different sizes. Ga is 5 x 1, having to do with the 5 busses you defined. Length is 10 x 1, dealing with the 10 lines that you defined. You cannot use * between them because the inner dimensions must agree for the * operator. You cannot use .* because the non-scalar dimensions must agree to use .*
What size is expected for the result? The next section does
for i = 1:M
I = i+Na;
OF(I) = Gama (i);
end
and that tells us that a vector is expected. But when you combine busses with lines it would make more sense for the result to be either 2D or scalar.

Iniciar sesión para comentar.

Más respuestas (2)

Wael Atiyah
Wael Atiyah el 6 de Ag. de 2021
stay not clear for obtain any positive answer and acceptance result
  2 comentarios
Walter Roberson
Walter Roberson el 6 de Ag. de 2021
We do not have your current version of the code, and we do not have your data files to test with.
Wael Atiyah
Wael Atiyah el 6 de Ag. de 2021
attachment file with data ,possible to do and inform me

Iniciar sesión para comentar.


Wael Atiyah
Wael Atiyah el 6 de Ag. de 2021
attachment file with data

Categorías

Más información sobre Author Block Masks en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by