资源描述:
《牛拉法计算C程序.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、#include#include#include#definePI3.14159structNodeType{intN;intType;doublee;doublef;doublePd;doubleQd;doublePs;doubleQs;doubleBc;};structBranchType{intNbr;intNl;intNr;doubleR;doubleX;doubleBn;doubleKt;};intn;intnPQ;intnPV;intn
2、PH;intnbr;intng;intMark=0;double**G;double**B;double*dS;double*mid1,*mid2;double*Us;doubleerror=1;doubleiteration=0.000001;double**Jacob;double**invJac;double*dfe;structNodeType*Node;structBranchType*Branch;voidmain(){voidLoadData();voidFormY();voidDelt
3、aS();voidFormJacob();voidInvJac();voidUpdateU();voidCalculatePQ();intkk;LoadData();FormY();printf("Îó²î¾«¶Èiteration=%lf",iteration);kk=0;DeltaS();while(error>iteration&&kk<50){FormJacob();UpdateU();DeltaS();kk++;}printf("µü´ú´ÎÊýΪ%4d",kk);Calculat
4、ePQ();printf("Îó²îÖµerror=%e",error);printf("");printf("");printf("{×¢:NΪ½ÚµãºÅ£¬TpΪ½ÚµãÀàÐÍ£¨ÆäÖÐ1ΪPQ½Úµã£¬2ΪPV½Úµã£¬3Ϊƽºâ½Úµã£©£¬AmpΪµçѹ´óС£¬DltaΪÏàλ½Ç£¬PdΪ½ÚµãÊä³öµÄÓй¦¹¦ÂÊ£¬QdΪ½ÚµãÊä³öµÄÎÞ¹¦¹¦ÂÊ£¬PsΪ·¢µç»úÊä³öÓй¦¹¦ÂÊ£¬QsÎ
5、ª·¢µç»úÊä³öÎÞ¹¦¹¦ÂÊ£¬BcΪ²¢ÁªµçÈݵĵ翹ֵ}");}voidLoadData(){inti,j;inttN,tType;doublete,tf,tPd,tQd,tPs,tQs,tBc;FILE*fp;charfilename[50]={""};printf("ÇëÊäÈëÊý¾ÝÎļþÃû(Ìáʾ£ºÊý¾ÝËùÔÚTXTÎļþ)£º");scanf("%s",filename);if((fp=fopen(filename,"r"))==NULL){p
6、rintf("cannotopenthefile:data.txt");return;}fscanf(fp,"%d",&n);printf("½Úµã¸öÊýΪ£º%d",n);Node=(structNodeType*)malloc(sizeof(structNodeType)*n);printf("µ÷ÕûÇ°µÄ½Úµã²ÎÊýΪ£º");for(i=0;i7、i].Type,&Node[i].e,&Node[i].f,&Node[i].Pd,&Node[i].Qd,&Node[i].Ps,&Node[i].Qs,&Node[i].Bc);for(i=0;i8、;printf("ƽºâ½Úµã¸öÊý£º%d",nPH);for(j=0;jNode[i+1].Type){tN=Node[i].N;Node[i].N=Node[i+1].N;Node[i+1].N=tN;tType=Node[i].Type;Node[i].Type=Node[i+1].Type;Node[i+1].Type=tType;te=Nod