i dunno why it run until 4th iteration then stopped...can anybody help me? it did not give any error...
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
clc
fprintf('\n\n')
Vb=230e3;
Sb=100e6;
Zb=Vb^2/Sb;
% From To R X
ldata=[1 2 12.333/Zb 0.0933*2*pi*60/Zb
1 4 8.256/Zb 0.1056*2*pi*60/Zb
2 3 6.328/Zb 0.0833*2*pi*60/Zb
2 6 15.696/Zb 0.1696*2*pi*60/Zb
3 5 5.839/Zb 0.0771*2*pi*60/Zb
4 5 10.581/Zb 0.1129*2*pi*60/Zb
4 7 5.993/Zb 0.0537*2*pi*60/Zb
4 8 9.673/Zb 0.1055*2*pi*60/Zb
5 8 7.996/Zb 0.1299*2*pi*60/Zb
6 7 16.395/Zb 0.1753*2*pi*60/Zb
6 8 5.839/Zb 0.0771*2*pi*60/Zb
7 8 6.566/Zb 0.0818*2*pi*60/Zb]
fb=ldata(:,1);
tb=ldata(:,2);
R=ldata(:,3);
X=ldata(:,4);
nbranch=length(ldata(:,1));
nbus=max(max(fb),max(tb));
Z=R+i*X;
y=ones(nbranch,1)./Z;
Y=zeros(nbus,nbus);
ydata=[ldata(:,1),ldata(:,2),y];
for k=1:nbranch;
if fb(k) > 0 && tb(k) > 0
Y(fb(k),tb(k))=Y(fb(k),tb(k))-y(k);
Y(tb(k),fb(k))=Y(fb(k),tb(k));
end
end
for n=1:nbus;
for k=1:nbranch;
if fb(k)==n||tb(k)==n
Y(n,n)=Y(n,n)+y(k);
else end
end
end
y12=ydata(1,3);
y14=ydata(2,3);
y23=ydata(3,3);
y26=ydata(4,3);
y35=ydata(5,3);
y45=ydata(6,3);
y47=ydata(7,3);
y48=ydata(8,3);
y58=ydata(9,3);
y67=ydata(10,3);
y68=ydata(11,3);
y78=ydata(12,3);
s1pu=-(125+i*100)/100;
p3pu=200/100;
s5pu=-(100+i*85)/100;
s6pu=-(150+i*100)/100;
s7pu=-(80+i*75)/100;
s8pu=-(130+i*115)/100;
v1=1.00;
v2=1.03;
v3=1.02;
v4=1.04;
v5=1.00;
v6=1.00;
v7=1.00;
v8=1.00;
dv1=10;
dv3=10;
dv5=10;
dv6=10;
dv7=10;
dv8=10;
iter=0;
disp('iter v1 v3 v5 v6 v7 v8 abs(dv1) abs(dv3) abs(dv5) abs(dv6) abs(dv7) abs(dv8)')
while abs(dv1)>=0.00001 && abs(dv3)>=0.00001 && abs(dv5)>=0.00001 && abs(dv6)>=0.00001 && abs(dv7)>=0.00001 && abs(dv8)>=0.00001 && iter<100
iter=iter+1;
v11=(conj(s1pu)/conj(v1)+y12*v2+y14*v4)/(y12+y14);
dv1=v11-v1;
v1=v11;
Q3=-imag(conj(v3)*(v3*(y23+y35)-y23*v2-y35*v5));
v31=(((p3pu-i*Q3)/conj(v3))+y23*v2+y35*v5)/(y23+y35);
vr3=sqrt(abs(v3)^2-(imag(v31)^2));
VR3=vr3+i*imag(v31);
dv3=VR3-v3;
v3=VR3;
v51=(conj(s5pu)/conj(v5)+y35*v3+y45*v4+y58*v8)/(y35+y45+y58);
dv5=v51-v5;
v5=v51;
v61=(conj(s6pu)/conj(v6)+y26*v2+y67*v7+y68*v8)/(y26+y67+y68);
dv6=v61-v6;
v6=v61;
v71=(conj(s7pu)/conj(v7)+y47*v4+y67*v6+y78*v8)/(y47+y67+y78);
dv7=v71-v7;
v7=v71;
v81=(conj(s8pu)/conj(v8)+y48*v4+y58*v5+y68*v6+y78*v7)/(y48+y58+y68+y78);
dv8=v81-v8;
v8=v81;
fprintf('%g',iter),disp([v1,v3,v5,v7,v8,abs(dv1),abs(dv3),abs(dv5),abs(dv6),abs(dv7),abs(dv8)]);
end
v=[v1,v2,v3,v4,v5,v6,v7,v8];
for i=1:8;
if imag(v(i))>=0
fprintf('v%g=%2.4f+%2.4f*i pu \n',i,real(v(i)),imag(v(i)));
else
fprintf('v%g=%2.4f%2.4f*i pu \n',i,real(v(i)),imag(v(i)));
end
end
1 commentaire
Geoff
le 23 Avr 2012
Please at least edit this question, highlight all the code and hit the 'code' button in the toolbar. Also, define 'stopped'. Did it give an error message, or did the loop complete cleanly (despite unexpectedly)?
Réponse acceptée
Richard Brown
le 23 Avr 2012
OK, with the disclaimer that what you have there isn't a particularly optimal way to write this code, you can fix your problem by replacing all of the && in the while line with || - your code is exiting when one component of the solution has converged, you should be watching for the worst component to have converged. (Oh, but don't modify the && for the iter expression). i.e.:
while iter < 100 && (abs(dv1)>=0.00001 || abs(dv3)>=0.00001 || abs(dv5)>=0.00001 || abs(dv6)>=0.00001 || abs(dv7)>=0.00001 || abs(dv8)>=0.00001)
Plus de réponses (2)
Richard Brown
le 23 Avr 2012
You're going to struggle to get someone to answer (let alone read) this question.
I would suggest using the debugger to step through your code one line at a time (to do this, click on a line of code and hit F12, next time you run it will stop here and you can advance it a line at a time using F10) and see if the values at each line are what you expect.
0 commentaires
Richard Brown
le 23 Avr 2012
It stops because dv1 drops below its threshhold, causing the loop to quit.
3 commentaires
Walter Roberson
le 23 Avr 2012
Why do you need to modify it? What do you want to have happen if one of the values drops below the threshold?
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!