1/20潮流计算软件----本软件基于牛顿-拉夫逊法(节点电压是直角坐标)ByQQ:879220194(有问题可交流)用C语言编程计算潮流的流程图否是否是开始始输入原始数据形成节点导纳矩阵YB设节点电压初值ei(0),fi(0)置迭代次数k=1计算ΔPi(k),ΔQi(k),ΔUi(k)2形成雅可比矩阵求各节点电压变量Δei(k),Δfi(k)求出|Δe(k)|max、|Δf(k)|max迭代是否收敛,|Δe(k)|max、|Δf(k)|max≤ε?计算平衡节点功率sS~和线路功率停止计算各节点电压新值:)()()1(kikikieee)()()1(kikikifff增大迭代次数,k-k+1kkm?2/20程序代码如下:#includestdio.h#includestdlib.h#includemath.h#includestring.h#includeconio.hstructlinetype//线路参数{intjiedian[2];//若为变压器,则左端为“低”压侧(换算成Π型等值电路),变压器的阻抗在“低”压侧doubleR,X,K,B0;}line[30];structNodetype//节点功率{intlei;//PQ定义1,PV定义2,平衡节点定义3intjie;//节点编号doubleP,Q;doubley1,y2;//初始电压}poin[30];intpoint,road;//节点数point支路数roadintp1,p2;//PQPV节点数目//*************************************************自定义函数***************************************************************voidchargescreen()//调节屏幕{intmode;printf(\t请选择界面模式:①.106*45②.134*45\n\t);a:scanf(%d,&mode);if(mode!=1&&mode!=2){printf(\n\t错误,请重新输入...\n\t);gotoa;}printf(\n\t);system(pause);if(mode==1)system(modecon:cols=106lines=45);//调整屏幕大小elsesystem(modecon:cols=134lines=45);}voidpqpv()//统计PQ、PV节点数目3/20{inti;p1=p2=0;for(i=0;i=point-1;i++){if(poin[i].lei==1)p1++;if(poin[i].lei==2)p2++;}}voidreadfile()//定义“读取文件信息”{FILE*fp;inti,j;i=j=0;charfilename[20];printf(\n\t请输入潮流方程数据的文件名...\n\t);a:scanf(%s,filename);charch='';//读取数据,以它们之间的空格做分隔标志if((fp=fopen(filename,rb))==NULL){printf(\t打开文件失败...\n\t\t请重新输入...\n\t);gotoa;}elseprintf(\n\t呵呵,读取文件信息成功...\n\n);while(ch!=EOF)//当读入的字符不是结束标志时进行循环{ch=fgetc(fp);if(ch==10)//当输入的字符时换行符时{ch=fgetc(fp);if(ch=='1')//读取PQPV平衡节点参数{//fscanf()读入ASCII字符的形式fscanf(fp,%d%d%lf%lf%lf%lf,&poin[i].lei,&poin[i].jie,&poin[i].P,&poin[i].Q,&poin[i].y1,&poin[i].y2);i++;}if(ch=='2')//读取线路参数(若为变压器,则左节点为“低”压侧(换算成Π型等值电路),变压器的阻抗在“低”压侧){fscanf(fp,%d%d%lf%lf%lf%lf,&line[j].jiedian[0],&line[j].jiedian[1],&line[j].R,&line[j].X,&line[j].K,&line[j].B0);j++;}4/20if(ch=='3')//节点数point支路数road{fscanf(fp,%d%d,&point,&road);}}}fclose(fp);}voidprint()//定义“打印数据信息”{inti,j;pqpv();printf(\n\t①节点参数表(PQ节点PV节点平衡节点):\n\n\t类型节点有功功率P无功功率Q电压e\t电压f\n);for(i=0;i=point-1;i++){if(poin[i].lei==1&&poin[i].jie!=0)printf(\tPQ%d%11.7lf%11.7lf%11.7lf%11.7lf\n,poin[i].jie,poin[i].P,poin[i].Q,poin[i].y1,poin[i].y2);if(poin[i].lei==2&&poin[i].jie!=0)printf(\tPV%d%11.7lf%11.7lf%11.7lf%11.7lf\n,poin[i].jie,poin[i].P,poin[i].Q,poin[i].y1,poin[i].y2);if(poin[i].lei==3&&poin[i].jie!=0)printf(\t平衡%d%11.7lf%11.7lf%11.7lf%11.7lf\n,poin[i].jie,poin[i].P,poin[i].Q,poin[i].y1,poin[i].y2);}printf(\n);printf(\t②线路参数表(变压器换算成Π型等值电路,左节点为“低”压侧):\n\n\t节点1节点2阻抗R感抗X变压器变比k对地电容B\n);for(j=0;j=road-1;j++)if(line[j].jiedian[0]!=0&&line[j].jiedian[1]!=0)printf(\t%d\t%d%11.7lf%11.7lf%11.7lf%11.7lf\n,line[j].jiedian[0],line[j].jiedian[1],line[j].R,line[j].X,line[j].K,line[j].B0);printf(\n);printf(\t③节点数%d,支路数%d\n\n\tPQ节点%d个,PV节点%d个.\n\n,point,road,p1,p2);}voidjiedian(inti)//节点参数{intg3;charc;printf(\n\t节点类型(1.PQ2.PV3.平衡节点):\n\t);a1:scanf(%d,&g3);//g3=c-48;if(g31||g33){5/20printf(\n\t错误,请重新输入...\n\t);gotoa1;}poin[i].lei=g3;if(poin[i].lei!=3){printf(\t有功功率P:\n\t);scanf(%lf,&poin[i].P);if(poin[i].lei!=2){printf(\t无功功率Q:\n\t);scanf(%lf,&poin[i].Q);}elsepoin[i].Q=0;}elsepoin[i].P=poin[i].Q=0;if(poin[i].lei!=1){printf(\t电压e:\n\t);scanf(%lf,&poin[i].y1);printf(\t电压f:\n\t);scanf(%lf,&poin[i].y2);}elsepoin[i].y1=poin[i].y2=0;}voidxianlu(intj)//线路参数{charg2;printf(\n\t线路若含有变压器,则换算成Π型等值电路,左节点为“低”压侧\n\t是否含变压器...(y/n));a:g2=getch();if(g2!='y'&&g2!='n'){printf(\n\n\t错误,请重新输入...\n\t);gotoa;}printf(\n\n\t左节点:\n\t);scanf(%d,&line[j].jiedian[0]);printf(\t右节点:\n\t);scanf(%d,&line[j].jiedian[1]);printf(\t阻抗R:\n\t);scanf(%lf,&line[j].R);printf(\t感抗X:\n\t);scanf(%lf,&line[j].X);if(g2=='y'){line[j].B0=0;6/20printf(\t变压器变比k:\n\t);scanf(%lf,&line[j].K);}else{line[j].K=1;printf(\t对地电容B:\n\t);scanf(%lf,&line[j].B0);}}voidporo()//输入节点数和支路数{printf(\n\t节点数:);scanf(%d,&point);printf(\t支路数:);scanf(%d,&road);}voidgai()//修改数据{charg;intm,n;a:system(cls);printf(\n\t**************************修改数据模式**************************\n);print();printf(\t修改类别如下:\n\ta:节点数&支路数,b:节点参数,c:线路参数...(q退出)\n\t);g=getch();switch(g){case'a':poro();break;case'b':{printf(\n\t请输入修改的节点编号:\n\t);scanf(%d,&m);poin[m-1].jie=m;m--;jiedian(m);}break;case'c':{printf(\n\t请输入修改线路序号:\n\t);scanf(%d,&n);n--;7/20xianlu(n);}break;case'q':;break;default:{printf(\n\t错误,请重新输入...\n\t);gotoa;}}if(g!='q')gotoa;}voidgetdata(inti,intj)//生成数据表{charg1;while(1){a1:system(cls);printf(\na:节点数&支路数,b:节点参数,c:线路参数,d:修改数据,e:数据清零...(q退出)\n\t);g1=getch();if(g1=='a')poro();elseif(g1=='b')while(1){printf(\n\t节点编号:\n\t);scanf(%d,&poin[i].jie);jiedian(i);printf(\n\t按任意键继续...(q退出)\n\t);i++;if(getch()=='q')break;}elseif(g1=='c')while(1){xianlu(j);printf(\n\t按任意键继续...(q退出)\n\t);j++;if(getch()=='q')break;}elseif(g1=='e')//每次生成数据,清零{point=road=0;p1=p2=0;8/20i=j=0;printf(\n\t数据清零成功...);gotoa1;}elseif(g1=='d')gai();elseif(g1=='q')break;else{printf(\n\t错误,请重新输入...\n\t);gotoa1;}}}voidputfile2()//将数据存入文件{FILE*fp;inti,j;charfilename[20],beizhu[60];printf(\n\t请输入要存入计算数据的文件名...\n\t);