What is the meaning of this code line? th1(2:NB)=inv(BM(2:NB,2:NB))*P1.';
1 view (last 30 days)
Show older comments
clear all
tic
% branch no.|from | to | reactance
linedata = [ 1 1 2 0.20 70 1;
2 1 4 0.20 100 1;
3 1 5 0.30 100 1;
4 2 3 0.25 30 1;
5 2 4 0.10 90 1;
6 2 5 0.30 40 1;
7 2 6 0.20 40 1;
8 3 5 0.26 45 1;
9 3 6 0.10 90 1;
10 4 5 0.40 15 1;
11 5 6 0.30 50 1];
P1=[0.5 0.6 -0.7 -0.7 -0.7];
SB=2; %Seller bus or source bus
BB=5; %Buyer bus or sink bus
P2=zeros(1,length(P1));
for i=1:length(P1)
if i==SB-1
P2(i)=P1(i)+0.1;
elseif i==BB-1
P2(i)=P1(i)-0.1;
else
P2(i)=P1(i);
end
end
X=linedata(:,4);
L=linedata(:,5);
ls=linedata(:,6); % line status
for k=1:size(linedata,1)
h(k)=linedata(k,2); % h is a column vecror of 'FROM BUS'
x(k)=linedata(k,3); % x is a column vecror of 'TO BUS'
LL(h(k),x(k))=L(k);
end
ss=[h x];
NB=max(unique(ss));
b=zeros(NB);
for k=1:size(linedata,1)
if (ls(k)==1)
b(h(k),x(k))=-inv(X(k));
b(x(k),h(k))=-inv(X(k));
else
continue;
end
end
for i=1:NB
for j=1:NB
if(i~=j)
B(i,j)=-b(i,j); % CALCULATION OF OFF-DIAGONAL ELEMENTS
end
end
end
BM=zeros(NB);
for i=1:NB
for j=1:NB
if i~=j
BM(i,i)=BM(i,i)+B(i,j); %CALCULATION OF DIAGONAL ELEMENTS
else
continue;
end
end
end
for i=1:NB
for j=1:NB
if(i~=j)
BM(i,j)=-B(i,j);
end
end
end
% calculation of the B-matrix completed
th1(2:NB)=inv(BM(2:NB,2:NB))*P1.';
th2(2:NB)=inv(BM(2:NB,2:NB))*P2.';
for k=1:size(linedata,1)
PF1(h(k),x(k))=(th1(h(k))-th1(x(k)))*B(h(k),x(k))*100;
PF2(h(k),x(k))=(th2(h(k))-th2(x(k)))*B(h(k),x(k))*100;
end
PTDF=(PF2-PF1)/10;
tt=zeros(1,size(linedata,1));
t1=zeros(1,size(linedata,1));
t2=zeros(1,size(linedata,1));
t3=zeros(1,size(linedata,1));
for k=1:size(linedata,1)
if (ls(k)==1)
LL(h(k),x(k))=L(k);
else
LL(h(k),x(k))=0;
end
end
for k=1:size(linedata,1)
t1(k)=PTDF(h(k),x(k));
t2(k)=PF1(h(k),x(k));
t3(k)=LL(h(k),x(k));
end
for k=1:size(linedata,1)
if t1(k)< 0
tt(k)=(-t3(k)-t2(k))./t1(k);
elseif t1(k)> 0
tt(k)=(t3(k)-t2(k))./t1(k);
end
end
%trial code to find overloaded line (not necessary for only ATC calculation)
TL=zeros(5,6);
for k=1:size(linedata,1)
if PTDF(h(k),x(k))<0
TL(h(k),x(k))=(-LL(h(k),x(k))-PF1(h(k),x(k)))./PTDF(h(k),x(k));
elseif PTDF(h(k),x(k))>0
TL(h(k),x(k))=(LL(h(k),x(k))-PF1(h(k),x(k)))./PTDF(h(k),x(k));
end
end
%trial code completed (not necessary for only ATC calculation)
ATC=min(nonzeros(tt));
fprintf('\nATC BETWEEN BUS %d(SELLER) AND BUS %d(BUYER) IS= %f MW (WITH PTDF-based method)\n',SB,BB,ATC);
[sb,bb]=find(TL==ATC);
fprintf('\nOVERLOADED LINE=%d-%d\n', sb,bb);
toc
0 Comments
Answers (1)
Sam Chak
on 21 Mar 2022
I think the code means
, which solves a system of linear equations,
.
For more info, please check mldivide:
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!