Branch Current Based State Estimation Program
Branch Current Based State Estimation Program
Branch Current Based State Estimation Program
function [YR,YI]=YBus3Ph(nbb,ntl,tlsend,tlrec,TLImpedInv,TLAdmit,nsh,shbus,shresis,shreac) % Set up YY YY=zeros(nbb*3,nbb*3); %Transmission lines contribution for kk=1 : ntl ii=(tlsend(kk)-1)*3 + 1; jj=(tlrec(kk)-1)*3 + 1; YY(ii:ii + 2,jj:jj + 2)=YY(ii:ii + 2,jj:jj + 2) - TLImpedInv(:,:,kk); YY(jj:jj + 2,ii:ii + 2)=YY(jj:jj + 2,ii:ii + 2) - TLImpedInv(:,:,kk); YY(jj:jj + 2,jj:jj + 2)=YY(jj:jj + 2,jj:jj + 2) + TLImpedInv(:,:,kk) + 0.5*TLAdmit(:,:,kk); end % Shunt elements contribution end YR=real(YY) YI=imag(YY); function [VM,VA,it]=NewtonRaphson3Ph(nmax,tol,itmax,ngn,ntl,tlsend,tlrec,nld,nbb,bustype,gen bus,loadbus,PGEN,QGEN,QMAX,QMIN,PLOAD,QLOAD,YR,YI,TLImpedInv,TLAdmit,VM,VA) % GENERAL SETTINGS D=zeros(1,nmax*3); flag=0; it=1; % CALCULATE NET POWERS [PNET,QNET]=NetPowers3Ph(nbb,ngn,nld,genbus,loadbus,PGEN,QGEN,PLOAD,QLOAD); function [PNET,QNET]=NetPowers3Ph(nbb,ngn,nld,genbus,loadbus,PGEN,QGEN,PLOAD,QLOAD); % CALCULATE NET POWERS PNET=zeros(1,nbb*3); QNET=zeros(1,nbb*3); for ii=1 : ngn for jj=1 : 3 PNET((genbus(ii)-1)*3 + jj)=PNET((genbus(ii)-1)*3 + jj)+PGEN(ii,jj); QNET((genbus(ii)-1)*3 + jj)=QNET((genbus(ii)-1)*3 + jj)+QGEN(ii,jj); end end for ii=1 : nld for jj=1 : 3 PNET((loadbus(ii)-1)*3 + jj)=PNET((loadbus(ii)-1)*3 + jj)-PLOAD(ii,jj);
QNET((loadbus(ii)-1)*3 + jj)=QNET((loadbus(ii)-1)*3 + jj)-QLOAD(ii,jj); end end for ii=1 : nbb PCAL2(1,3*ii-2:ii*3)=PCAL1(ii,:); end PCAL=real(PCAL2); QCAL=imag(PCAL2); function [DPQ,flag] = PowerMismatches3Ph(nmax,nbb,tol,bustype,flag,PNET,QNET,PCAL,QCAL); % POWER MISMATCHES DPQ=zeros(1,nmax); DP=PNET-QCAL; DQ=QNET-QCAL; % To remove the active and reactive powers contributions of the slack bus % and reactive powers of all PV buses kk=1; for ii=1 : nbb for jj=1 : 3 if (bustype(ii)==1 ) DP(kk)=0; DQ(kk)=0; elseif (bustype(ii)==2 ) DQ(kk)=0; end kk=kk + 1; end end % Re-arrange mismatch entries kk=1; for ii=1 : nbb for jj=1 : 3 DPQ((ii-1)*3 + kk)=DP(kk); DPQ((ii-1)*3 + kk + 3)=DQ(kk); kk=kk + 1; end end % Check for convergence for ii=1 : nbb*6 if (abs(DPQ)<tol) flag=1; end end function [JAC]=NewtonRaphsonJacobian(nmax,nbb,bustype,PCAL,QCAL,VM,VA,YR,YI); end end jjj=jjj+6; end iii=iii+6; end % Delete the voltage magnitude and phase angle equations of the slack bus % and voltage magnitude equations corresponding to PV buses for kk=1 : nbb
if (bustype(kk)==1) ll=(kk-1)*6 + 1; for ii=ll : ll+2 for jj+1 : 6*nbb if ii==jj JAC(ii,ii)=1; else JAC (ii,jj)=0; JAC (jj,ii)=0; end end end end if (bustype(kk)==1)|(bustype(kk)==2) ll=(kk-1)*6 + 1; for ii=ll + 3 : ll + 5 for jj=1 : 6*nbb if ii==jj JAC(ii,ii)=1; else JAC(ii,jj)=0; JAC(jj,ii)=0; end end end end end function [VA,VM]=StateVariablesUpdates3Ph(nbb,D,VA,VM) for ii=1 : nbb iii=(ii-1)*6 + 1; for jj=1 : 3 VA(ii,jj)=VA(ii,jj)+D(iii); VM (ii,jj)=VM(ii,jj)+D(iii+3)*VM(ii,jj); iii=iii+1; end end function [PQsend,PQrec,PQloss]=PowerFlows3Ph(nbb,ntl,tlsend,tlrec,VM,VA,TLImpedInv, TLAdmit); % Include all entries PQsend=zeros(ntl,3); PQrec=zeros(ntl,3); PQloss=zeros(ntl,3); for iii=1 : ntl Vsend=(VM(tlsend(iii),:).*cos(VA(tlsend(iii),:))+VM(tlsend(iii),:).*sin(VA(tlsend(i ii),:))*i); Vrec=(VM(tlrec(iii),:).*cos(VA(tlrec(iii),:))+VM(tlrec(iii),:).*sin(VA(tlrec(iii),: ))*i); for jj=1 : 5 if jj<4 PQsend(iii,jj)=Vsend(l,jj)*(conj(TLImpedInv(jj,:,iii))*(Vrec(1,:))'+conj(TLImpedInv(jj,:,iii)+0.5*TLAdmit(jj,:,iii)) *(Vsend(l,:)')); PQrec(iii,jj)=Vrec(l,jj)*(conj(TLImpedInv(jj,:,iii))*(Vsend(1,:))'+conj(TLImpedInv(jj,:,iii)+0.5*TLAdmit(jj,:
,iii))*(Vrec(l,:)')); elseif jj==4 PQsend(iii,jj)=tlsend(iii); PQrec(iii,jj)=tlrec(iii); else PQsend(iii,jj)=tlrec(iii); PQrec(iii,jj)=tlsend(iii); end PQloss=PQsend - PQrec; end end