I can't do iterations with "while loop"....No puedo hacer iteraciones con WHILE

Hi good afternoon , sorry , but as I have the following code that I've been doing , but I can not do iterations . Everything is correct , the equations give me the results I want, but must meet as many iterations as possible until the result of " increq = 0.001" . In each iteration the values of v2 , s2 , s3 , q20 ; They should change as follows: v2 = v21 , s2 = s21 , s3 = s31 , q20 = q21 . if you can help me please . I'm desperate.
clc
disp ('===========================================')
disp ('Modelado de sistemas electricos de potencia')
disp ('Unidad 2: Flujo de potencias; 3 nodos')
disp ('===========================================')
z12=input('Coloque impedancia de linea 1-2 ====> ');
z13=input('Coloque impedancia de linea 1-3 ====> ');
z23=input('Coloque impedancia de linea 2-3 ====> ');
y12=-(z12)^-1;
y13=-(z13)^-1;
y23=-(z23)^-1;
disp ('===========================================')
B11=y12+y13;,B12=-y12;,B13=-y13;
B21=-y12;,B22=y12+y23;,B23=-y23;
B31=-y13;,B32=-y23;,B33=y13+y23;
matriz=[B11 B12 B13;B21 B22 B23;B31 B32 B33]
disp ('¿EN QUE BUS SE ENCUENTRA EL CONDENSADOR? 1, 2 o 3')
bus=input(' ')
if bus == 1
ybus=-[B22 B23;B32 B33]
elseif bus == 2
ybus=-[B11 B13;B31 B33]
else bus == 3
ybus=-[B11 B12;B21 B22]
end
ybusinversa=inv(ybus)
%ITERACIONES%
disp('===================================')
disp ('Iteraciones')
disp('===================================')
p20=input ('ingrese la potencia "P" de la carga (recuerde que las cargas se representan con signo negativo)===> ');
q20=input ('ingrese la potencia "Q" de la carga (recuerde que las cargas de representan con signo negativo)===> ');
p30=input ('ingrese la potencia "P" del generador====> ');
v1=1;, s1=0;
v2=1;, s2=0;
v3=1;, s3=0;
%CALCULANDO POTENCIA ACTIVA P%
p21=v2*((B21*v1*sin(s2-s1))+(B23*v3*sin(s2-s3)));
p31=v3*((B31*v1*sin(s3-s1))+(B32*v2*sin(s3-s2)));
%CALCULAR INCREMENTO DE P%
incp2v2=p20-p21;
incp3v3=p30-p31;
%CALCULAR INCREMENTO DE Q%
matrizincp=[incp2v2;incp3v3];
incdeq=(ybusinversa)*(matrizincp);
%s21 y s31%
des2=[incdeq];
s21=des2(1:2:end);
s31=des2(2:2:end);
%CALCULO DE Q%
singrad1=sin(acos(s21-s1));
singrad2=sin(acos(s21-s31));
q21=((-B22*(v2^2))-((v2*(B21*v1*(singrad1)))+(B23*v3*(((singrad2))))));
%INCREMENTO DE Q%
increq=(q20-q21)/v2;
%INCREMENTO DE V2%
increv2=-(1/B22)*(increq);
%CALCULO V2%
v21=v2+increv2;
%FIN%

 Accepted Answer

% initialise values here
while increq > 0.001
% calculations here
% update values here, including increq!
end

1 Comment

Ok, so...
p20=input ('ingrese la potencia "P" de la carga (recuerde que las cargas se representan con signo negativo)===> '); q20=input ('ingrese la potencia "Q" de la carga (recuerde que las cargas de representan con signo negativo)===> '); p30=input ('ingrese la potencia "P" del generador====> '); v1=1;, s1=0; v2=1;, s2=0; v3=1;, s3=0; While increq>0.001 %CALCULANDO POTENCIA ACTIVA P% p21=v2*((B21*v1*sin(s2-s1))+(B23*v3*sin(s2-s3))); p31=v3*((B31*v1*sin(s3-s1))+(B32*v2*sin(s3-s2))); %CALCULAR INCREMENTO DE P% incp2v2=p20-p21; incp3v3=p30-p31; %CALCULAR INCREMENTO DE Q% matrizincp=[incp2v2;incp3v3]; incdeq=(ybusinversa)*(matrizincp); %s21 y s31% des2=[incdeq]; s21=des2(1:2:end); s31=des2(2:2:end); %CALCULO DE Q% singrad1=sin(acos(s21-s1)); singrad2=sin(acos(s21-s31)); q21=((-B22*(v2^2))-((v2*(B21*v1*(singrad1)))+(B23*v3*(((singrad2)))))); %INCREMENTO DE Q% increq=(q20-q21)/v2; %INCREMENTO DE V2% increv2=-(1/B22)*(increq); %CALCULO V2% v2=v2+increv2; %more values% %FIN% End
I try

Sign in to comment.

Categories

Find more on Software Development 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!