1樓:匿名使用者
function lianxuchaoliu
clear;
clc;
n=9;%節點數;
nl=9;%支路數;
isb=1;%平衡節點號;
pr=0.00001;%誤差精度;
b1=[1 4 0.0576i 0 1.05 1; 4 5 0.
017+0.092i 0.158i 1 0; 5 6 0.
039+0.17i 0.358i 1 0; 3 6 0.
0586i 0 1.05 1; 6 7 0.0119+0.
1008i 0.209i 1 0; 7 8 0.0085+0.
072i 0.149i 1 0; 8 2 0.0625i 0 1.
05 1; 8 9 0.032+0.161i 0.
306i 1 0; 9 4 0.01+0.085i 0.
176i 1 0];
%依次是支路首端;末端,支路阻抗;對地電納;支路變比;折算到哪一側標誌(高壓側為1;低壓側為0);
b2=[0 0 1.05 1.05 0 1; 1.
63 0 1.05 1.05 0 3; 0.
85 0 1.05 1.05 0 3; 0 0 1 0 0 2; 0 0.
9+0.3i 1 0 0 2; 0 0 1 0 0 2; 0 1+0.35i 1 0 0 2; 0 0 1 0 0 2; 0 1.
25+0.5i 1 0 0 2];
%依次是節點的發電機功率;負荷功率;節點電壓初值;pv節點電壓v給定值;節點無功補償裝置容量;節點分類標號(平衡1;pq2;pv3);
y=zeros(n);%求導納陣;
for i=1:nl
if b1(i,6)==0
p=b1(i,1);q=b1(i,2);
else
p=b1(i,2);q=b1(i,1);
endy(p,q)=y(p,q)-1./(b1(i,3)*b1(i,5));
y(q,p)=y(p,q);
y(q,q)=y(q,q)+1./(b1(i,3)*b1(i,5)^2)+b1(i,4)./2;
y(p,p)=y(p,p)+1./b1(i,3)+b1(i,4)./2;
end%disp('系統的導納陣為:');
%disp(y);
g=real(y);b=imag(y);
for i=1:n
e(i)=real(b2(i,3));
f(i)=imag(b2(i,3));
v(i)=b2(i,4);
endfor i=1:n
s(i)=b2(i,1)-b2(i,2);
b(i,i)=b(i,i)+b2(i,5);
endp=real(s);q=imag(s);
w=zeros(2*n,1);jac=zeros(2*n);
t=0;
while t==0
for i=1:n
if b2(i,6)~=isb
c=0;d=0;
for j=1:n
c=c+g(i,j)*e(j)-b(i,j)*f(j);
d=d+g(i,j)*f(j)+b(i,j)*e(j);
endif b2(i,6)==2%p,q節點;
w(2*i)=p(i)-e(i)*c-f(i)*d;
w(2*i-1)=q(i)-f(i)*c+e(i)*d;
else if b2(i,6)==3%p,v節點;
w(2*i)=p(i)-e(i)*c-f(i)*d;
w(2*i-1)=v(i)^2-(e(i)^2+f(i)^2);
endendelse
w(2*i-1)=0;
w(2*i)=0;
endend%disp(w);
w1=w(3:2*n);
for i=1:n
for j=1:n
if b2(i,6)~=isb
if b2(i,6)==2%p,q節點;
if j~=i
jac(2*i,2*j-1)=-1*(g(i,j)*e(i)+b(i,j)*f(i));
jac(2*i-1,2*j)=(g(i,j)*e(i)+b(i,j)*f(i));
jac(2*i,2*j)=b(i,j)*e(i)-g(i,j)*f(i);
jac(2*i-1,2*j-1)=b(i,j)*e(i)-g(i,j)*f(i);
else if j==i
m=0;h=0;
for r=1:n
m=m+g(i,r)*e(r)-b(i,r)*f(r);
h=h+g(i,r)*f(r)+b(i,r)*e(r);
endjac(2*i,2*j-1)=-1*m-g(i,i)*e(i)-b(i,i)*f(i);
jac(2*i-1,2*j)=-1*m+g(i,i)*e(i)+b(i,i)*f(i);
jac(2*i,2*j)=-1*h+b(i,i)*e(i)-g(i,i)*f(i);
jac(2*i-1,2*j-1)=h+b(i,i)*e(i)-g(i,i)*f(i);
endendelse if b2(i,6)==3%p,v節點;
if j~=i
jac(2*i,2*j-1)=-1*(g(i,j)*e(i)+b(i,j)*f(i));
jac(2*i-1,2*j)=0;
jac(2*i,2*j)=b(i,j)*e(i)-g(i,j)*f(i);
jac(2*i-1,2*j-1)=0;
else if j==i
m=0;h=0;
for r=1:n
m=m+g(i,r)*e(r)-b(i,r)*f(r);
h=h+g(i,r)*f(r)+b(i,r)*e(r);
endjac(2*i,2*j-1)=-1*m-g(i,i)*e(i)-b(i,i)*f(i);
jac(2*i-1,2*j)=-2*f(i);
jac(2*i,2*j)=-1*h+b(i,i)*e(i)-g(i,i)*f(i);
jac(2*i-1,2*j-1)=-2*e(i);
endendendendelse
jac(2*i-1,2*j-1)=0;
jac(2*i,2*j)=0;
jac(2*i-1,2*j)=0;
jac(2*i,2*j-1)=0;
endendend%disp(jac);
jac1=jac(3:2*n,3:2*n);
for k=1:2*n-2
m=0;
for i=k+1:2*n-2
m=jac1(i,k)./jac1(k,k);
w1(i)=w1(i)-m*w1(k);
for j=k+1:2*n-2
jac1(i,j)=jac1(i,j)-m*jac1(k,j);
endendende(2*n-2)=w1(2*n-2)./jac1(2*n-2,2*n-2);
for i=2*n-3:-1:1
c=0;
for k=i+1:2*n-2
c=c+jac1(i,k)*e(k);
e(i)=(w1(i)-c)./jac1(i,i);
endend%disp(e);
for i=1:n-1
e(i+1)=e(i+1)-e(2*i-1);
f(i+1)=f(i+1)-e(2*i);
end%disp(e);
%disp(f);
for i=1:n-1
b(2*i-1)=abs(e(2*i-1));
b(2*i)=abs(e(2*i));
endkb=max(b);
%disp(kb);
if kb1%以切向量中分量最大(絕對值最大)的狀態變數選定為連續引數;
for i=1:2*n-2
jd(i)=abs(d(i));
endfor i=1:2*n-3
if jd(i)>=jd(i+1)
zd=jd(i);ek=i;
else if jd(i)<=jd(i+1)
zd=jd(i+1);ek=i+1;
endendendfor j=1:2*n-1
jj1(2*n-1,j)=0;
endjj1(2*n-1,ek)=1;
w2=zeros(2*n-1,1);
for i=1:2*n-1
w2(i,1)=0;
endif d(ek)>0
w2(ek,1)=1;
else if d(ek)<0
w2(ek,1)=-1;
endendendfor k=1:2*n-1
m=0;
for i=k+1:2*n-1
m=jj1(i,k)./jj1(k,k);
w2(i)=w2(i)-m*w2(k);
for j=k+1:2*n-1
jj1(i,j)=jj1(i,j)-m*jj1(k,j);
endendendd(2*n-1)=w2(2*n-1)./jj1(2*n-1,2*n-1);
for i=2*n-2:-1:1
c=0;
for k=i+1:2*n-1
c=c+jj1(i,k)*d(k);
d(i)=(w2(i)-c)./jj1(i,i);
endend%disp(d);
for i=1:n-1
e(i+1)=e(i+1)+l*d(2*i-1);
f(i+1)=f(i+1)+l*d(2*i);
endt=t+l*d(2*n-1);
disp(d(2*n-1));
%disp(e);
%disp(f);
%disp(t);
%對預估的近似解進行校正;
tt=0;
while tt==0
for i=1:n
if b2(i,6)~=isb
c=0;d=0;
for j=1:n
c=c+g(i,j)*e(j)-b(i,j)*f(j);
d=d+g(i,j)*f(j)+b(i,j)*e(j);
endif b2(i,6)==2% p,q節點;
if b2(i,2)~=0
wj(2*i)=p(i)-t*real(b2(i,2))-e(i)*c-f(i)*d;
wj(2*i-1)=q(i)-t*imag(b2(i,2))-f(i)*c+e(i)*d;
else
wj(2*i)=p(i)-e(i)*c-f(i)*d;
wj(2*i-1)=q(i)-f(i)*c+e(i)*d;
endelse if b2(i,6)==3%p,v節點;
wj(2*i)=p(i)+t*1.5*1.05-e(i)*c-f(i)*d;
wj(2*i-1)=0;
endendelse
wj(2*i)=0;
wj(2*i-1)=0;
endendwj1=wj(3:2*n);
for i=1:n
for j=1:n
if b2(i,6)~=isb
if b2(i,6)==2%p,q節點;
if j~=i
jjac(2*i,2*j-1)=-1*(g(i,j)*e(i)+b(i,j)*f(i));
jjac(2*i-1,2*j)=(g(i,j)*e(i)+b(i,j)*f(i));
jjac(2*i,2*j)=b(i,j)*e(i)-g(i,j)*f(i);
jjac(2*i-1,2*j-1)=b(i,j)*e(i)-g(i,j)*f(i);
else if j==i
m=0;h=0;
for r=1:n
m=m+g(i,r)*e(r)-b(i,r)*f(r);
h=h+g(i,r)*f(r)+b(i,r)*e(r);
endjjac(2*i,2*j-1)=-1*m-g(i,i)*e(i)-b(i,i)*f(i);
jjac(2*i-1,2*j)=-1*m+g(i,i)*e(i)+b(i,i)*f(i);
jjac(2*i,2*j)=-1*h+b(i,i)*e(i)-g(i,i)*f(i);
jjac(2*i-1,2*j-1)=h+b(i,i)*e(i)-g(i,i)*f(i);
endendelse if b2(i,6)==3%p,v節點;
if j~=i
jjac(2*i,2*j-1)=-1*(g(i,j)*e(i)+b(i,j)*f(i));
jjac(2*i-1,2*j)=0;
jjac(2*i,2*j)=b(i,j)*e(i)-g(i,j)*f(i);
jjac(2*i-1,2*j-1)=0;
else if j==i
m=0;h=0;
for r=1:n
m=m+g(i,r)*e(r)-b(i,r)*f(r);
h=h+g(i,r)*f(r)+b(i,r)*e(r);
endjjac(2*i,2*j-1)=-1*m-g(i,i)*e(i)-b(i,i)*f(i);
jjac(2*i-1,2*j)=-2*f(i);
jjac(2*i,2*j)=-1*h+b(i,i)*e(i)-g(i,i)*f(i);
jjac(2*i-1,2*j-1)=-2*e(i);
endendendendelse
jjac(2*i-1,2*j-1)=0;
jjac(2*i,2*j)=0;
jjac(2*i-1,2*j)=0;
jjac(2*i,2*j-1)=0;
endendendjjac1=jjac(3:2*n,3:2*n);
for k=1:2*n-2
m=0;
for i=k+1:2*n-2
m=jjac1(i,k)./jjac1(k,k);
wj1(i)=wj1(i)-m*wj1(k);
for j=k+1:2*n-2
jjac1(i,j)=jjac1(i,j)-m*jjac1(k,j);
endendende1(2*n-2)=wj1(2*n-2)./jjac1(2*n-2,2*n-2);
for i=2*n-3:-1:1
c=0;
for k=i+1:2*n-2
c=c+jjac1(i,k)*e1(k);
e1(i)=(wj1(i)-c)./jjac1(i,i);
endend%disp(e1);
for i=1:n-1
e(i+1)=e(i+1)-e1(2*i-1);
f(i+1)=f(i+1)-e1(2*i);
endfor i=1:n-1
bx(2*i-1)=abs(e1(2*i-1));
bx(2*i)=abs(e1(2*i));
endkb1=max(bx);
if kb10
ttt=0;ccc=ccc+1;
else
ttt=1;
endend
disp(t);
disp(ccc);
%disp(e);
%disp(f);
for i=1:n
fz1(i)=sqrt(e(i)^2+f(i)^2);
enddisp(fz1);
求簡單的matlab程式,想實現函式的影象顯示,並且當輸入x
你這個系 複數太麻煩,寫個制m檔案吧 function y f x y 9.7800000000000082 0.0084265734265880 x 0.0015909090909031 x.2 0.0001631701631693 x.3 0.0000058275058275 x.4 end儲存...
用matlab編寫程式1計算yx3x
這些都是matlab基本語句,建議你看看相關書籍,謝謝 這麼簡單的東西,你有時間碼這麼多字,為什麼不花點時間去看看書,一般基本教程看完前三章就都會了 如何用matlab程式設計求解x 3 2 x 2 1 0在 1,3 範圍內的根?只會用抄 符號解。襲。syms x f x 3 2 x 2 1 sol...
matlab建立M檔案編寫程式,求1 1000 的值
程式如下 s 1 sum 0 for i 1 1000 s s i sum sum 1 s endsum c語言程式設計題,計算s 1 1 2 1 3 1 4.1 m n是整型,執行1 n後也是個整型。修改 include int main printf f n s return 0 由於你的n是i...