//------------------------------------求不平衡量------------------------------------------------
floatP[9],Q[9];
for(inti=0;i<9;i++)
{P[i]=bus[i].PG-bus[i].PL;
Q[i]=bus[i].QG-bus[i].QL;
}
floatdeltaP[9],deltaQ[9],deltaUU[9];
floataii[9]={0},bii[9]={0};
for(inti=0;i<9;i++)
{for(intj=0;j<9;j++)
{aii[i]+=YG[i][j]*Ue[j]-YB[i][j]*Uf[j];
bii[i]+=YG[i][j]*Uf[j]+YB[i][j]*Ue[j];}
deltaP[i]=P[i]-Ue[i]*aii[i]-Uf[i]*bii[i];
deltaQ[i]=Q[i]-Uf[i]*aii[i]+Ue[i]*bii[i];
deltaUU[i]=bus[i].U*bus[i].U-Ue[i]*Ue[i]-Uf[i]*Uf[i];
}
for(inti=0;i<9;i++)
ob3<<"deltaP["<
for(inti=0;i<9;i++)
ob3<<"deltaQ["<
for(inti=0;i<9;i++)
ob3<<"deltaUU["<
//-----------------------------------形成雅可比矩阵------------------------------------------------
floatH[9][9],N[9][9],J[9][9],L[9][9],R[9][9],S[9][9];
for(inti=0;i<9;i++)
{
for(intj=0;j<9;j++)
{
H[i][j]=0;
N[i][j]=0;
J[i][j]=0;
L[i][j]=0;
R[i][j]=0;
S[i][j]=0;
}
}
for(inti=0;i<9;i++)
{for(intj=0;j<9;j++)
{
if(i==j)
{
H[i][j]=YG[i][j]*Uf[i]-YB[i][j]*Ue[i]+bii[i];
N[i][j]=YG[i][j]*Ue[i]+YB[i][j]*Uf[i]+aii[i];
}
else
{
H[i][j]=YG[i][j]*Uf[i]-YB[i][j]*Ue[i];
N[i][j]=YG[i][j]*Ue[i]+YB[i][j]*Uf[i];
}
}
}
for(inti=3;i<9;i++)
{for(intj=0;j<9;j++)
{
if(i==j)
{
J[i][j]=-YG[i][j]*Ue[i]-YB[i][j]*Uf[i]+aii[i];
L[i][j]=YG[i][j]*Uf[i]-YB[i][j]*Ue[i]-bii[i];
}
else
{
J[i][j]=-YG[i][j]*Ue[i]-YB[i][j]*Uf[i];
L[i][j]=YG[i][j]*Uf[i]-YB[i][j]*Ue[i];
}
}
}
for(inti=0;i<3;i++)
for(intj=0;j<9;j++)
{
if(i==j)
{
R[i][i]=2*Uf[i];
S[i][i]=2*Ue[i];
}
else
{
R[i][j]=0;
S[i][j]=0;
}
}
floatJacobian[16][16];
for(inti=0;i<16;i++)
{for(intj=0;j<16;j++)
{
Jacobian[i][j]=0;
}
}
for(inti=0;i<2;i++)
for(intj=0;j<8;j++)
{Jacobian[2*i][2*j]=H[i+1][j+1];
Jacobian[2*i][2*j+1]=N[i+1][j+1];
Jacobian[2*i+1][2*j]=R[i+1][j+1];
Jacobian[2*i+1][2*j+1]=S[i+1][j+1];
}
for(inti=2;i<8;i++)
for(intj=0;j<8;j++)
{Jacobian[2*i][2*j]=H[i+1][j+1];
Jacobian[2*i][2*j+1]=N[i+1][j+1];
Jacobian[2*i+1][2*j]=J[i+1][j+1];
Jacobian[2*i+1][2*j+1]=L[i+1][j+1];
}
for(inti=0;i<16;i++)
{
for(intj=0;j<16;j++)
{
ob4<}ob4<}
//-----------------------------------解修正方程------------------------------------------------
NEquationob5;
ob5.SetSize(16);
for(inti=0;i<=15;i++)
{for(intj=0;j<=15;j++)
{ob5.Data(i,j)=Jacobian[i][j];}
}
for(inti=2;i<8;i++)
{
ob5.Value(2*i)=deltaP[i+1];
ob5.Value(2*i+1)=deltaQ[i+1];
}
for(inti=0;i<2;i++)
{ob5.Value(2*i)=deltaP[i+1];
ob5.Value(2*i+1)=deltaUU[i+1];
}
ob5.Run();
floatdeltaF[9],deltaE[9];
for(inti=0;i<8;i++)
{deltaF[i+1]=ob5.Value(2*i);
deltaE[i+1]=ob5.Value(2*i+1);
deltaF[0]=deltaE[0]=0;
}
for(inti=1;i<9;i++)
{ob6<<"deltaF["<
ob6<<"deltaE["<
}
//------------------------------------电压新值------------------------------------------------
for(inti=0;i<9;i++)
{
Ue[i]+=deltaE[i];
Uf[i]+=deltaF[i];
}
for(inti=1;i<9;i++)
{ob7<<"Uf["<
ob7<<"Ue["<
}
}
//---------------------------------------------循环结束----------------------------------------
ob3.close();
ob4.close();
ob6.close();
ob7.close();
//----------------------------------------------输出1.2.3节点功率-----------------------------------------
floatPin[9]={0},Qin[9]={0};
floataii[9]={0},bii[9]={0};
ofstreamob9("f:
\\yangyuanyuan\\end.txt");
for(inti=0;i<9;i++)
{
for(intj=0;j<9;j++)
{aii[i]+=YG[i][j]*Ue[j]-YB[i][j]*Uf[j];
bii[i]+=YG[i][j]*Uf[j]+YB[i][j]*Ue[j];
Pin[i]=Ue[i]*aii[i]+Uf[i]*bii[i];
Qin[i]=Uf[i]*aii[i]-Ue[i]*bii[i];}
}
for(inti=0;i<3;i++)
{
ob9<<"Pin["<
ob9<<"Qin["<
//----------------------------------------------网损-------------------------------------------------
floatPl[9][9]={0},Ql[9][9]={0},Pll[9][9]={0},Qll[9][9]={0};
ob9<for(inti=0;i<9;i++)
{floatyG=Branch[i].R/(Branch[i].R*Branch[i].R+Branch[i].X*Branch[i].X);
floatyB=-Branch[i].X/(Branch[i].R*Branch[i].R+Branch[i].X*Branch[i].X);
intii=Branch[i].FisrtBus-1;
intjj=Branch[i].EndBus-1;
floata=Ue[ii]*Ue[ii]+Uf[ii]*Uf[ii]-Ue[ii]*Ue[jj]-Uf[ii]*Uf[jj];
floatb=Ue[ii]*Uf[jj]-Ue[jj]*Uf[ii];
Pl[ii][jj]=a*yG+b*yB;
Ql[ii][jj]=b*yG-a*yB-Branch[i].B*(Ue[ii]*Ue[ii]+Uf[ii]*Uf[ii]);
floatc=Ue[jj]*Ue[jj]+Uf[jj]*Uf[jj]-Ue[jj]*Ue[ii]-Uf[jj]*Uf[ii];
floatd=Ue[jj]*Uf[ii]-Ue[ii]*Uf[jj];
Pl[jj][ii]=c*yG+d*yB;
Ql[jj][ii]=d*yG-c*yB-Branch[i].B*(Ue[jj]*Ue[jj]+Uf[jj]*Uf[jj]);
Pll[ii][jj]=Pl[ii][jj]+Pl[jj][ii];
Qll[ii][jj]=Ql[ii][jj]+Ql[jj][ii];
ob9<<"Pll["<ob9<<"Qll["<floatPwhole=0,Qwhole=0;
for(inti=0;i<9;i++)
{
for(intj=0;j<9;j++)
{Pwhole+=Pll[i][j];
Qwhole+=Qll[i][j];}
}
if(Qwhole>=0)
ob9<<"Swhole="<else
ob9<<"Swhole="<ob9.close();
return0;
}