Script Returning NaN when it is inside a WHILE loop
Show older comments
So I have this MATLAB code for Newton Raphson Power flow and I need to find the answer within a tolerance limit of 1e-6. But the problem is that once I input my script inside the while loop, the output is returning NaN values. When I remove the while loop, it works...Any help will be appreciated.
% The Ybus matrix is
[yb,~]=ybusnr;
g=real(yb);b=imag(yb);
% The given parameters and initial conditions are
p=[0 0.5 -0.275 0 -0.15 -0.25];
q=[0 0 -0.11 0 -0.09 -0.15];
mv=[1.05; 1.05; 1; 1; 1; 1;];
th=[0;0;0;0;0;0];
del=1;indx=0;
% The Newton-Raphson iterations starts here
while del>1e-6
for i=1:6
temp=0;
for k=1:6
temp=temp+mv(i)*mv(k)*(g(i,k)-j*b(i,k))*exp(j*(th(i)-th(k)));
end
pcal(i)=real(temp);qcal(i)=imag(temp);
end
% The mismatches
delp=p-pcal';
delq=q-qcal';
% The Jacobian matrix
for i=1:5
ii=i+1;
for k=1:5
kk=k+1;
j11(i,k)=mv(ii)*mv(kk)*(g(ii,kk)*sin(th(ii)-th(kk))-b(ii,kk)*cos(th(ii)-th(kk)));
end
j11(i,i)=-qcal(ii)-b(ii,ii)*mv(ii)^2;
end
for i=1:5
ii=i+1;
for k=1:5
kk=k+1;
j211(i,k)=-mv(ii)*mv(kk)*(g(ii,kk)*cos(th(ii)-th(kk))-b(ii,kk)*sin(th(ii)-th(kk)));
end
j211(i,i)=pcal(ii)-g(ii,ii)*mv(ii)^2;
end
j21=j211(1:4,1:5);
j12=-j211(1:5,1:4);
for i=1:4
j12(i,i)=pcal(i+1)+g(i+1,i+1)*mv(i+1)^2;
end
j22=j11(1:4,1:4);
for i=1:4
j22(i,i)=qcal(i+1)-b(i+1,i+1)*mv(i+1)^2;
end
jacob=[j11 j12;j21 j22];
delpq= transpose([delp(2:6) delq(3:6)]);
corr=solveLS(jacob,delpq);
th=th+[0;corr(1:5)];
mv=mv+[0; 0; mv(3:6).*corr(6:9)];
del=max(abs(delpq));
index+1;
end
Answers (0)
Categories
Find more on Loops and Conditional Statements 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!