資源描述:
《牛頓-拉夫遜法潮流計(jì)算matlab程序》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在行業(yè)資料-天天文庫。
1、牛頓-拉夫遜法潮流計(jì)算matlab程序主程序"PowerFlow_NR.m"function[bus_res,S_res]=PowerFlow_NR_2%牛頓-拉夫遜法解潮流方程的主程序[bus,line]=OpDF_;%打開數(shù)據(jù)文件的子程序,返回bus(節(jié)點(diǎn)數(shù)據(jù))和line(線路數(shù)據(jù))回主程序[nb,mb]=size(bus);[nl,ml]=size(line);%計(jì)算bus和line矩陣的行數(shù)和列數(shù)[bus,line,nPQ,nPV,nodenum]=Num_(bus,line);%對(duì)節(jié)點(diǎn)重新
2、排序的子程序Y=y_(bus,line);%計(jì)算節(jié)點(diǎn)導(dǎo)納矩陣的子程序myf=fopen('Result.m','w');fprintf(myf,'---------------bylongdinhohe---------------http://blog.sina.com.cn/longdinhohe---------------nn');fclose(myf);%在當(dāng)前目錄下生成“Result.m”文件,寫入節(jié)點(diǎn)導(dǎo)納矩陣formatlongEPS=1.0e-10;%設(shè)定誤差精度fort=1:100
3、%開始迭代計(jì)算,設(shè)定最大迭代次數(shù)為100,以便不收斂情況下及時(shí)跳出[dP,dQ]=dPQ_(Y,bus,nPQ,nPV);%計(jì)算功率偏差dP和dQ的子程序J=Jac_(bus,Y,nPQ);%計(jì)算雅克比矩陣的子程序UD=zeros(nPQ,nPQ);fori=1:nPQUD(i,i)=bus(i,2);%生成電壓對(duì)角矩陣enddAngU=J[dP;dQ];dAng=dAngU(1:nb-1,1);%計(jì)算相角修正量dU=UD*(dAngU(nb:nb+nPQ-1,1));%計(jì)算電壓修正量bus(1:n
4、PQ,2)=bus(1:nPQ,2)-dU;%修正電壓bus(1:nb-1,3)=bus(1:nb-1,3)-dAng;%修正相角if(max(abs(dU))5、計(jì)算線路的等效Yt和Ym的子程序,以計(jì)算線路潮流bus_res=bus_res_(bus);%計(jì)算節(jié)點(diǎn)數(shù)據(jù)結(jié)果的子程序S_res=S_res_(bus,line,YtYm);%計(jì)算線路潮流的子程序myf=fopen('Result.m','a');fprintf(myf,'---------------牛頓-拉夫遜法潮流計(jì)算結(jié)果----------nn節(jié)點(diǎn)計(jì)算結(jié)果:n節(jié)點(diǎn)節(jié)點(diǎn)電壓節(jié)點(diǎn)相角(角度)節(jié)點(diǎn)注入功率n');fori=1:nbfprintf(myf,'%2.0f',bus_res(i,1));
6、fprintf(myf,'%10.6f',bus_res(i,2));fprintf(myf,'%10.6f',bus_res(i,3));fprintf(myf,'%10.6f+j%10.6fn',real(bus_res(i,4)),imag(bus_res(i,4)));endfprintf(myf,'n線路計(jì)算結(jié)果:n節(jié)點(diǎn)I節(jié)點(diǎn)J線路功率S(I,J)線路功率S(J,I)線路損耗dS(I,J)n');fori=1:nlfprintf(myf,'%2.0f',S_res(i,1));fprint
7、f(myf,'%2.0f',S_res(i,2));fprintf(myf,'%10.6f+j%10.6f',real(S_res(i,3)),imag(S_res(i,3)));fprintf(myf,'%10.6f+j%10.6f',real(S_res(i,4)),imag(S_res(i,4)));fprintf(myf,'%10.6f+j%10.6fn',real(S_res(i,5)),imag(S_res(i,5)));endfclose(myf);%迭代結(jié)束后繼續(xù)在“Result.m
8、”寫入節(jié)點(diǎn)計(jì)算結(jié)果和線路計(jì)算結(jié)果程序結(jié)束子程序1"OpDF_.m"作用為打開數(shù)據(jù)文件function[bus,line]=OpDF_[dfile,pathname]=uigetfile('*.m','SelectDataFile');%數(shù)據(jù)文件類型為m文件,窗口標(biāo)題為“SelectDataFile”ifpathname==0error('youmustselectavaliddatafile')%如果沒有選擇有效文件,則出現(xiàn)錯(cuò)誤提示elselfile=length(d