problem with condictions in if-elseif

1 view (last 30 days)
adele
adele on 30 Jan 2015
Commented: Geoff Hayes on 1 Feb 2015
Hi my problem is when I run this code, there is no output(nothing displayed in output as I expected) while the code seems to be correct command run successfully
limits: " if ~(PL_i>Ptot_dg)
break
% ui=ui+1;
elseif (PL_i>Ptot_dg)"
%%continue
how to fix this problem? ........................................................................................
clc
clear all;
format shortG;
tic
m=load('loaddata14bus.m');
l=load('linedata14bus.m'); o=load('DGcapacity.m'); br=length(l); no=length(m);
MVAb=100;
KVb=20;
Zb=(KVb^2)/MVAb;
% Per unit Values for i=1:br R(i,1)=(l(i,4)); X(i,1)=(l(i,5)); Fmax(i,1)=l(i,6); end
ui=1;
c=0;
while ui<=size(o,2)
for i=1:no
P(i,1)=((m(i,2)-o(i,ui))/(1000*MVAb));
Pdg(i,1)=o(i,ui);
Q(i,1)=((m(i,3))/(1000*MVAb));
end
sum=0; z=find(o(:,ui)) zbig=max(z(:)) for i = zbig+1:no sum=sum+m(i,2);
end
PL_i=sum
Ptot_dg(1,1)=0;
for i=1:no
sum=sum+P(i,1);
Ptot_dg(1,1)=Ptot_dg(1,1)+Pdg(i,1);
end
Ptot=sum*100000 %sum(PL-PG)......KW
Ptot_dg
if ~(PL_i>Ptot_dg) %%%%%THIS LINE%%%%%%%%%%%%%
break
% ui=ui+1;
elseif (PL_i>Ptot_dg)
%
R; X; fprintf('\n P on case %d is :\n',ui); P %per unit.....injection power to each bus....PL-PG Fmax; ............................................................................................ sum=0; %SUM PG....KW fprintf('\n Q on case %d is :\n',ui); Q
...................................................................................... C=zeros(br,no); for i=1:br a=l(i,2); b=l(i,3); for j=1:no if a==j C(i,j)=-1; end if b==j C(i,j)=1; end end end C; e=1; for i=1:no d=0; for j=1:br if C(j,i)==-1 d=1; end end if d==0 endnode(e,1)=i; e=e+1; end end endnode h=length(endnode); for j=1:h e=2;
f=endnode(j,1);
% while (f~=1)
for s=1:no
if (f~=1)
k=1;
for i=1:br
if ((C(i,f)==1)&&(k==1))
f=i;
k=2;
end
end
k=1;
for i=1:no
if ((C(f,i)==-1)&&(k==1));
f=i;
g(j,e)=i;
e=e+1;
k=3;
end
end
end
end
end
for i=1:h
g(i,1)=endnode(i,1);
end
g;
w=length(g(1,:));
for i=1:h
j=1;
for k=1:no
for t=1:w
if g(i,t)==k
g(i,t)=g(i,j);
g(i,j)=k;
j=j+1;
end
end
end
end
g;
for k=1:br
e=1;
for i=1:h
for j=1:w-1
if (g(i,j)==k)
if g(i,j+1)~=0
adjb(k,e)=g(i,j+1);
e=e+1;
else
adjb(k,1)=0;
end
end
end
end
end
adjb;
for i=1:br-1
for j=h:-1:1
for k=j:-1:2
if adjb(i,j)==adjb(i,k-1)
adjb(i,j)=0;
end
end
end
end
adjb;
x=length(adjb(:,1));
ab=length(adjb(1,:));
for i=1:x
for j=1:ab
if adjb(i,j)==0 && j~=ab
if adjb(i,j+1)~=0
adjb(i,j)=adjb(i,j+1);
adjb(i,j+1)=0;
end
end
if adjb(i,j)~=0
adjb(i,j)=adjb(i,j)-1;
end
end
end
adjb;
for i=1:x-1
for j=1:ab
adjcb(i,j)=adjb(i+1,j);
end
end
b=length(adjcb);
% voltage current program
for i=1:no vb(i,1)=1; end for s=1:10 for i=1:no nlc(i,1)=conj(complex(P(i,1),Q(i,1)))/(vb(i,1)); end nlc; for i=1:br Ibr(i,1)=nlc(i+1,1); end Ibr; xy=length(adjcb(1,:)); for i=br-1:-1:1 for k=1:xy if adjcb(i,k)~=0 u=adjcb(i,k); %Ibr(i,1)=nlc(i+1,1)+Ibr(k,1); Ibr(i,1)=Ibr(i,1)+Ibr(u,1); end end end Ibr; for i=2:no g=0; for a=1:b if xy>1 if adjcb(a,2)==i-1 u=adjcb(a,1); vb(i,1)=((vb(u,1))-((Ibr(i-1,1))*(complex((R(i-1,1)),X(i-1,1))))); g=1; end if adjcb(a,3)==i-1 u=adjcb(a,1); vb(i,1)=((vb(u,1))-((Ibr(i-1,1))*(complex((R(i-1,1)),X(i-1,1))))); g=1; end end end if g==0 vb(i,1)=((vb(i-1,1))-((Ibr(i-1,1))*(complex((R(i-1,1)),X(i-1,1))))); end end s=s+1; end nlc; Ibr; fprintf('\n vb on case %d is :\n',ui); vb vb_phasor=[abs(vb) angle(vb)*180/pi]
toc; for i=1:no va(i,2:3)=vb_phasor(i,1:2); end for i=1:no va(i,1)=i; end va;
Ibr_phase=[abs(Ibr) angle(Ibr)*180/pi]; PLoss_tot(1,1)=0; QLoss_tot(1,1)=0; n=[1:5]; re=.2; % losses for f=1:br F(f,1)=(vb_phasor(f,1)*real(conj(Ibr_phase(f,1)))); Pl(f,1)=(Ibr_phase(f,1)^2)*R(f,1); Ql(f,1)=X(f,1)*(Ibr_phase(f,1)^2); PLoss_tot(1,1)=PLoss_tot(1,1)+Pl(f,1); QLoss_tot(1,1)=QLoss_tot(1,1)+Ql(f,1); end FlowKw=F*100 %MW fprintf('\n Ploss on case %d is :\n',ui); PLoss_to=zeros(5,1); Plosskw=(Pl)*100000 fprintf('\n Qloss on case %d is :\n',ui); Qlosskw=(Ql)*100000 PLoss_to(n)=(PLoss_tot)*100000*((1+re).^n) QLoss_tot=(QLoss_tot)*100000
fprintf('\n voltage on case %d is :\n',ui); voltage = vb_phasor(:,1) fprintf('\n vangle on case %d is :\n',ui); vangle = vb_phasor(:,2)*(pi/180)
%title('COSTS WITH DG') ......................................LIMITS............................... for i=1:br if ~( FlowKw(i)<Fmax(i)) % savedata( c,ui,0,0,0,0,0,0 );
% c=c+13;
ui=ui+1;
%break
elseif ( FlowKw(i)<Fmax(i))
%=========================================================================
%%Fdg_purching%%
%=========================================================================
n=[1:5];
Ccp=570;
Ccb=570;
t=8760;
hp=1460;
hb=2920;
Kdg=0.9;
Edg=zeros(5,1); %energy of DG
Fdg=zeros(5,1);
Ep_dg(n)=Ptot_dg*Kdg*hp
Eb_dg(n)=Ptot_dg*Kdg*hb
Fdg(n)=Ccp*Ep_dg(n)+Ccb*Eb_dg(n)
%========================================================================= %Fnet_purching% %========================================================================= C_Np=900; %Worth C_Nb=450; lsf_p=1; lsf_b=.5258; hp=1460; hb=2920; t=8760; I=0.12; %Interest sum=0; re=0.2; %Rate of growth n=[1:5]; %period COST=zeros(5,1); EL=zeros(5,1); Fnet=zeros(5,1); PL_tot=3.555*1000; %KW
EL_p(n)=PL_tot*((1+re).^n)*hp*lsf_p; %ENERGY loading annual
EL_b(n)=PL_tot*((1+re).^n)*hb*lsf_b;
Fnet(n)=C_Np*(EL_p(n)-Ep_dg)+C_Nb*(EL_b(n)-Eb_dg(n)) %Future Worth
%=========================================================================
%Floss%
%=========================================================================
Floss=zeros(5,1);
Ep_loss(n)=hp*PLoss_to(n);
Eb_loss(n)=hb*PLoss_to(n);
Eloss(n)=Eb_loss(n)+Ep_loss(n)
Floss(n)=C_Np*Ep_loss(n)+C_Nb*Eb_loss(n)
%========================================================================= % COST AFTER DG %========================================================================= fprintf('\n COST on case %d is :\n',ui); COST(n)=Fnet(n)+Fdg(n)+Floss(n) for n=1:5 sum=COST(n)+sum; sum_COST=sum; end tot_cost=zeros(5,1); fprintf('\n tot_cost on case %d is :\n',ui); n=[1:5]; tot_cost(n)=sum_COST*(1+I).^(5-n) %Uniform Annual Cost(Income)
%bar (COST(n))
savedata( c,ui,P,Q,Plosskw,Qlosskw,voltage,vangle,Fdg,Fnet,PLoss_to,Floss,COST,tot_cost);
c=c+13; ui=ui+1; end
break
end
% ui=ui+1;
end
end
  1 Comment
Geoff Hayes
Geoff Hayes on 1 Feb 2015
Soosan - you may just want to attach your code rather than pasting it into the question body. That much code may discourage people from trying to answer.

Sign in to comment.

Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!