#include\"Complex.h\" #include\"wanjing.h\" #include\"gauss.h\" using namespace std;
int _tmain(int argc, _TCHAR* argv[]) { int i; //i作为整个程序的循环变量 int N=Bus::ScanfBusNo(); //输入节点个数
int L=Line::ScanflineNo(); //输入支路个数
if((L&&N)==0){return 0;} //如果找不到两个文件中的任意一个,退出 Line *line=new Line[L]; //动态分配支路结构体 Line::ScanfLineData(line); //输入支路参数 Line::PrintfLineData(line,L); //输出支路参数 Bus *bus=new Bus[N]; for(int i=0;i //输入节点参数 bus[i].Sdelta.real=0; bus[i].Sdelta.image=0; //动态分配结点结构体 Bus::PrintfBusData(bus,N); //输出结点参数 Complex **X; X=new Complex *[N]; for(i=0;i int NN=(N-1)*2; double **JacAug; JacAug=new double *[NN]; for(i=0;i LOOP: Bus::JisuanNodeI(X,bus,N); //计算节点注入电流 Bus::JisuanNodeScal(X,bus,N); //计算节点功率 Bus::JisuanNodeScal(X,bus,N);//计算节点功率 Bus::JisuanNodeSdelta(bus,N); //计算节点功率差值 Bus::PrintfNodeScal(X,bus,N);//输出节点功率差值 int icon=wehcon1(bus,N);//whether converbence看迭代是否结束 if(icon==1) { // // } else { for(i=0;i int statemp,endtemp; Complex aa,bb,cc,dd,B; B.real=0; B.image=-line[i].B; statemp=line[i].start; endtemp=line[i].end; cout<<\"icon=\"< aa=Complex::productComplex (Complex::getconj(bus[statemp-1].V), B); (Complex::getconj(bus[statemp-1].V), bb=Complex::subComplex Complex::getconj(bus[endtemp-1].V)); Complex::getconj(line[i].Y)); dd=Complex::CaddC(aa,cc); cc=Complex::productComplex (bb , line[i].stoe=Complex::productComplex(bus[statemp-1].V,dd); aa=Complex::productComplex (Complex::getconj(bus[endtemp-1].V), B); bb=Complex::subComplex (Complex::getconj(bus[endtemp-1].V), Complex::getconj(bus[statemp-1].V)); cc=Complex::productComplex (bb , Complex::getconj(line[i].Y)); dd=Complex::CaddC(aa,cc); line[i].etos=Complex::productComplex(bus[endtemp-1].V,dd); } for(i=0;i cout<<\"icon=\"< cout<<\"====节点电压===============发电机发出功率======\"< cout<<\"======线路传输功率==========\"< cout< } #include \"stdafx.h\" #include #include\"Complex.h\" #include\"wanjing.h\" #include\"gauss.h\" using namespace std; int _tmain(int argc, _TCHAR* argv[]) { int i; //i作为整个程序的循环变量 int N=Bus::ScanfBusNo(); //输入节点个数 int L=Line::ScanflineNo(); //输入支路个数 for(int i=0;i if((L&&N)==0){return 0;} //如果找不到两个文件中的任意一个,退出 Line *line=new Line[L]; //动态分配支路结构体 Line::ScanfLineData(line); //输入支路参数 Line::PrintfLineData(line,L); //输出支路参数 Bus *bus=new Bus[N]; //动态分配结点结构体 Bus::ScanfBusData(bus); //输入节点参数 Bus::PrintfBusData(bus,N); //输出结点参数 Complex **X; X=new Complex *[N]; for(i=0;i Bus::PrintfNodeDnz(X,N); //输出节点导纳矩阵 int NN=(N-1)*2; double **JacAug; JacAug=new double *[NN]; for(i=0;i x=new double[NN]; int count=1; LOOP: Bus::JisuanNodeI(X,bus,N); //计算节点注入电流 Bus::JisuanNodeScal(X,bus,N); //计算节点功率 aa=Complex::productComplex (Complex::getconj(bus[statemp-1].V), B); bb=Complex::subComplex (Complex::getconj(bus[statemp-1].V), cc=Complex::productComplex (bb , Bus::JisuanNodeScal(X,bus,N);//计算节点功率 Bus::JisuanNodeSdelta(bus,N); //计算节点功率差值 Bus::PrintfNodeScal(X,bus,N);//输出节点功率差值 int icon=wehcon1(bus,N);//whether converbence看迭代是否结束 if(icon==1) { // // } cout<<\"icon=\"< else { for(i=0;i int statemp,endtemp; Complex aa,bb,cc,dd,B; B.real=0; B.image=-line[i].B; statemp=line[i].start; endtemp=line[i].end; Complex::getconj(bus[endtemp-1].V)); Complex::getconj(line[i].Y)); dd=Complex::CaddC(aa,cc); line[i].stoe=Complex::productComplex(bus[statemp-1].V,dd); aa=Complex::productComplex (Complex::getconj(bus[endtemp-1].V), B); bb=Complex::subComplex (Complex::getconj(bus[endtemp-1].V), Complex::getconj(bus[statemp-1].V)); cc=Complex::productComplex (bb , Complex::getconj(line[i].Y)); } dd=Complex::CaddC(aa,cc); line[i].etos=Complex::productComplex(bus[endtemp-1].V,dd); cout<<\"icon=\"< cout< } cout<<\"====节点电压===============发电机发出功率======\"< } } } cout< #include using namespace std; class Complex//定义复数类 { public: double real; double image; int RecPolar;//0表示直角坐标,1表示极坐标 static Complex CaddC(Complex c1,Complex c2); //求两个复数和 static Complex subComplex(Complex c1,Complex c2);//求两个复数差 static Complex productComplex(Complex c1,Complex c2); //求两个复数积 static Complex divideComplex(Complex c1,Complex c2); //求两个复数商 static Complex ComDivRea(Complex c1,double r2);//除数 static Complex getconj(Complex c1); //求一个复数共轭 static Complex getinverse(Complex c1);//取倒数 static double getComplexReal(Complex c1); //求一个复数实部 static double getCompleximage(Complex c1);//求一个复数虚部 static void PrintfComplex(Complex c1);//显示一个复数 static void PrintfmultiComplex(Complex C,int N);//显示多个复数 static void zeroComplex(Complex c1);//将复数复零 static Complex Rec2Polar(Complex c1);//取极坐标 Complex() { } RecPolar=0; }; Complex Complex::Rec2Polar(Complex c1)//极坐标表示 { Complex Node; Node.real=sqrt(c1.real*c1.real+c1.image*c1.image); Node.image=atan2(c1.image,c1.real)*180/3.1415926; Node.RecPolar=1; return Node; } Complex Complex::CaddC(Complex c1,Complex c2) //复数加法 { Complex Node; Node.real=c1.real+c2.real; Node.image=c1.image+c2.image; return Node; } Complex Complex::subComplex(Complex c1,Complex c2) //复数减法 { Complex Node; Node.real=c1.real-c2.real; Node.image=c1.image-c2.image; return Node; } Complex Complex::productComplex(Complex c1,Complex c2) //复数乘法 { Complex Node; Node.real=c1.real*c2.real-c1.image*c2.image; Node.image=c1.image*c2.real+c2.image*c1.real; return Node; } Complex Complex::divideComplex(Complex c1,Complex c2) //复数除法 { Complex Node; Node.real=(c1.real*c2.real+c1.image*c2.image)/(pow(c2.real,2)+pow(c2.image,2)); Node.image=(c1.image*c2.real-c1.real*c2.image)/(pow(c2.real,2)+pow(c2.image,2)); return Node; } Complex Complex::ComDivRea(Complex c1,double r1)//复数除数 { Complex Node; Node.real=c1.real/(r1); Node.image=c1.image/(r1); return Node; } Complex Complex::getconj(Complex c1) //取共轭 { Complex Node; Node.real=c1.real; Node.image=-c1.image; return Node; } Complex Complex::getinverse(Complex c1)//取倒数 { Complex Node; Node.real=1; Node.image=0; Node=(Complex::divideComplex(Node,c1)); return Node; } double Complex::getComplexReal(Complex c1) //取实部 { return c1.real; } double Complex::getCompleximage(Complex c1) //取虚部 { return c1.image; } void Complex::PrintfComplex(Complex c1)//按直角坐标输出 { if(c1.RecPolar==0) { cout.precision(6); cout.width(8); cout.setf(ios::right); cout< cout< void Complex::zeroComplex(Complex c1)//清零 { } class gauss { public: static void gauss_slove(double **a,double *x,int NN); c1.real=0; c1.image=0; static void gauss_output(); }; void gauss::gauss_slove(double **a,double *x,int NN) { int n,i,j,k,*pivrow,**pivcol; double eps,pivot,sum,aik,al; n=NN; pivrow=new int[n]; pivcol=new int *[n]; for(i=0;i pivot= fabs(a[k][k]); pivrow[k]=k;//行 pivcol[k][0]=k;pivcol[k][1]=k;//列n*2矩阵 for(i=k;i pivot=fabs(a[i][j]); pivrow[k]=i;//行 pivcol[k][1]=j;//列 if(pivot if(pivrow[k]!=k)//行变换 { for(j=k;j<(n+1);j++) { al=a[pivrow[k]][j]; a[pivrow[k]][j]=a[k][j]; a[k][j]=al; } } if(pivcol[k][1]!=k)//列变换 { for(i=0;i } } if (k!=(n-1))//将矩阵化为上三角形式 { for(i=(k+1);i for(j=k;j<(n+1);j++) { } a[i][j]-=aik*a[k][j]/a[k][k]; } } } x[n-1]=a[n-1][n]/a[n-1][n-1];//解方程 for(i=(n-2);i>=0;i--) { } sum=0; for(j=(i+1);j x[i]=(a[i][n]-sum)/a[i][i]; for(k=(n-2);k>=0;k--) { } cout<<\"节点电压修正量\"< x[pivcol[k][1]]=x[pivcol[k][0]]; x[pivcol[k][0]]=al; } cout< 0.935261 -0.159048 0.573909 0.0789973 -0.00289889 -0.00796623 -0.0791247 -0.0168362 -0.436255 -0.0580392 0.0359139 -0.0106592 -0.229118 -0.0885419 -0.136179 -0.148207 0.0446243 0.0111298 -0.0223764 -0.00695775 0.182709 0.016894 -0.0310701 -0.0402051 0.156702 -0.0355909 -0.0668055 -0.00703229 -0.0886481 -0.0129814 -0.0390805 -0.0135062 -0.1023 -0.0460568 -0.0342827 -0.00382402 -0.102896 -0.0184062 -0.0237482 -0.00347744 -0.198318 -0.0869347 -5.24266e-015 -9.48909e-015 -0.0354071 -0.0110778 -0.0925078 -0.0538236 -1.05629e-015 -7.53784e-016 -0.0391348 -0.0168097 0.014529 7.049e-005 0.00158644 -0.00146487 -0.0258771 -0.00458276 -0.109514 0.00251645 icon=1进行第2次迭代 节点电压修正量 ================= -0.00164889 -0.000540034 -0.00261067 -0.00532027 -0.00235315 -0.00600971 -0.00189677 -0.00643874 -0.0023631 -0.00650659 -0.00170949 -0.0074907 -0.00164545 -0.00485415 -0.00493977 -0.0119042 -0.00331285 -0.0175611 -0.00207908 -0.00336375 -0.00530645 -0.0147816 -0.000326161 -0.00640487 -0.00251701 -0.0169829 -0.00175286 -0.0174333 -0.00307326 -0.0163809 -0.00232773 -0.0175806 8.74293e-005 -0.0192018 0.000558996 -0.0197776 -0.000247851 -0.0193784 -0.00115346 -0.0185848 -0.00127275 -0.0186244 -0.00010108 -0.0188966 0.000553585 -0.0200901 -3.76315e-005 -0.0208303 0.00308341 -0.0219386 -0.00195916 -0.0205356 -0.00184757 -0.0076401 0.00197593 -0.0245534 0.00434657 -0.027534 ====节点功率计算值==== 0.98623 -0.134163 0.583136 0.166278 -0.0239063 -0.0119192 -0.076014 -0.0160104 -0.441997 -0.0750285 0.000250012 3.72542e-005 -0.228052 -0.108844 -0.100078 -0.105634 0.000410707 0.000378067 -0.057497 -0.0195879 0.200039 0.0582563 -0.111173 -0.0739846 0.199792 0.0227868 -0.0621041 -0.0158709 -0.0821379 -0.0248173 -0.0350785 -0.0179447 -0.0902383 -0.0578368 -0.0320461 -0.00890719 -0.0951562 -0.0337091 -0.0220362 -0.00693706 -0.175458 -0.111601 4.72557e-015 1.21429e-014 -0.0320661 -0.0159145 -0.0871134 -0.0667319 -7.03489e-017 9.24355e-016 -0.0350769 -0.0228592 0.000273455 7.10354e-005 1.51804e-005 -6.6188e-006 -0.0240417 -0.00889343 -0.10604 -0.0184098 icon=1进行第3次迭代 节点电压修正量 ================= -2.67079e-005 -2.30128e-006 -2.20543e-005 -6.00686e-005 -2.33043e-005 -6.85601e-005 -3.22294e-005 -2.61107e-005 -2.80198e-005 -6.6167e-005 -2.34528e-005 -5.66132e-005 -4.4646e-005 -1.74668e-005 -4.50947e-005 -0.000181763 -3.81763e-006 -0.000286581 -6.68993e-005 -1.28441e-005 -5.17172e-005 -0.000223284 -4.54717e-005 -2.47586e-005 4.32335e-007 -0.000258494 1.82635e-005 -0.000272051 -6.95195e-006 -0.000251969 1.11318e-005 -0.000279418 5.74737e-005 -0.000307368 6.86998e-005 -0.000320274 5.38112e-005 -0.00031447 3.59531e-005 -0.00030494 3.37607e-005 -0.000307449 5.26532e-005 -0.000310721 6.92761e-005 -0.000350373 5.60942e-005 -0.00040977 0.000123641 -0.000440259 1.36149e-005 -0.000426973 -1.70227e-005 -9.37794e-005 0.000113675 -0.000544011 0.000176034 -0.000636202 ====节点功率计算值==== 0.986878 -0.133979 0.583 0.167193 -0.024 -0.012 -0.076 -0.016 -0.442 -0.0748606 1.43501e-008 1.07366e-008 -0.228 -0.109 -0.0999999 -0.104049 4.51318e-008 8.98835e-008 -0.0579999 -0.0199999 0.2 0.0591018 -0.112 -0.0749997 0.2 0.0242519 -0.062 -0.016 -0.082 -0.025 -0.035 -0.018 -0.0900001 -0.058 -0.032 -0.00899997 -0.095 -0.0339999 -0.022 -0.00699998 -0.175 -0.112 -6.07156e-015 -1.19217e-014 -0.032 -0.016 -0.087 -0.0669999 7.03078e-017 -9.23979e-016 -0.035 -0.0229999 1.09492e-007 4.45699e-008 1.54958e-009 -2.01531e-010 -0.024 -0.00899994 -0.106 -0.0189996 icon=0,迭代结束。 ====节点电压===============发电机发出功率====== 节点1 1.05 0。 98.6878 -13.3979 节点2 1.045 -1.846。 80 29.4193 节点3 1.02384 -3.83352。 0 0 节点4 1.01637 -4.55698。 0 0 节点5 节点6 节点7 节点8 1.01 -6.48617。 50 11.5139 1.01332 -5.38073。 0 0 1.00489 -6.38368。 0 0 1.01 -5.62974。 20 19.5951 节点9 1.03905 -6.78143。 0 0 节点10 1.03595 -8.69362。 0 0 节点11 1.05 -4.5962。 20 5.91018 节点12 1.04711 -7.80323。 0 0 节点13 1.05 -6.34392。 20 2.42519 节点14 1.03242 -8.7401。 0 0 节点15 1.02788 -8.86784。 0 0 节点16 1.03458 -8.45044。 0 0 节点17 1.03051 -8.83678。 0 0 节点18 1.01845 -9.5141。 0 0 节点19 1.01604 -9.70326。 0 0 节点20 1.02022 -9.50938。 0 0 节点21 1.0237 -9.17478。 0 0 节点22 1.02432 -9.17024。 0 0 节点23 1.01802 -9.36719。 0 0 节点24 1.01339 -9.68362。 0 0 节点25 1.01216 -9.68486。 0 0 节点26 0.994393 -10.1089。 0 0 节点27 1.02012 -9.42025。 0 0 节点28 1.00992 -5.86244。 0 0 节点29 1.00022 -10.6579。 0 0 节点30 0.988705 -11.5464。 0 0 ======线路传输功率========== 2to1 -57.7373 5.41674i 58.3454 -15.1827i 3to1 -39.659 -7.75964i 40.3424 1.78481i 4to2 -30.87 -9.74186i 31.4153 3.58352i 4to3 -37.0772 -7.78596i 37.259 6.55964i 5to2 -44.3717 -9.78456i 45.2968 4.84242i 6to2 -38.4766 6to4 -34.946 7to5 -0.16304 7to6 -22.637 8to6 -11.8939 6to9 12.3737 6to10 10.9107 11to9 20 10to9 -32.652 4to12 23.5411 13to12 20 14to12 -7.9019 15to12 -18.254 16to12 -7.53872 15to14 -1.69544 17to16 -4.03014 18to15 -6.08074 19to18 -2.87549 20to19 6.6418 20to10 -8.8418 17to10 -4.96987 21to10 -16.1562 22to10 -7.87782 22to21 1.34443 23to15 -5.59369 24to22 -6.48186 24to23 -2.38596 25to24 -0.167617 26to25 -3.5 27to25 3.39433 28to27 16.1446 29to27 -6.10398 30to27 -6.92979 30to29 -3.6702 28to8 -1.89152 -8.22625i 1.92384i -6.41767i -4.48233i -5.48098i -12.3826i -3.80907i 5.91018i -2.3712i -11.5375i 2.42519i -2.06732i -5.74885i -2.90237i -0.461488i -1.07089i -1.37839i -0.467767i 2.96679i -3.66679i -4.72911i -9.18162i -4.10132i 2.01969i -2.17981i -2.00141i -0.56401i -0.28102i -2.29999i 2.11848i -2.10093i -1.50639i -1.3574i -0.542564i -3.79982i 39.3252 2.87667i 35.0885 -3.28202i 0.171702 2.2985i 22.7745 1.44238i 11.913 3.70557i -12.3737 13.0033i -10.9107 4.53223i -20 -5.08963i 32.652 3.46974i -23.5411 13.2407i -20 -1.90978i 7.97894 2.22749i 18.4835 6.20089i 7.59633 3.02352i 1.70189 0.467323i 4.03872 1.10238i 6.12096 1.46028i 2.88074 0.478389i -6.62452 -2.93222i 8.9242 3.85077i 4.98423 4.76656i 16.2709 9.42843i 7.93248 4.21401i -1.34378 -2.01837i 5.62846 2.25006i 6.53339 2.08163i 2.39369 0.579814i 0.167814 0.281364i 3.54513 2.3674i -3.37751 -2.08638i -16.1446 3.13006i 6.19083 1.67047i 7.09313 1.66484i 3.70398 0.606393i 1.89395 -4.9239i 28to6 -14.7868 -2.82565i 14.8234 0.294601i 请按任意键继续. . . 高等电力系统分析 IEEE30节点潮流程序 班级:电研114班 姓名:王大伟 学号:2201100151
因篇幅问题不能全部显示,请点此查看更多更全内容